Esempio n. 1
0
        /// <summary>
        /// Is the cell location <paramref name="cell"/> claimed for harvesting by any other actor?
        /// </summary>
        /// <param name="self"></param>
        /// <param name="cell"></param>
        /// <returns>true if already claimed by an ally that isn't <paramref name="self"/>; false otherwise.</returns>
        public bool IsClaimedByAnyoneElse(Actor self, CPos cell, out ResourceClaim claim)
        {
            if (claimByCell.TryGetValue(cell, out claim))
            {
                // Same claimer:
                if (claim.Claimer == self)
                {
                    return(false);
                }

                // This is to prevent in-fighting amongst friendly harvesters:
                if (self.Owner == claim.Claimer.Owner)
                {
                    return(true);
                }
                if (self.Owner.Stances[claim.Claimer.Owner] == Stance.Ally)
                {
                    return(true);
                }

                // If an enemy/neutral claimed this, don't respect that claim and fall through:
            }
            else
            {
                // No claim.
                claim = null;
            }

            return(false);
        }
Esempio n. 2
0
        public void OnNotifyResourceClaimLost(Actor self, ResourceClaim claim, Actor claimer)
        {
            if (self == claimer)
            {
                return;
            }

            // Our claim on a resource was stolen, find more unclaimed resources:
            self.CancelActivity();
            self.QueueActivity(new FindResources());
        }
Esempio n. 3
0
        private void Unclaim(ResourceClaim claim, Actor claimer)
        {
            if (claimByActor.Remove(claim.Claimer) & claimByCell.Remove(claim.Cell))
            {
                if (claim.Claimer.Destroyed)
                {
                    return;
                }
                if (!claim.Claimer.IsInWorld)
                {
                    return;
                }
                if (claim.Claimer.IsDead())
                {
                    return;
                }

                claim.Claimer.Trait <INotifyResourceClaimLost>().OnNotifyResourceClaimLost(claim.Claimer, claim, claimer);
            }
        }
Esempio n. 4
0
 private void MakeClaim(Actor claimer, CPos cell)
 {
     UnclaimByActor(claimer);
     UnclaimByCell(cell, claimer);
     claimByActor[claimer] = claimByCell[cell] = new ResourceClaim(claimer, cell);
 }
Esempio n. 5
0
		public void OnNotifyResourceClaimLost(Actor self, ResourceClaim claim, Actor claimer)
		{
			if (self == claimer) return;

			// Our claim on a resource was stolen, find more unclaimed resources:
			self.CancelActivity();
			self.QueueActivity(new FindResources());
		}