public override float Execute(UrbAgent Instigator, UrbAgent Target, float Modifier = 0) { if (Instigator.WasDestroyed || Target.WasDestroyed) { return(0); } using (s_AttackAction_p.Auto()) { float Result = base.Execute(Instigator, Target, Modifier); if (!(Result > 0)) { return(Result); } //Instigator.CurrentTile.AddScent(UrbScentTag.Violence, Result); UrbAction DefenseAction = Target.PickAction(DefenseCategory, Result); if (DefenseAction != null) { Result -= DefenseAction.Execute(Target, Instigator); } if (Result > 0) { Result = DamageAction.Execute(Instigator, Target, Result); } return(Result); } }
public void DepartFromTile(UrbTile Tile, UrbAgent Agent) { int Xoffset = 0; int Yoffset = 0; if (X == 1 && Y == 1) { UnprintAtTile(Print[0][0], Tile, Agent); s_ArriveAtTile_p.End(); return; } if (X > 2 && Y > 2) { Vector2 Voffset = GetOffset(); Xoffset = (int)Voffset.x; Yoffset = (int)Voffset.y; } for (int y = 0; y < Print.Length; y++) { for (int x = 0; x < Print[y].Length; x++) { UrbTile FillingTile = Tile.GetRelativeTile(x + Xoffset, y + Yoffset); if (FillingTile == null) { continue; } UrbTileprintFill Fill = Print[y][x]; UnprintAtTile(Fill, FillingTile, Agent); } } }
public void OnAgentArrive(UrbAgent input) { Assert.IsNotNull(input); s_OnAgentArrive_p.Begin(input); Contents.Add(input); input.Tileprint.ArriveAtTile(this, input); input.CurrentTile = this; //TODO: What is a map, and why are we assigning it so frequently //I can only find OwningMap being set once, at game initialization... //Can we move CurrentMap to object initialization? input.CurrentMap = OwningMap; input.transform.localScale = new Vector3(this.OwningMap.TileSize, this.OwningMap.TileSize, this.OwningMap.TileSize) * input.SizeOffset; if (input.IsSmelly) { ScentDirty = true; } if (input.HasEnableBeenCalled) { CalculateRemainingCapacity(); UpdateClearance(); if (input.Shuffle) { VisualShuffle(); } } s_OnAgentArrive_p.End(); }
public override float TaskCompletionCostEstimate(UrbAgent Instigator, UrbTile WorkTile) { if (NoTarget) { return(float.MaxValue); } if (Instigator.HasAction(UrbTestCategory.Hold)) { UrbAction Action = Instigator.PickAction(UrbTestCategory.Hold); float Estimate = Action.CostEstimate(Instigator); float CarryAmount = Action.Test(Instigator); float TargetAmount = GoalSubstance.SubstanceAmount - _TargetTile[GoalSubstance.Substance]; if (CarryAmount >= TargetAmount) { return(Estimate); } else { return(Estimate * (TargetAmount / CarryAmount)); } } return(float.MaxValue); }
//TemplatesMatch tells us if these are the same type of entity or not. public bool TemplatesMatch(UrbAgent input) { //Don't trigger this codepath on agents that have been destroyed. Assert.IsFalse(WasDestroyed); Assert.IsFalse(input.WasDestroyed); if (Removing) { Debug.Log("Cannot merge component because Agent was removing/Destroyed or input was destroyed", this); return(false); } if (string.IsNullOrWhiteSpace(AgentLocalName)) { AgentLocalName = gameObject.name.Split('(')[0]; } var templatesMatch = string.Compare(AgentLocalName, input.AgentLocalName, true) == 0; if (!templatesMatch && LogMe) { Debug.Log($"Local Name: {AgentLocalName} != input name: {input.AgentLocalName}", this); } return(templatesMatch); }
public virtual float GiveTo(UrbAgent Target, UrbSubstanceTag Substance) { if (!Target.HasBody) { return(0); } float Amount = 0; UrbAction HoldAction = mAgent.PickAction(UrbTestCategory.Hold); if (HoldAction != null) { Amount = HoldAction.Execute(mAgent, Target); if (Target.IsGrasper) { Target.Grasper.TakeFrom(mAgent, Substance); } else if (Target.IsEater) { Amount = HeldComposition.TransferTo(Target.Eater.Stomach, Substance, Amount); } else { Amount = HeldComposition.TransferTo(Target.mBody.BodyComposition, Substance, Amount); } } return(Amount); }
public override float PerformTask(UrbAgent Instigator, UrbTile WorkTile) { if (NoTarget || WorkTile.Occupants.Count == 0) { return(0); } if (Instigator.HasAction(UrbTestCategory.Hold)) { UrbAction Action = Instigator.PickAction(UrbTestCategory.Hold); float CarryAmount = 0; if (WorkTile == TargetTile) { } else { for (int o = 0; o < WorkTile.Occupants.Count; o++) { } } } return(0); }
public override float Test(UrbAgent target, float Modifier = 0) { float Teeth = target.mBody.BodyComposition[UrbSubstanceTag.Teeth]; Assert.IsFalse(float.IsInfinity(Teeth) || float.IsNaN(Teeth)); return(Mathf.Max(0, Teeth + MobilityTest(target.mBody) + Modifier)); }
public override void DisplayActionIcon(UrbAgent Target, Vector3 Location) { if (Target.Display == null || ActionIcon == null) { return; } Target.Display.QueueEffectDisplay(this, Location, true); }
public virtual void DisplayActionIcon(UrbAgent Target, Vector3 Location) { if (Target.Display == null || ActionIcon == null) { return; } Target.Display.QueueEffectDisplay(this, Location, false); }
public UrbTile[] GetAdjacentPrintTiles(UrbAgent Agent, bool GetLinked = false) { if (Agent.IsCurrentMapNull || Agent.CurrentTile == null) { return(new UrbTile[0]); } return(GetAdjacentPrintTiles(Agent.CurrentTile, GetLinked)); }
public UrbTile[] GetBorderingTiles(UrbAgent Agent, bool GetLinked = false, int Distance = 0) { if (Agent.IsCurrentMapNull || Agent.CurrentTile == null) { return(new UrbTile[0]); } return(GetBorderingTiles(Agent.CurrentTile, GetLinked, Distance)); }
public virtual float Test(UrbAgent target, float Modifier = 0.0f) { UrbBody TestBody = target.mBody; Debug.Log(this.GetType() + " Using Default Test"); float Result = Modifier; return(Result); }
public override bool TaskValid(UrbAgent TaskedAgent) { if (NoTarget) { return(false); } return(TaskedAgent.HasAction(UrbTestCategory.Hold)); }
public UrbTile[] GetAllPrintTiles(UrbAgent Agent) { if (Agent.IsCurrentMapNull || Agent.CurrentTile == null) { return(new UrbTile[0]); } return(GetAllPrintTiles(Agent.CurrentTile)); }
private void SetOffspringTemplate(int Choice) { if (Choice != OffspringChoice && Choice > -1 && Choice < OffspringObjects.Length) { OffspringChoice = Choice; OffspringTemplate = OffspringObjects[OffspringChoice]; OffspringAgent = OffspringTemplate.GetComponent <UrbAgent>(); } }
public override float Execute(UrbAgent Instigator, UrbAgent Target, float Modifier = 0) { float Result = Modifier; Result = Target.mBody.BodyComposition.Membrane.Impact(Instigator.mBody.BodyComposition, DamageSubstance, Result); Target.Express(UrbDisplayFace.Expression.Flinch); DisplayActionIcon(Instigator, Target.Location); return(Modifier); }
public static void UnregisterAgent(UrbAgent Input) { s_UrbAgentMgr_UnRegister_p.Begin(); if (Uninitialized) { return; } //We can attempt removal without checking if it contains //If we don't contain it... is a no-op. Agents.Remove(Input); s_UrbAgentMgr_UnRegister_p.End(); }
protected void SetOffspringData(UrbAgent Offspring) { if (Offspring == null || !Offspring.IsBreeder) { return; } UrbObjectData[] ChildOffspringData = new UrbObjectData[OffspringData.Length]; OffspringData.CopyTo(ChildOffspringData, 0); Offspring.Breeder.OffspringData = ChildOffspringData; }
protected void MergeIntoTarget(UrbAgent Target) { logger.Log("Attempting to merge", Target); mAgent.mBody.BodyComposition.EmptyInto(Target.mBody.BodyComposition); if (Target.IsEater && !Target.Eater.WasDestroyed) { if (IsEater && !Eater.WasDestroyed) { Eater.Stomach.EmptyInto(Target.Eater.Stomach); } } mAgent.Remove(); }
public static UrbAgent LoadAgentFromID(int ID, UrbTile Tile, UrbObjectData Data) { if (ID < 0 || !HasInstance || ID >= Instance.AgentTypes.Count) { return(null); } if (!UrbAgentSpawner.SpawnAgent(Instance.AgentTypes[ID], Tile, out var AgentObject, Data)) { return(null); } UrbAgent LoadedAgent = AgentObject.GetComponent <UrbAgent>(); return(LoadedAgent); }
public static int GetAgentID(UrbAgent input) { if (!HasInstance) { return(-1); } for (int i = 0; i < Instance.AgentTypes.Count; i++) { UrbAgent candidate = Instance.AgentTypes[i]; if (candidate.TemplatesMatch(input)) { return(i); } } return(-1); }
public static void RegisterAgent(UrbAgent Input) { s_UrbAgentMgr_Register_p.Begin(Input); if (Uninitialized) { Initialize(); } if (Agents.Contains(Input)) { s_UrbAgentMgr_Register_p.End(); return; } Agents.Add(Input); s_UrbAgentMgr_Register_p.End(); }
public override void MouseClick(UrbTile currentCursorTile) { Ray mouseray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 Location = mouseray.origin; Collider2D Result = Physics2D.OverlapCircle(Location, 0.1f); if (Result != null) { UrbAgent SelectedAgent = Result.GetComponentInParent <UrbAgent>(); if (SelectedAgent != null) { SelectedAgent.Remove(); } } base.MouseClick(currentCursorTile); }
public override float Execute(UrbAgent Instigator, UrbAgent Target, float Modifier = 0) { if (Instigator != Target) { Debug.LogWarning("Illegal Action: " + Instigator.name + " trying to recover for " + Target.name); return(0); } float Result = Mathf.Min(Instigator.mBody.Utilization, Test(Instigator)); if (Instigator.HasMetabolism) { Instigator.Metabolism.SpendEnergy(Result); } Assert.IsFalse(float.IsInfinity(Result) || float.IsNaN(Result)); return(Result); }
public override float Execute(UrbAgent Instigator, UrbAgent Target, float Modifier = 0) { s_MoveAction_p.Begin(Instigator); float Result = Test(Instigator, Modifier); Result = Instigator.mBody.UtilizeBody(Result); if (Result > 0) { s_MoveAction_p_e.Begin(); UrbPathfinder Pathfinder = Instigator.GetComponent <UrbPathfinder>(); UrbMovement Movement = Instigator.GetComponent <UrbMovement>(); UrbTile Goal = null; if (!Pathfinder.WasDestroyed && Pathfinder.isActiveAndEnabled) { Goal = Pathfinder.GetNextGoal(); } if (!Movement.WasDestroyed && Movement.isActiveAndEnabled) { if (Goal != null && Goal != Instigator.CurrentTile) { DisplayActionIcon(Instigator, Instigator.Location); float AdjustedResult = Result / 10; Movement.Speed = AdjustedResult; Movement.EnergyCost = AdjustedResult; Movement.MoveTo(Goal); } s_MoveAction_p_e.End(); } else { s_MoveAction_p_e.End(); s_MoveAction_p.End(); //Debug.LogWarning("Illegal Action: Move Action Called on " + Instigator.name + " this Agent has no UrbMovement Component"); return(0); } } s_MoveAction_p.End(); return(Result); }
public virtual float Drop(UrbSubstance Substance, float Amount) { if (LastPileTile != mAgent.CurrentTile) { for (int o = 0; o < mAgent.CurrentTile.Occupants.Count; o++) { if (mAgent.CurrentTile.Occupants[o].TemplatesMatch(PileAgent)) { CurrentPile = mAgent.CurrentTile.Occupants[o]; } } LastPileTile = mAgent.CurrentTile; } if (CurrentPile == null) { } float Dropped = Amount; return(Dropped); }
public override void MouseClick(UrbTile currentCursorTile) { Ray mouseray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 Location = mouseray.origin; Collider2D Result = Physics2D.OverlapCircle(Location, 0.1f); if (Result != null) { UrbAgent SelectedAgent = Result.GetComponentInParent <UrbAgent>(); if (SelectedAgent != null) { UrbAgentDetailWindow Window = Object.Instantiate(UrbUIManager.Instance.AgentDisplayPrefab, UrbUIManager.Instance.WindowManager.transform); Window.TargetAgent = SelectedAgent; UrbEventLogger.TargetAgent = SelectedAgent; } } base.MouseClick(currentCursorTile); }
public virtual float Execute(UrbAgent Instigator, UrbAgent Target, float Modifier = 0.0f) { if (Instigator.WasDestroyed || Target.WasDestroyed) { return(0.0f); } float Result = Modifier; Result += Test(Instigator, Modifier); Result = Instigator.mBody.UtilizeBody(Result); if (Result > 0) { DisplayActionIcon(Instigator, Instigator.Location); if (Instigator.Metabolism != null) { Instigator.Metabolism.SpendEnergy(Result); } } return(Result); }
public void OnAgentLeave(UrbAgent input, bool reorder = true) { Contents.Remove(input); s_OnAgentLeave_p.Begin(); input.Tileprint.DepartFromTile(this, input); if (input.IsSmelly) { ScentDirty = true; } CalculateRemainingCapacity(); UpdateClearance(); if (input.Shuffle) { VisualShuffle(); } s_OnAgentLeave_p.End(); }