protected bool ResolveNavigation( MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { int2 pos = agent.GetPosition(); if (action == AGENT_ACTIONS.UP && pos.y < w.GetHeight() - 1) { if (CanMakeStepTo(pos.x, pos.y + 1, tales, agent.GetWeight())) { agent.MoveUp(); return(true); } } else if (action == AGENT_ACTIONS.DOWN && agent.GetPosition().y > 0) { if (CanMakeStepTo(pos.x, pos.y - 1, tales, agent.GetWeight())) { agent.MoveDown(); return(true); } } else if (action == AGENT_ACTIONS.LEFT && agent.GetPosition().x > 0) { if (CanMakeStepTo(pos.x - 1, pos.y, tales, agent.GetWeight())) { agent.MoveLeft(); return(true); } } else if (action == AGENT_ACTIONS.RIGHT && agent.GetPosition().x < w.GetWidth() - 1) { if (CanMakeStepTo(pos.x + 1, pos.y, tales, agent.GetWeight())) { agent.MoveRight(); return(true); } } return(false); }
protected bool ResolveNavigation( MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { int2 pos = agent.GetPosition(); if (action == AGENT_ACTIONS.UP && pos.y < w.GetHeight() - 1) { if (CanMakeStepTo(pos.x, pos.y + 1, tales, agent.GetWeight())) { agent.MoveUp(); return true; } } else if (action == AGENT_ACTIONS.DOWN && agent.GetPosition().y > 0) { if (CanMakeStepTo(pos.x, pos.y - 1, tales, agent.GetWeight())) { agent.MoveDown(); return true; } } else if (action == AGENT_ACTIONS.LEFT && agent.GetPosition().x > 0) { if (CanMakeStepTo(pos.x - 1, pos.y, tales, agent.GetWeight())) { agent.MoveLeft(); return true; } } else if (action == AGENT_ACTIONS.RIGHT && agent.GetPosition().x < w.GetWidth() - 1) { if (CanMakeStepTo(pos.x + 1, pos.y, tales, agent.GetWeight())) { agent.MoveRight(); return true; } } return false; }
protected bool ResolveCustomActions(MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { bool result = false; Tale t; if (action == AGENT_ACTIONS.BASIC) { t = tales[agent.GetPosition().x, agent.GetPosition().y]; for (int i = 0; i < t.Objects.Count; i++) { if (t.Objects[i] is TwoStateObjectControl) { if (t.Objects[i] is DoorControl) { if (!pars.ForceDoorSwitches) { ((DoorControl)t.Objects[i]).applyPressAction(); result = true; } } else if (t.Objects[i] is LightsControl) { if (!pars.ForceLightSwitches) { ((LightsControl)t.Objects[i]).applyPressAction(); result = true; } } else { ((TwoStateObjectControl)t.Objects[i]).applyPressAction(); result = true; } } } } if (pars.ForceDoorSwitches || pars.ForceLightSwitches) { for (int i = 0; i < tales.GetLength(0); i++) { for (int j = 0; j < tales.GetLength(1); j++) { t = tales[i, j]; if (t.Objects != null) { for (int k = 0; k < t.Objects.Count; k++) { if (t.Objects[k] is DoorControl && pars.ForceDoorSwitches) { DoorControl dc = (DoorControl)t.Objects[k]; if (dc.IsOn() != pars.ForceDoorSwitchesState) { dc.applyPressAction(); } } else if (t.Objects[k] is LightsControl && pars.ForceLightSwitches) { LightsControl lc = (LightsControl)t.Objects[k]; if (lc.IsOn() != pars.ForceLightSwitchesState) { lc.applyPressAction(); } } } } } } } return result; }
public override void Execute() { // draw the visible area of the map (empty and obstacle tales) MyGraphicsPrototype taleEmpty = Owner.m_tale_empty_g; MyGraphicsPrototype taleObstacle = Owner.m_tale_obstacle_g; m_drawTalesKernel.SetupExecution(Owner.VISIBLE_WIDTH * Owner.VISIBLE_HEIGHT); m_drawTalesKernel.Run(Owner.Visual, Owner.VISIBLE_WIDTH, Owner.VISIBLE_HEIGHT, Owner.MapTales, Owner.World.GetWidth(), Owner.World.GetHeight(), taleEmpty.Bitmap, taleObstacle.Bitmap, taleEmpty.PixelSize); // draw static objects MyStaticObject[] objects = Owner.World.GetStaticObjects(); for (int i = 0; i < objects.Length; i++) { MyStaticObject o = objects[i]; m_drawObjKernel.SetupExecution(o.Graphics.PixelSize.x * o.Graphics.PixelSize.y); m_drawObjKernel.Run(Owner.Visual, Owner.RES, Owner.VISIBLE_WIDTH, Owner.VISIBLE_HEIGHT, o.Graphics.Bitmap, o.GetPosition(), o.Graphics.PixelSize); } // draw the agent MyMovingObject agent = Owner.World.GetAgent(); MyGraphicsPrototype agent_g = agent.Graphics; m_agentPosition.x = agent.GetPosition().x *Owner.RES; m_agentPosition.y = (agent.GetPosition().y + 1) * Owner.RES - 1; if (!Owner.ShowInEgocentricView) { this.DrawEgocentric(); } if (Owner.UpdateTask.ContinuousMovement && Owner.m_performingMovement) { switch (Owner.LastAction) { case AGENT_ACTIONS.LEFT: { m_agentPosition.x += Owner.m_movementCooldown; break; } case AGENT_ACTIONS.RIGHT: { m_agentPosition.x -= Owner.m_movementCooldown; break; } case AGENT_ACTIONS.UP: { m_agentPosition.y -= Owner.m_movementCooldown; break; } case AGENT_ACTIONS.DOWN: { m_agentPosition.y += Owner.m_movementCooldown; break; } } m_drawFreeObjKernel.SetupExecution(agent_g.PixelSize.x * agent_g.PixelSize.y); m_drawFreeObjKernel.Run(Owner.Visual, Owner.VISIBLE_WIDTH, Owner.VISIBLE_HEIGHT, agent_g.Bitmap, m_agentPosition, agent_g.PixelSize); } else { m_drawObjKernel.SetupExecution(agent_g.PixelSize.x * agent_g.PixelSize.y); m_drawObjKernel.Run(Owner.Visual, Owner.RES, Owner.VISIBLE_WIDTH, Owner.VISIBLE_HEIGHT, agent_g.Bitmap, agent.GetPosition(), agent_g.PixelSize); } if (Owner.ShowInEgocentricView) { this.DrawEgocentric(); } }
protected bool ResolveCustomActions(MyMovingObject agent, Tale[,] tales, AGENT_ACTIONS action) { bool result = false; Tale t; if (action == AGENT_ACTIONS.BASIC) { t = tales[agent.GetPosition().x, agent.GetPosition().y]; for (int i = 0; i < t.Objects.Count; i++) { if (t.Objects[i] is TwoStateObjectControl) { if (t.Objects[i] is DoorControl) { if (!pars.ForceDoorSwitches) { ((DoorControl)t.Objects[i]).applyPressAction(); result = true; } } else if (t.Objects[i] is LightsControl) { if (!pars.ForceLightSwitches) { ((LightsControl)t.Objects[i]).applyPressAction(); result = true; } } else { ((TwoStateObjectControl)t.Objects[i]).applyPressAction(); result = true; } } } } if (pars.ForceDoorSwitches || pars.ForceLightSwitches) { for (int i = 0; i < tales.GetLength(0); i++) { for (int j = 0; j < tales.GetLength(1); j++) { t = tales[i, j]; if (t.Objects != null) { for (int k = 0; k < t.Objects.Count; k++) { if (t.Objects[k] is DoorControl && pars.ForceDoorSwitches) { DoorControl dc = (DoorControl)t.Objects[k]; if (dc.IsOn() != pars.ForceDoorSwitchesState) { dc.applyPressAction(); } } else if (t.Objects[k] is LightsControl && pars.ForceLightSwitches) { LightsControl lc = (LightsControl)t.Objects[k]; if (lc.IsOn() != pars.ForceLightSwitchesState) { lc.applyPressAction(); } } } } } } } return(result); }