/// <summary> /// Every action happens here. /// </summary> public override void Update() { bool found; Point pos = Engine.GetMapObjectPosition(this, out found); if (found) { if (Amount == Capacity && (myNextOrder == Order.GoToFood || myNextOrder == Order.GoToWood || myNextOrder == Order.GoToGold)) { myNextOrder = Order.ReturnResource; if (RememberedReturnTarget == null) { RememberedReturnTarget = Engine.SearchClosestMainHall(pos); } } if (Amount == 0 && myNextOrder == Order.ReturnResource) { switch (CarriedResourceType) { case ResourceType.Gold: myNextOrder = Order.GoToGold; break; case ResourceType.Wood: myNextOrder = Order.GoToWood; break; case ResourceType.Food: myNextOrder = Order.GoToFood; break; } } switch (myNextOrder) { case Order.ReturnResource: MoveTarget = RememberedReturnTarget; break; case Order.Hunt: bool isDead; MoveTarget = Engine.SearchClosestPeacefulAnimalInRange(pos, SightRange, out isDead); if (isDead) { NextOrder = Order.GoToFood; RememberedGatherTarget = MoveTarget; } break; case Order.GoToFood: bool ResourceIsNotValid = true; foreach (MapObject mo in Engine.Map.GetCellAt(RememberedGatherTarget).MapObjects) { if (mo.GetType().IsSubclassOf(typeof(Resource))) { Resource res = (Resource)mo; if (res.Type == ResourceType.Food) { if (mo.GetType().IsSubclassOf(typeof(Animal))) { Animal animal = (Animal)mo; if (animal.Dead) { ResourceIsNotValid = false; } } else { ResourceIsNotValid = false; } } } } if (ResourceIsNotValid) { myNextOrder = Order.Hunt; MoveTarget = Engine.SearchClosestPeacefulAnimalInRange(pos, SightRange, out isDead); if (isDead) { NextOrder = Order.GoToFood; RememberedGatherTarget = MoveTarget; } } MoveTarget = RememberedGatherTarget; break; case Order.GoToGold: ResourceIsNotValid = true; foreach (MapObject mo in Engine.Map.GetCellAt(RememberedGatherTarget).MapObjects) { if (mo.GetType().IsSubclassOf(typeof(Resource))) { Resource res = (Resource)mo; if (res.Type == ResourceType.Gold) { ResourceIsNotValid = false; } } } if (ResourceIsNotValid) { RememberedGatherTarget = Engine.SearchClosestResourceInRange(pos, ResourceType.Gold, SightRange); } MoveTarget = RememberedGatherTarget; break; case Order.GoToWood: ResourceIsNotValid = true; foreach (MapObject mo in Engine.Map.GetCellAt(RememberedGatherTarget).MapObjects) { if (mo.GetType().IsSubclassOf(typeof(Resource))) { Resource res = (Resource)mo; if (res.Type == ResourceType.Wood) { ResourceIsNotValid = false; } } } if (ResourceIsNotValid) { RememberedGatherTarget = Engine.SearchClosestResourceInRange(pos, ResourceType.Wood, SightRange); } MoveTarget = RememberedGatherTarget; break; } if (myNextOrder == Order.GoToFood || myNextOrder == Order.GoToGold || myNextOrder == Order.GoToWood) { Gather(pos); } if (myNextOrder == Order.ReturnResource) { ReturnResource(pos); } if (myNextOrder == Order.Build) { Build(pos); } if (myNextOrder == Order.Hunt) { Attack(pos); } Move(pos); } }