public override void DoEveryStep() { if (Origin == null || !pathfinder.CanGoTo(X, Y, Prevx, Prevy, data)) { DestroySelf(); } string spot = X + "_" + Y; if (!VisitedSpots.Contains(spot)) { VisitedSpots.Add(spot); } //random movement if walktime > 0 if (lifeTime > 0) { lifeTime--; if (WalkTime > 0) { UpdateRandomMovement(); WalkTime--; } else if (RestTime > 0) { Stuck = true; RestTime--; } else { Stuck = false; WalkTime = walkTimeMax; RestTime = restTimeMax; } } //if time is up and there's no path, find one else if (Path == null) { ReturnHome(); } //if a path is supposed to exist else if (data.ReturningHome) { //if the path is still there, follow it if (Path.Count > 0) { UpdatePathedMovement(); } //otherwise kill it else { DestroySelf(); } } }
void UpdateCleanliness() { string spot = X + "_" + Y; if (!world.Map.IsUnblockedRoadAt(X, Y) || VisitedSpots.Contains(spot)) { return; } VisitedSpots.Add(spot); int localCleanliness = world.Map.cleanliness[X, Y]; int previousAvg = yield; int tiles = VisitedSpots.Count; yield = (int)((tiles - 1) * previousAvg + localCleanliness * Multiplier) / tiles; //Debug.Log(spot + VisitedSpots.Contains(spot) + " - " + yield); }
public override void VisitBuilding(int a, int b) { base.VisitBuilding(a, b); House h = world.Map.GetBuildingAt(a, b).GetComponent <House>(); if (h == null) { return; } if (VisitedSpots.Contains(h.name)) { return; } else { VisitedSpots.Add(h.name); } SetDemand(h); GiveFoodTo(h); }
public override void VisitBuilding(int a, int b) { base.VisitBuilding(a, b); House house = world.Map.GetBuildingAt(a, b).GetComponent <House>(); if (house == null) { return; } //give water regardless of how many times visited if (house.WillAcceptWaterVisit(waterQuality)) { house.ReceiveWater(waterQuality, waterQuantity); } //check if spot visited string spot = a + "_" + b; if (VisitedSpots.Contains(spot)) { return; } VisitedSpots.Add(spot); //house has been visited //give water UpdateCleanliness(); //yield is the average filthiness of roads that the wellwalker has walked on //give disease if (yield != 0) { TryDisease(house); } }
void Update() { TimeDelta += Time.deltaTime; if (WalkTime != 0) { Move(); } if (TimeDelta > MovementTime) { TimeDelta = 0; if (Origin == null || !CanGoTo(X, Y)) { Kill(); } string spot = X + "_" + Y; if (!VisitedSpots.Contains(spot)) { VisitedSpots.Add(spot); } //random movement if walktime > 0 if (lifeTime > 0) { lifeTime--; if (WalkTime > 0) { UpdateRandomMovement(); WalkTime--; } else if (RestTime > 0) { Stuck = true; RestTime--; } else { Stuck = false; WalkTime = walkTimeMax; RestTime = restTimeMax; } } //if time is up and there's no path, find one else if (Path == null) { ReturnHome(); } //if a path is supposed to exist else if (ReturningHome) { //if the path is still there, follow it if (Path.Count > 0) { UpdateAStarMovement(); } //otherwise kill it else { Kill(); } } } }