public AIGoalBladder(AIAgent agent) : base(agent) { BasePriority = 3f; PreConditions.Add("bladder", true); PostConditions.Add("bladder", false); }
public AIGoal(AIAgent agent) { mAgent = agent; }
public AIActionStateDiscardLitter(AIAgent owner) : base(owner) { }
public override void Update(float dt, AIAgent agent) { base.Update(dt, agent); }
public AIActionState(AIAgent owner) { Owner = owner; }
public override void OnStateEnter() { Context.Context.ScreenClearColor = Color.Black; rand = new Random(); MapGenerator.GenerateMap(30, 1); Random rnd = new Random(); for (int i = 0; i < 100 ; i++) { VisitorAgent go = new VisitorAgent(new Vector2(50, -80), 1); go.MaxHealth = 1; go.Name = "test"; go.MyTexture = TextureManager.TextureDictionary["testSprite"]; go.Size = new Vector2(20, 20); Game1.AddGameObject(go); agent = go; bool foundTile = false; while (!foundTile) { int x = rnd.Next(1, 39); // creates a number between 1 and 12 int y = rnd.Next(1, 39); go.CurrentTile = MapGenerator.Map[x, y]; foundTile = go.CurrentTile.Walkable; } go.Position = go.CurrentTile.Position; //AIActionMoveTo action = new AIActionMoveTo(); // action.Target = MapGenerator.Map[x, y]; // action.MyAgent = go; go.Home = go.CurrentTile; // action.SetTarget(MapGenerator.Map[10,10], go); // go.JobQueue.Add(action); if (i < 100) { go.Team = 1; } else { go.Team = 2; go.MyTexture = TextureManager.TextureDictionary["trump"]; } } DrinkObject drink = new DrinkObject(); drink.MyTexture = TextureManager.TextureDictionary["drinkstand"]; drink.CurrentTile = MapGenerator.Map[10, 10]; drink.Position = new Vector2(500, 500); Game1.AddGameObject(drink); drink = new DrinkObject(); drink.MyTexture = TextureManager.TextureDictionary["drinkstand"]; drink.CurrentTile = MapGenerator.Map[30, 30]; drink.Position = new Vector2(1500, 1500); Game1.AddGameObject(drink); EatableObject eat = new EatableObject(); eat.MyTexture = TextureManager.TextureDictionary["burgerstand"]; eat.CurrentTile = MapGenerator.Map[20, 20]; eat.Position = new Vector2(1000, 1000); Game1.AddGameObject(eat); eat = new EatableObject(); eat.MyTexture = TextureManager.TextureDictionary["burgerstand"]; eat.CurrentTile = MapGenerator.Map[15, 15]; eat.Position = new Vector2(750, 750); Game1.AddGameObject(eat); Tile t = MapGenerator.GetTileAtPosition(new Vector2(0, 0)); t = MapGenerator.GetTileAtPosition(new Vector2(120, 60)); t = MapGenerator.GetTileAtPosition(new Vector2(320, 418)); ToiletObject to = new ToiletObject(); to.MyTexture = TextureManager.TextureDictionary["toilet"]; to.CurrentTile = MapGenerator.Map[15, 25]; to.Position = new Vector2(750, 1250); Game1.AddGameObject(to); Bin bin = new Bin(); bin.CurrentTile = MapGenerator.Map[12, 12]; bin.Position = new Vector2(600, 600); Game1.AddGameObject(bin); JanitorAgent j = new JanitorAgent(new Vector2(50, -80), 1); j.MaxHealth = 1; j.Name = "test"; j.MyTexture = TextureManager.TextureDictionary["trump"]; j.Size = new Vector2(20, 20); Game1.AddGameObject(j); bool found = false; while (!found) { int x = rnd.Next(1, 39); // creates a number between 1 and 12 int y = rnd.Next(1, 39); j.CurrentTile = MapGenerator.Map[x, y]; found = j.CurrentTile.Walkable; } j.Position = j.CurrentTile.Position; //AIActionMoveTo action = new AIActionMoveTo(); // action.Target = MapGenerator.Map[x, y]; // action.MyAgent = go; j.Home = j.CurrentTile; JanitorAgent j2 = new JanitorAgent(new Vector2(50, -80), 1); j2.MaxHealth = 1; j2.Name = "test"; j2.MyTexture = TextureManager.TextureDictionary["trump"]; j2.Size = new Vector2(20, 20); Game1.AddGameObject(j2); bool found3 = false; while (!found3) { int x = rnd.Next(1, 39); // creates a number between 1 and 12 int y = rnd.Next(1, 39); j2.CurrentTile = MapGenerator.Map[x, y]; found3 = j2.CurrentTile.Walkable; } j2.Position = j2.CurrentTile.Position; //AIActionMoveTo action = new AIActionMoveTo(); // action.Target = MapGenerator.Map[x, y]; // action.MyAgent = go; j2.Home = j2.CurrentTile; }
public AIGoalDrink(AIAgent agent) : base(agent) { BasePriority = 1.5f; PreConditions.Add("thirsty", true); PostConditions.Add("thirsty", false); }
public AIActionStateEatFood(AIAgent owner) : base(owner) { }
public AIGoalLeave(AIAgent agent) : base(agent) { BasePriority = 0.5f; PostConditions.Add("left", true); }
public void Update(float dt, AIAgent agent) { MyAgent = agent; CurPathReset -= dt; //if (CurPathReset < 0) //{ // CurPathReset = MaxPathReset; // if (AgentTarget != null) // { // SetTarget(AgentTarget, agent); // } // else // { // if (Target != null) // { // SetTarget(Target, agent); // } // } //} if (Path.Count() > 0) { if (Vector2.Distance(agent.Position, Path[0].Position) < 5) { agent.CurrentTile = Path[0]; Path.RemoveAt(0); } } if (Path.Count() == 0 && CheckedOnce) { } Vector2 totalDir = new Vector2(0, 0); Vector2 pathTargetDir = new Vector2(0, 0); float pathSteerWeight = 2; float unitAvoidanceWeight = 1.5f; //if (Path.Count() > 0) //{ // pathTargetDir = Path[0].Position - agent.Position; // pathTargetDir.Normalize(); // pathTargetDir *= agent.Speed * dt; // agent.Position += pathTargetDir; //} if (Path.Count() > 0) { pathTargetDir = Path[0].Position - agent.Position; if (AgentTarget != null) { pathTargetDir = AgentTarget.Position - agent.Position; } pathTargetDir.Normalize(); pathTargetDir *= pathSteerWeight; float closestDistance = 9999999; Agent closestAgent; closestAgent = MyAgent; Rectangle rect = new Rectangle(); rect.Position = agent.Position; rect.Size = new Vector2(50, 50); var q = Game1.quadtree.CircleQuery(agent.Position, 50); //var t = new List<GameObject>(); //var l = Game1.GameObjects.Where(o => o is Agent); // foreach(var f in l) //{ // if(Vector2.Distance(f.Position, this.MyAgent.Position) < 300) // { // t.Add(f); // } //} foreach (var go in q.Where(o => o is Agent)) { if (go != this.MyAgent) { if (Vector2.Distance(go.Position, this.MyAgent.Position) < closestDistance) { if (((Agent)go) != agent.TargetAgent) { closestAgent = ((Agent)go); closestDistance = Vector2.Distance(go.Position, this.MyAgent.Position); } } } } if (closestAgent != null && closestAgent != MyAgent) { Vector2 agentAvoidDir = closestAgent.Position - MyAgent.Position; agentAvoidDir.Normalize(); agentAvoidDir *= -unitAvoidanceWeight; totalDir += agentAvoidDir; } totalDir += pathTargetDir; totalDir.Normalize(); totalDir *= agent.Speed * dt; agent.Position += totalDir; } }
public AIActionStateMovingTo(AIAgent owner) : base(owner) { }