Exemplo n.º 1
0
 private void EndFight()
 {
     if (this.currentPoints1 == 0.0f)
     {
         this.currentFight.winners.Add(this.currentFight.factionTwo);
     }
     else
     if (this.currentPoints2 == 0.0f)
     {
         this.currentFight.winners.Add(this.currentFight.factionOne);
     }
     else
     {
         if (this.currentPoints1 > this.currentPoints2)
         {
             this.currentFight.winners.Add(this.currentFight.factionOne);
         }
         else
         if (this.currentPoints2 > this.currentPoints1)
         {
             this.currentFight.winners.Add(this.currentFight.factionTwo);
         }
     }
     this.stage          = ExecutingStage.CleaningArena;
     this.remainingTicks = 100;
     this.currentFight   = null;
     this.currentBrain1  = null;
     this.currentBrain2  = null;
     this.currentPoints1 = 0.0f;
     this.currentPoints2 = 0.0f;
 }
Exemplo n.º 2
0
        private void CalculateFights(Faction factionOne, Faction factionTwo, float scale)
        {
            if (scale < factionOne.def.MinPointsToGeneratePawnGroup())
            {
                Log.Warning("Faction " + factionOne.name + " cannot be create with " + scale + " points (Min: " + factionOne.def.MinPointsToGeneratePawnGroup().ToString("N0") + ".");
                return;
            }

            if (scale < factionTwo.def.MinPointsToGeneratePawnGroup())
            {
                Log.Warning("Faction " + factionTwo.name + " cannot be create with " + scale + " points (Min: " + factionTwo.def.MinPointsToGeneratePawnGroup().ToString("N0") + ".");
                return;
            }

            SaveableFight fight = new SaveableFight();

            fight.points     = scale;
            fight.factionOne = factionOne;
            fight.factionTwo = factionTwo;
            this.fights.Add(fight);
        }
 private void EndFight()
 {
     if (this.currentPoints1 == 0.0f)
         this.currentFight.winners.Add(this.currentFight.factionTwo);
     else
         if (this.currentPoints2 == 0.0f)
             this.currentFight.winners.Add(this.currentFight.factionOne);
         else
         {
             if (this.currentPoints1 > this.currentPoints2)
                 this.currentFight.winners.Add(this.currentFight.factionOne);
             else
                 if (this.currentPoints2 > this.currentPoints1)
                     this.currentFight.winners.Add(this.currentFight.factionTwo);
         }
     this.stage = ExecutingStage.CleaningArena;
     this.remainingTicks = 100;
     this.currentFight = null;
     this.currentBrain1 = null;
     this.currentBrain2 = null;
     this.currentPoints1 = 0.0f;
     this.currentPoints2 = 0.0f;
 }
        private void CalculateFights(Faction factionOne, Faction factionTwo, float scale)
        {
            if (scale < factionOne.def.MinPointsToGeneratePawnGroup())
            {
                Log.Warning("Faction " + factionOne.name + " cannot be create with " + scale + " points (Min: " + factionOne.def.MinPointsToGeneratePawnGroup().ToString("N0") + ".");
                return;
            }

            if (scale < factionTwo.def.MinPointsToGeneratePawnGroup())
            {
                Log.Warning("Faction " + factionTwo.name + " cannot be create with " + scale + " points (Min: " + factionTwo.def.MinPointsToGeneratePawnGroup().ToString("N0") + ".");
                return;
            }

            SaveableFight fight = new SaveableFight();
            fight.points = scale;
            fight.factionOne = factionOne;
            fight.factionTwo = factionTwo;
            this.fights.Add(fight);
        }
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            switch (this.stage)
            {
                case ExecutingStage.ClearParameters:
                    this.competitorTable = null;
                    this.style = null;
                    this.roundNumbers = null;
                    this.sandBagChance = null;
                    this.wallChance = null;
                    this.raidScales.Clear();
                    this.stage = ExecutingStage.PickingParameters;
                    break;
                case ExecutingStage.PickingParameters:
                    break;
                case ExecutingStage.CalculatingFights:
                    this.fights.Clear();
                    switch (this.competitorTable.Value)
                    {
                        case ChallengeType.AnotherFaction:
                            this.CalculateFights(this.toRaid[0], this.toRaid[1]);
                            break;
                        case ChallengeType.AllOtherFactions:
                            foreach (Faction faction in Find.FactionManager.AllFactions.Where(i => i.HostileTo(Faction.OfColony)))
                                this.CalculateFights(this.toRaid[0], faction);
                            break;
                        case ChallengeType.AllCoreFactions:
                            foreach (Faction faction in Find.FactionManager.AllFactions.Where(i => i.HostileTo(Faction.OfColony)))
                                if ((faction.def.defName == "Colony") ||
                                    (faction.def.defName == "Spacer") ||
                                    (faction.def.defName == "SpacerHostile") ||
                                    (faction.def.defName == "Outlander") ||
                                    (faction.def.defName == "Pirate") ||
                                    (faction.def.defName == "Tribe") ||
                                    (faction.def.defName == "Mechanoid"))
                                this.CalculateFights(this.toRaid[0], faction);
                            break;
                    }
                    this.stage = ExecutingStage.CreatingArena;
                    break;
                case ExecutingStage.CreatingArena:

                    if (this.fights.Where(i => i.winners.Count < this.roundNumbers.Value).Any())
                        this.currentFight = this.fights.Where(i => i.winners.Count < this.roundNumbers.Value).First();
                    else
                    {
                        this.stage = ExecutingStage.DisplaingResults;
                        return;
                    }

                    CellRect rect = CellRect.FromLimits(5, 5, 100, 60);

                    rect.ClipInsideMap();

                    foreach (IntVec3 current in rect)
                        Find.RoofGrid.SetRoof(current, null);

                    foreach (IntVec3 current in rect)
                    {
                        List<Thing> thingList = current.GetThingList();
                        for (int i = thingList.Count - 1; i >= 0; i--)
                        {
                            if (!Thing.allowDestroyNonDestroyable && !thingList[i].def.destroyable)
                                thingList[i].DeSpawn();
                            else
                                thingList[i].Destroy(DestroyMode.Vanish);
                        }

                        if (Rand.Range(0, 100) < this.sandBagChance.Value)
                            GenSpawn.Spawn(ThingDefOf.Sandbags, current);
                        else
                            if (Rand.Range(0, 100) < this.wallChance.Value)
                            {
                                ThingDef wall = ThingDefOf.Wall;
                                Thing newThing = ThingMaker.MakeThing(wall, ThingDefOf.Plasteel);
                                GenSpawn.Spawn(newThing, current);
                            }
                    }

                    foreach (IntVec3 current in rect)
                        Find.TerrainGrid.SetTerrain(current, TerrainDefOf.Concrete);

                    foreach (IntVec3 current in rect.EdgeCells)
                    {
                        ThingDef wall = ThingDefOf.Wall;
                        Thing newThing = ThingMaker.MakeThing(wall, ThingDefOf.Plasteel);
                        GenSpawn.Spawn(newThing, current);
                    }

                    AbilityRequeriment_ColonyBiggerThan.forcedValue = this.currentFight.points;

                    this.currentFight.factionOne.SetHostileTo(this.currentFight.factionTwo, true);
                    this.currentFight.factionOne.SetHostileTo(Faction.OfColony, true);
                    this.currentFight.factionTwo.SetHostileTo(this.currentFight.factionOne, true);
                    this.currentFight.factionTwo.SetHostileTo(Faction.OfColony, true);

                    List<Brain> oldBrains = new List<Brain>(Find.SquadBrainManager.allSquadBrains);

                    IncidentDef incidentDef = IncidentDef.Named("RaidEnemy");
                    IncidentParms incidentParms = Find.Storyteller.def.IncidentMaker.ParmsNow(incidentDef.category);
                    incidentParms.faction = this.currentFight.factionOne;
                    incidentParms.spawnCenter = new IntVec3(30, 0, 35);
                    incidentParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack;
                    incidentParms.points = this.currentFight.points;
                    incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                    incidentDef.Worker.TryExecute(incidentParms);

                    incidentDef = IncidentDef.Named("RaidEnemy");
                    incidentParms = Find.Storyteller.def.IncidentMaker.ParmsNow(incidentDef.category);
                    incidentParms.faction = this.currentFight.factionTwo;
                    incidentParms.spawnCenter = new IntVec3(80, 0, 35);
                    incidentParms.raidStrategy = RaidStrategyDefOf.ImmediateAttack;
                    incidentParms.points = this.currentFight.points;
                    incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                    incidentDef.Worker.TryExecute(incidentParms);

                    List<Brain> newBrains = new List<Brain>(Find.SquadBrainManager.allSquadBrains);
                    foreach (Brain b in oldBrains)
                        newBrains.Remove(b);

                    this.currentBrain1 = this.GetBrain(this.currentFight.factionOne, newBrains);
                    this.currentBrain2 = this.GetBrain(this.currentFight.factionTwo, newBrains);
                    this.currentPoints1 = this.BrainPoints(this.currentBrain1);
                    this.currentPoints2 = this.BrainPoints(this.currentBrain2);

                    this.remainingTicks = MapComponentFactionGauntlet.roundLenght;
                    this.stage = ExecutingStage.Fighting;
                    break;
                case ExecutingStage.Fighting:

                    this.currentPoints1 = this.BrainPoints(this.currentBrain1);
                    this.currentPoints2 = this.BrainPoints(this.currentBrain2);

                    if ((this.currentPoints1 == 0.0f) ||
                        (this.currentPoints2 == 0.0f))
                    {
                        this.EndFight();
                        return;
                    }

                    if (this.style.Value == FightStyle.TimedRounds)
                    {
                        if (this.remainingTicks > 0)
                            this.remainingTicks--;
                        else
                        {
                            this.EndFight();
                            return;
                        }
                    }

                    break;
                case ExecutingStage.CleaningArena:
                    this.remainingTicks--;
                    if (this.remainingTicks <= 0)
                        this.stage = ExecutingStage.CreatingArena;
                    break;
            }
        }
Exemplo n.º 6
0
        public override void MapComponentTick()
        {
            base.MapComponentTick();

            switch (this.stage)
            {
            case ExecutingStage.ClearParameters:
                this.competitorTable = null;
                this.style           = null;
                this.roundNumbers    = null;
                this.sandBagChance   = null;
                this.wallChance      = null;
                this.raidScales.Clear();
                this.stage = ExecutingStage.PickingParameters;
                break;

            case ExecutingStage.PickingParameters:
                break;

            case ExecutingStage.CalculatingFights:
                this.fights.Clear();
                switch (this.competitorTable.Value)
                {
                case ChallengeType.AnotherFaction:
                    this.CalculateFights(this.toRaid[0], this.toRaid[1]);
                    break;

                case ChallengeType.AllOtherFactions:
                    foreach (Faction faction in Find.FactionManager.AllFactions.Where(i => i.HostileTo(Faction.OfColony)))
                    {
                        this.CalculateFights(this.toRaid[0], faction);
                    }
                    break;

                case ChallengeType.AllCoreFactions:
                    foreach (Faction faction in Find.FactionManager.AllFactions.Where(i => i.HostileTo(Faction.OfColony)))
                    {
                        if ((faction.def.defName == "Colony") ||
                            (faction.def.defName == "Spacer") ||
                            (faction.def.defName == "SpacerHostile") ||
                            (faction.def.defName == "Outlander") ||
                            (faction.def.defName == "Pirate") ||
                            (faction.def.defName == "Tribe") ||
                            (faction.def.defName == "Mechanoid"))
                        {
                            this.CalculateFights(this.toRaid[0], faction);
                        }
                    }
                    break;
                }
                this.stage = ExecutingStage.CreatingArena;
                break;

            case ExecutingStage.CreatingArena:

                if (this.fights.Where(i => i.winners.Count < this.roundNumbers.Value).Any())
                {
                    this.currentFight = this.fights.Where(i => i.winners.Count < this.roundNumbers.Value).First();
                }
                else
                {
                    this.stage = ExecutingStage.DisplaingResults;
                    return;
                }

                CellRect rect = CellRect.FromLimits(5, 5, 100, 60);

                rect.ClipInsideMap();

                foreach (IntVec3 current in rect)
                {
                    Find.RoofGrid.SetRoof(current, null);
                }

                foreach (IntVec3 current in rect)
                {
                    List <Thing> thingList = current.GetThingList();
                    for (int i = thingList.Count - 1; i >= 0; i--)
                    {
                        if (!Thing.allowDestroyNonDestroyable && !thingList[i].def.destroyable)
                        {
                            thingList[i].DeSpawn();
                        }
                        else
                        {
                            thingList[i].Destroy(DestroyMode.Vanish);
                        }
                    }

                    if (Rand.Range(0, 100) < this.sandBagChance.Value)
                    {
                        GenSpawn.Spawn(ThingDefOf.Sandbags, current);
                    }
                    else
                    if (Rand.Range(0, 100) < this.wallChance.Value)
                    {
                        ThingDef wall     = ThingDefOf.Wall;
                        Thing    newThing = ThingMaker.MakeThing(wall, ThingDefOf.Plasteel);
                        GenSpawn.Spawn(newThing, current);
                    }
                }

                foreach (IntVec3 current in rect)
                {
                    Find.TerrainGrid.SetTerrain(current, TerrainDefOf.Concrete);
                }

                foreach (IntVec3 current in rect.EdgeCells)
                {
                    ThingDef wall     = ThingDefOf.Wall;
                    Thing    newThing = ThingMaker.MakeThing(wall, ThingDefOf.Plasteel);
                    GenSpawn.Spawn(newThing, current);
                }

                AbilityRequeriment_ColonyBiggerThan.forcedValue = this.currentFight.points;

                this.currentFight.factionOne.SetHostileTo(this.currentFight.factionTwo, true);
                this.currentFight.factionOne.SetHostileTo(Faction.OfColony, true);
                this.currentFight.factionTwo.SetHostileTo(this.currentFight.factionOne, true);
                this.currentFight.factionTwo.SetHostileTo(Faction.OfColony, true);

                List <Brain> oldBrains = new List <Brain>(Find.SquadBrainManager.allSquadBrains);

                IncidentDef   incidentDef   = IncidentDef.Named("RaidEnemy");
                IncidentParms incidentParms = Find.Storyteller.def.IncidentMaker.ParmsNow(incidentDef.category);
                incidentParms.faction         = this.currentFight.factionOne;
                incidentParms.spawnCenter     = new IntVec3(30, 0, 35);
                incidentParms.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
                incidentParms.points          = this.currentFight.points;
                incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                incidentDef.Worker.TryExecute(incidentParms);

                incidentDef                   = IncidentDef.Named("RaidEnemy");
                incidentParms                 = Find.Storyteller.def.IncidentMaker.ParmsNow(incidentDef.category);
                incidentParms.faction         = this.currentFight.factionTwo;
                incidentParms.spawnCenter     = new IntVec3(80, 0, 35);
                incidentParms.raidStrategy    = RaidStrategyDefOf.ImmediateAttack;
                incidentParms.points          = this.currentFight.points;
                incidentParms.raidArrivalMode = PawnsArriveMode.EdgeWalkIn;
                incidentDef.Worker.TryExecute(incidentParms);

                List <Brain> newBrains = new List <Brain>(Find.SquadBrainManager.allSquadBrains);
                foreach (Brain b in oldBrains)
                {
                    newBrains.Remove(b);
                }

                this.currentBrain1  = this.GetBrain(this.currentFight.factionOne, newBrains);
                this.currentBrain2  = this.GetBrain(this.currentFight.factionTwo, newBrains);
                this.currentPoints1 = this.BrainPoints(this.currentBrain1);
                this.currentPoints2 = this.BrainPoints(this.currentBrain2);

                this.remainingTicks = MapComponentFactionGauntlet.roundLenght;
                this.stage          = ExecutingStage.Fighting;
                break;

            case ExecutingStage.Fighting:

                this.currentPoints1 = this.BrainPoints(this.currentBrain1);
                this.currentPoints2 = this.BrainPoints(this.currentBrain2);

                if ((this.currentPoints1 == 0.0f) ||
                    (this.currentPoints2 == 0.0f))
                {
                    this.EndFight();
                    return;
                }

                if (this.style.Value == FightStyle.TimedRounds)
                {
                    if (this.remainingTicks > 0)
                    {
                        this.remainingTicks--;
                    }
                    else
                    {
                        this.EndFight();
                        return;
                    }
                }

                break;

            case ExecutingStage.CleaningArena:
                this.remainingTicks--;
                if (this.remainingTicks <= 0)
                {
                    this.stage = ExecutingStage.CreatingArena;
                }
                break;
            }
        }