Beispiel #1
0
        private void CheckTriggers()
        {
            if (triggersCache == null)
            {
                BuildRaidTriggersCache();
            }

            foreach (RaidTrigger raidTrigger in triggersCache)
            {
                if (raidTrigger.IsTriggered() == false || raidTrigger.TicksLeft() > 0)
                {
                    return;
                }
            }

            //we got here only when all triggers have fired.
            if (state == RuinedBaseState.FightingWaves)
            {
                if (unlockHysteresisTimeout == 0)
                {
                    state = RuinedBaseState.WaitingForEnemiesToBeDefeated;
                    //Debug.Message("All triggers fired and expired, and we've wait safety margin => can wait before hostiled defeating and map unlocking");
                }
                else
                {
                    unlockHysteresisTimeout--;
                }
            }
        }
Beispiel #2
0
 public override void PostMapGenerate()
 {
     base.PostMapGenerate();
     if (state == RuinedBaseState.WaitingForArrival)
     {
         state = RuinedBaseState.FightingWaves;
         BuildRaidTriggersCache();
         //Debug.Message("Built cache, cache has size of {0}", triggersCache.Count);
     }
 }
Beispiel #3
0
        public override void CompTick()
        {
            base.CompTick();
            if (ShouldRemoveWorldObjectNow)
            {
                Find.WorldObjects.Remove(parent);
            }

            if (state == RuinedBaseState.Inactive)
            {
                return;
            }


            if (!ParentHasMap)
            {
                //base "do maradeur" act chance is once per 1.5 game days, but high activity can make it as often as once per game hour
                if (Rand.Chance(0.00001f + (float)raidersActivity / 50000000.0f) || raidersActivity * 4 > currentCapCost / 2)
                {
                    int stolenAmount = (int)(Rand.Range(0.05f, 0.2f) * (raidersActivity / 12000.0f) * currentCapCost);
                    currentCapCost -= Math.Max(stolenAmount, (int)(raidersActivity * 4));
                    raidersActivity = raidersActivity / Rand.Range(2.0f, 5.0f);
                }

                raidersActivity += Rand.Range(-.1f, 0.25f) * currentCapCost / 100000.0f;
                if (raidersActivity < 0)
                {
                    raidersActivity = 0;
                }

                if ((currentCapCost < 20000 && Rand.Chance(0.00001f)) || currentCapCost <= 100)
                {
                    state = RuinedBaseState.ScavengedCompletely;
                }
            }

            //Do not remember if faction of pristine ruins does matter somehow. It actually shouldn't.
            //This should be removed, but just in case it is needed for some reason, I'll leave it, but add check fro reformingType = 1 (instant reforing), because for other modes this yields caravan items unloading.
            if (ParentHasMap && parent.Faction != Faction.OfPlayer && RealRuins_ModSettings.caravanReformType == 1)
            {
                if (!GenHostility.AnyHostileActiveThreatToPlayer((parent as MapParent).Map))
                {
                    //show letter about enemies defeated
                    Debug.Log(Debug.Generic, "pristine ruins was cleared, changing faction");
                    parent.SetFaction(Faction.OfPlayer);
                    // parent as MapParent
                }
            }


            if (RealRuins_ModSettings.caravanReformType == 2 && ParentHasMap)
            {
                if (state == RuinedBaseState.FightingWaves)
                {
                    CheckTriggers();
                }
                else if (state == RuinedBaseState.WaitingForEnemiesToBeDefeated)
                {
                    //AnyHostileActiveThreatToPlayer is a proxy call to AnyHostileActiveThreatTo, but it is postfixed with additional check by this mod.
                    //Here I want to do original check, without my postfix, so I call directly the checking method. So-so solution, but cant think of anything better AND worthwhile
                    if (!GenHostility.AnyHostileActiveThreatTo((parent as MapParent).Map, Faction.OfPlayer))
                    {
                        unlockTargetTime = Find.TickManager.TicksGame + Rand.Range(30000, 30000 + currentCapCost);
                        state            = RuinedBaseState.WaitingTimeoutAfterEnemiesDefeat;
                        //Debug.Message("no more hostiles. time: {0}, unlocktime: {1}", Find.TickManager.TicksGame, unlockTargetTime);
                    }
                }
                else if (state == RuinedBaseState.WaitingTimeoutAfterEnemiesDefeat)
                {
                    if (Find.TickManager.TicksGame > unlockTargetTime)
                    {
                        state = RuinedBaseState.WaitingToBeInformed;
                        string text = "RealRuins.NoMoreEnemies".Translate();
                        Messages.Message(text, parent, MessageTypeDefOf.PositiveEvent);
                        state = RuinedBaseState.InformedWaitingForLeaving;
                    }
                }
            }
        }
Beispiel #4
0
 public void StartScavenging(int initialCost)
 {
     currentCapCost  = initialCost;
     raidersActivity = 0;
     state           = RuinedBaseState.WaitingForArrival;
 }