//this method is utilized by DispatchMessage or DispatchDelayedMessages. //This method calls the message handling member function of the receiving //entity, pReceiver, with the newly created telegram public void Discharge(BaseGameEntity pReceiver, Telegram telegram) { if (!pReceiver.HandleMessage(telegram)) { Debug.WriteLine("Telegram could not be handled"); } }
public StateMachine(BaseGameEntity owner) { m_pOwner = owner; m_pCurrentState = null; m_pPreviousState = null; m_pGlobalState = null; }
public override void Execute(BaseGameEntity pEntity) { Miner pMiner = (Miner)pEntity; if (pMiner.HP == 1) { DebugMessages.Instance.WriteLine(String.Format("{0}: Dang it, defeated by a drunkard!", MainSM.GetEntityName(pEntity.ID()))); // Lost fight! Tell Joe we are done. MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_BarFly, (int)message_type.Msg_DeclineFight, (int)MessageDispatcher.NO_ADDITIONAL_INFO); pMiner.GetFSM().RevertToPreviousState(); } else { // Throw a punch DebugMessages.Instance.WriteLine(String.Format("{0}: Take this, drunken varmint!", MainSM.GetEntityName(pEntity.ID()))); MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_BarFly, (int)message_type.Msg_IncomingPunch, (int)MessageDispatcher.NO_ADDITIONAL_INFO); } }
public override void Enter(BaseGameEntity pEntity) { BarFlyJoe joe = (BarFlyJoe)pEntity; // reset Stats joe.Drunkeness = -joe.Drunkeness; joe.Angered = false; DebugMessages.Instance.WriteLine(String.Format("{0}: Time to do some chillin'!", MainSM.GetEntityName(pEntity.ID()))); }
public override void Enter(BaseGameEntity pEntity) { DebugMessages.Instance.WriteLine(String.Format("{0}: Time to pick a fight!", MainSM.GetEntityName(pEntity.ID()))); MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_Miner_Bob, (int)message_type.Msg_Antagonize, (int)MessageDispatcher.NO_ADDITIONAL_INFO); }
public override void Execute(BaseGameEntity pEntity) { MinersWife wife = (MinersWife)pEntity; //1 in 10 chance of needing the bathroom (provided she is not already //in the bathroom) if ((Utils.RandFloat() < 0.1) && !wife.GetFSM().isInState(typeof(VisitBathroom))) { wife.GetFSM().ChangeState(new VisitBathroom()); } }
//------------------------- Overlapped ----------------------------------- // // tests to see if an entity is overlapping any of a number of entities // stored in a std container //------------------------------------------------------------------------ public static bool Overlapped(BaseGameEntity ob, List <BaseGameEntity> conOb, double MinDistBetweenObstacles) { foreach (BaseGameEntity it in conOb) { if (TwoCirclesOverlapped(ob.Pos, ob.BRadius + MinDistBetweenObstacles, it.Pos, it.BRadius)) { return(true); } } return(false); }
public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram) { Miner pMiner = (Miner)pEntity; switch (pTelegram.Msg) { case (int)message_type.Msg_Antagonize: { double CurrentTime = MessageDispatcher.Instance.GetRunningTime(); DebugMessages.Instance.WriteLine(String.Format("Message handled by {0} at time: {1}", MainSM.GetEntityName(pEntity.ID()), CurrentTime)); if (pMiner.Location == location_type.saloon) { if (Utils.RandFloat() <= 0.5) { MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_BarFly, (int)message_type.Msg_AcceptFight, (int)MessageDispatcher.NO_ADDITIONAL_INFO); pMiner.GetFSM().ChangeState(new BobFight()); } else { DebugMessages.Instance.WriteLine(String.Format("{0}: No, I can't be bothered to fight you drunken fool!", MainSM.GetEntityName(pEntity.ID()))); MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_BarFly, (int)message_type.Msg_DeclineFight, (int)MessageDispatcher.NO_ADDITIONAL_INFO); } } return true; } } return false; }
public override void Execute(BaseGameEntity pEntity) { BarFlyJoe joe = (BarFlyJoe)pEntity; if (!joe.Angered) { DebugMessages.Instance.WriteLine(String.Format("{0}: Ahh, jus' drinkin'", MainSM.GetEntityName(pEntity.ID()))); joe.Drunkeness = joe.Drunkeness + 1; if (joe.Drunkeness > BarFlyJoe.AlchoAngerSwitch) { DebugMessages.Instance.WriteLine(String.Format("{0}: Feelin drunk and angry! I need a fight...", MainSM.GetEntityName(pEntity.ID()))); joe.Angered = true; } } if (joe.Angered) { Miner bob = (Miner)MessageDispatcher.Instance.GetRegisteredEntityFromID((int)EntityName.ent_Miner_Bob); if (bob.Location != location_type.saloon) { if (Utils.RandFloat() <= 0.5) { DebugMessages.Instance.WriteLine(String.Format("{0}: Damnit no one here to fight with!", MainSM.GetEntityName(pEntity.ID()))); } else { DebugMessages.Instance.WriteLine(String.Format("{0}: Burp! Grr Im not a happy *hic* cowboy.", MainSM.GetEntityName(pEntity.ID()))); } } else { joe.GetFSM().ChangeState(new JoeDoAntagonizin()); } } }
public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram) { MinersWife wife = (MinersWife)pEntity; switch (pTelegram.Msg) { case (int)message_type.Msg_HiHoneyImHome: { double CurrentTime = MessageDispatcher.Instance.GetRunningTime(); DebugMessages.Instance.WriteLine(String.Format("Message handled by {0} at time: {1}", MainSM.GetEntityName(wife.ID()), CurrentTime)); DebugMessages.Instance.WriteLine(String.Format("{0}: Hi honey. Let me make you some of mah fine country stew", MainSM.GetEntityName(wife.ID()))); wife.GetFSM().ChangeState(new CookStew()); return true; } } return false; }
public override void Execute(BaseGameEntity pEntity) { switch (Utils.RandInt(0, 2)) { case 0: DebugMessages.Instance.WriteLine(String.Format("{0}: Moppin' the floor", MainSM.GetEntityName(pEntity.ID()))); break; case 1: DebugMessages.Instance.WriteLine(String.Format("{0}: Washin' the dishes", MainSM.GetEntityName(pEntity.ID()))); break; case 2: DebugMessages.Instance.WriteLine(String.Format("{0}: Makin' the bed", MainSM.GetEntityName(pEntity.ID()))); break; } }
//------------------------ GetClosestEntityLineSegmentIntersection ------------ // // tests a line segment AB against a container of entities. First of all // a test is made to confirm that the entity is within a specified range of // the one_to_ignore (positioned at A). If within range the intersection test // is made. // // returns the closest entity that tested positive for intersection or NULL // if none found //----------------------------------------------------------------------------- public static BaseGameEntity GetClosestEntityLineSegmentIntersection(List <BaseGameEntity> entities, int the_one_to_ignore, Vector2D A, Vector2D B, double range) { BaseGameEntity ClosestEntity = null; double ClosestDist = Double.MaxValue; //iterate through all entities checking against the line segment AB foreach (BaseGameEntity it in entities) { double distSq = Vector2D.Vec2DDistanceSq(it.Pos, A); //if not within range or the entity being checked is the_one_to_ignore //just continue with the next entity if ((it.ID() == the_one_to_ignore) || (distSq > range * range)) { continue; } //if the distance to AB is less than the entities bounding radius then //there is an intersection so add it to hits if (DistToLineSegment(A, B, it.Pos) < it.BRadius) { if (distSq < ClosestDist) { ClosestDist = distSq; ClosestEntity = it; } } } return(ClosestEntity); }
private void RenderObstacle(BaseGameEntity objObstacle, Graphics objGraphics, Pen objPen) { objGraphics.DrawEllipse(objPen, (int)(objObstacle.Pos.X - objObstacle.BRadius), (int)(objObstacle.Pos.Y - objObstacle.BRadius), (int)objObstacle.BRadius * 2, (int)objObstacle.BRadius * 2); }
public override void Exit(BaseGameEntity pEntity) { BarFlyJoe joe = (BarFlyJoe)pEntity; joe.HP = Miner.HPFull; }
public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram) { BarFlyJoe joe = (BarFlyJoe)pEntity; switch (pTelegram.Msg) { case (int)message_type.Msg_IncomingPunch: { if (Utils.RandFloat() <= 0.5) { joe.HP = joe.HP - 1; DebugMessages.Instance.WriteLine(String.Format("{0}: Gaah Im hit!", MainSM.GetEntityName(pEntity.ID()))); } else { DebugMessages.Instance.WriteLine(String.Format("{0}: Missed me, sucker!", MainSM.GetEntityName(pEntity.ID()))); } return true; } case (int)message_type.Msg_DeclineFight: { DebugMessages.Instance.WriteLine(String.Format("{0}: That'll teach ya to mess with an alchoholic!", MainSM.GetEntityName(pEntity.ID()))); joe.GetFSM().ChangeState(new JoeDoChillin()); return true; } } return false; }
public override void Enter(BaseGameEntity pEntity) { DebugMessages.Instance.WriteLine(String.Format("{0}: Get over here!", MainSM.GetEntityName(pEntity.ID()))); }
public override void Execute(BaseGameEntity pEntity) { BarFlyJoe joe = (BarFlyJoe)pEntity; if (joe.HP == 1) { // Lost fight! Tell Bob we are done. DebugMessages.Instance.WriteLine(String.Format("{0}: Ok ok Im beat! Mercy!", MainSM.GetEntityName(pEntity.ID()))); MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_Miner_Bob, (int)message_type.Msg_DeclineFight, (int)MessageDispatcher.NO_ADDITIONAL_INFO); joe.GetFSM().ChangeState(new JoeDoChillin()); } else { // Throw a punch DebugMessages.Instance.WriteLine(String.Format("{0}: Eat mah knuckle!", MainSM.GetEntityName(pEntity.ID()))); MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, pEntity.ID(), (int)EntityName.ent_Miner_Bob, (int)message_type.Msg_IncomingPunch, (int)MessageDispatcher.NO_ADDITIONAL_INFO); } }
public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram) { BarFlyJoe joe = (BarFlyJoe)pEntity; switch (pTelegram.Msg) { case (int)message_type.Msg_DeclineFight: { DebugMessages.Instance.WriteLine(String.Format("{0}: Har har, ya'll a bunch o' yellow bellied chickens!", MainSM.GetEntityName(pEntity.ID()))); joe.GetFSM().ChangeState(new JoeDoChillin()); return true; } case (int)message_type.Msg_AcceptFight: { joe.GetFSM().ChangeState(new JoeFight()); return true; } } return false; }
public override void Enter(BaseGameEntity pEntity) { Miner pMiner = (Miner)pEntity; if (pMiner.Location != location_type.saloon) { pMiner.Location = location_type.saloon; DebugMessages.Instance.WriteLine(String.Format("{0}: Boy, ah sure is thusty! Walking to the saloon", MainSM.GetEntityName(pEntity.ID()))); } }
public override void Exit(BaseGameEntity pEntity) { DebugMessages.Instance.WriteLine(String.Format("{0}: Leavin' the bank", MainSM.GetEntityName(pEntity.ID()))); }
public override void Execute(BaseGameEntity pEntity) { Miner pMiner = (Miner)pEntity; pMiner.BuyAndDrinkAWhiskey(); DebugMessages.Instance.WriteLine(String.Format("{0}: That's mighty fine sippin' liquer", MainSM.GetEntityName(pEntity.ID()))); pMiner.GetFSM().ChangeState(new EnterMineAndDigForNugget()); }
public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram) { return false; }
public override bool OnMessage(BaseGameEntity pEntity, Telegram pTelegram) { Miner pMiner = (Miner)pEntity; switch (pTelegram.Msg) { case (int)message_type.Msg_StewReady: { DebugMessages.Instance.WriteLine(String.Format("Message handled by {0} at time {1}", MainSM.GetEntityName(pEntity.ID()), MessageDispatcher.Instance.GetRunningTime())); DebugMessages.Instance.WriteLine(String.Format("{0}: Okay Hun, ahm a comin'", MainSM.GetEntityName(pEntity.ID()))); pMiner.GetFSM().ChangeState(new EatStew()); return true; } }//end switch return false; //send message to global message handler }
public override void Enter(BaseGameEntity pEntity) { DebugMessages.Instance.WriteLine(String.Format("{0}: Smells Reaaal goood Elsa!", MainSM.GetEntityName(pEntity.ID()))); }
public override void Execute(BaseGameEntity pEntity) { }
public override void Execute(BaseGameEntity pEntity) { Miner pMiner = (Miner)pEntity; DebugMessages.Instance.WriteLine(String.Format("{0}: Tastes real good too!", MainSM.GetEntityName(pEntity.ID()))); pMiner.GetFSM().RevertToPreviousState(); }
public override void Enter(BaseGameEntity pEntity) { Miner pMiner = (Miner)pEntity; if (pMiner.Location != location_type.shack) { DebugMessages.Instance.WriteLine(String.Format("{0}: Walkin' home", MainSM.GetEntityName(pEntity.ID()))); pMiner.Location = location_type.shack; //let the wife know I'm home MessageDispatcher.Instance.DispatchMessage((int)MessageDispatcher.SEND_MSG_IMMEDIATELY, //time delay pMiner.ID(), //ID of sender (int)EntityName.ent_Elsa, //ID of recipient (int)message_type.Msg_HiHoneyImHome, //the message (int)MessageDispatcher.NO_ADDITIONAL_INFO); } }
public override void Exit(BaseGameEntity pEntity) { DebugMessages.Instance.WriteLine(String.Format("{0}: Thankya li'lle lady. Ah better get back to whatever ah wuz doin'", MainSM.GetEntityName(pEntity.ID()))); }
public void RegisterEntity(BaseGameEntity NewEntity) { m_dictEntities[NewEntity.ID()] = NewEntity; }
public override void Execute(BaseGameEntity pEntity) { Miner pMiner = (Miner)pEntity; //if miner is not fatigued start to dig for nuggets again. if (!pMiner.Fatigued()) { DebugMessages.Instance.WriteLine(String.Format("{0}: All mah fatigue has drained away. Time to find more gold!", MainSM.GetEntityName(pEntity.ID()))); pMiner.GetFSM().ChangeState(new EnterMineAndDigForNugget()); } else { //sleep pMiner.DecreaseFatigue(); DebugMessages.Instance.WriteLine(String.Format("{0}: ZZZZ... ", MainSM.GetEntityName(pEntity.ID()))); } }
public override void Exit(BaseGameEntity pEntity) { }
//--------------------------- CreateObstacles ----------------------------- // // Sets up the vector of obstacles with random positions and sizes. Makes // sure the obstacles do not overlap //------------------------------------------------------------------------ private void CreateObstacles() { //create a number of randomly sized tiddlywinks for (int o = 0; o < SteerParams.Instance.NumObstacles; ++o) { bool bOverlapped = true; //keep creating tiddlywinks until we find one that doesn't overlap //any others.Sometimes this can get into an endless loop because the //obstacle has nowhere to fit. We test for this case and exit accordingly int NumTrys = 0; int NumAllowableTrys = 2000; while (bOverlapped) { NumTrys++; if (NumTrys > NumAllowableTrys) return; int radius = Utils.RandInt((int)SteerParams.Instance.MinObstacleRadius, (int)SteerParams.Instance.MaxObstacleRadius); const int border = 10; const int MinGapBetweenObstacles = 20; Vector2D randomPos = new Vector2D(Utils.RandInt(radius + border, m_cxClient - radius - border), Utils.RandInt(radius + border, m_cyClient - radius - 30 - border)); BaseGameEntity ob = new BaseGameEntity(0, randomPos, radius); if (!Utils.Overlapped(ob, m_Obstacles, MinGapBetweenObstacles)) { //its not overlapped so we can add it m_Obstacles.Add(ob); bOverlapped = false; } else { ob = null; } } } }