//Send out any delayed messages. This method is called each time through //the main game loop public void DispatchDelayedMessages() { //first get current time double currentTime = DateTime.Now.Second; //Now peek at the queue to see if ane telegrams need dispatching. //remove all telegrams from the front of the queue that have gone //past their sell-by date. while (PriorityQ.Min.DispatchTime < currentTime && PriorityQ.Min.DispatchTime > 0) { //Read the telegram from the front of the queue Telegram telegram = PriorityQ.Min; //Find the recipient BaseGameEntity msgReceiver = EntityManager.Instance.GetEntityFromId(telegram.Receiver); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Queude telegram ready for dispatch: Sent to {0}", EnumsNames.GetNameOfEntity(msgReceiver.UniqueID)); Console.WriteLine("Msg is {0}", EnumsNames.GetMessageDescription(telegram.Msg)); //Send the telegram to the recipient Discharge(msgReceiver, telegram); //Remove it from the queue PriorityQ.Remove(telegram); } }
public override void Enter(Miner miner) { //on entry the miner makes sure he is located at the bank if (miner.Location != LocationType.Bank) { Console.ForegroundColor = Color; Console.WriteLine("{0}: Goin' to the bank. Yes siree", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.Location = LocationType.Bank; } }
public override void Enter(Miner miner) { //If the miner is not already located at the goldmine, he must //change location to the gold mine if (miner.Location != LocationType.Goldmine) { Console.ForegroundColor = Color; Console.WriteLine("{0}: Walkin' to the goldmine", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.Location = LocationType.Goldmine; } }
public override void Enter(Wife wife) { if (!wife.Cooking) { Console.WriteLine("{0}: Putting the stew in the oven", EnumsNames.GetNameOfEntity(wife.UniqueID)); //Send a delayed message myself so that I know when to take the stew out of the oven MessageDispatcher.Instance.DispatchMessage(1.5, wife.UniqueID, wife.UniqueID, (int)MessageType.StewReady, MessageDispatcher.NoAdditionalInfo); wife.Cooking = true; } }
public override void Enter(Miner miner) { if (miner.Location != LocationType.Shack) { Console.ForegroundColor = Color; Console.WriteLine("{0}: Walkin' home", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.Location = LocationType.Shack; //Let the wife know I'm home MessageDispatcher.Instance.DispatchMessage(MessageDispatcher.SendMsgImmediately, miner.UniqueID, (int)EntityType.Wife, (int)WestWorld.MessageType.HiHoneyImHome, MessageDispatcher.NoAdditionalInfo); } }
public override void Execute(Miner miner) { if (miner.Thirsty()) { miner.BuyAndDrinkAWhisley(); Console.ForegroundColor = Color; Console.WriteLine("{0}: That's mighty fine sippin liquer", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.StateMachine.ChangeState(EnterMineAndDigForNugget.Instance); } else { Console.ForegroundColor = Color; Console.WriteLine("ERROR"); } }
public override void Execute(Miner miner) { //If miner is not fatigued start for nuggets again if (!miner.Fatigued()) { Console.ForegroundColor = Color; Console.WriteLine("{0}: What a God darn fantastic nap! Time to find more gold", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.StateMachine.ChangeState(EnterMineAndDigForNugget.Instance); } else { //Sleep miner.DecreaseFatigue(); Console.ForegroundColor = Color; Console.WriteLine("{0}: ZZZZzzz...", EnumsNames.GetNameOfEntity(miner.UniqueID)); } }
//send a message to another agent public void DispatchMessage(double delay, int sender, int receiver, int msg, object extraInfo) { Console.ForegroundColor = ConsoleColor.Gray; //Get pointers to the sender and receiver BaseGameEntity msgSender = EntityManager.Instance.GetEntityFromId(sender); BaseGameEntity msgReceiver = EntityManager.Instance.GetEntityFromId(receiver); //Make sure the receiver is valid if (receiver.Equals(null)) { Console.WriteLine("Warning! No Receiver with ID of {0} found", receiver); } //Create the Telegram Telegram telegram = new Telegram(sender, receiver, msg, 0.0f, extraInfo); //if there is no delay, route the telegram immediatly if (delay <= 0.0) { Console.WriteLine("Instant telegram dispatched at time {0} by {1} for {2}", DateTime.Now, EnumsNames.GetNameOfEntity(msgSender.UniqueID), EnumsNames.GetNameOfEntity(msgReceiver.UniqueID)); Console.WriteLine("Msg is {0}", EnumsNames.GetMessageDescription(msg)); //Send the telegram to the recipient Discharge(msgReceiver, telegram); } else { //else calculate the time when the telegram should be dispatched double currentTime = DateTime.Now.Second; telegram.DispatchTime = currentTime + delay; //and put it in the queue PriorityQ.Add(telegram); Console.WriteLine("Delayed telegram from {0} recorded at time {1} for {2}", EnumsNames.GetNameOfEntity(msgSender.UniqueID), DateTime.Now, EnumsNames.GetNameOfEntity(msgReceiver.UniqueID)); Console.WriteLine("Msg is {0}", EnumsNames.GetMessageDescription(msg)); } }
public override bool OnMessage(Miner miner, Telegram msg) { Console.ForegroundColor = ConsoleColor.Gray; switch (msg.Msg) { case (int)MessageType.StewReady: Console.WriteLine("Message handled by {0} at time: {1}", EnumsNames.GetNameOfEntity(miner.UniqueID), DateTime.Now.Second); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("{0}: Okay Hun, ahm a comin'", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.StateMachine.ChangeState(EatStew.Instance); return(true); default: return(false); } }
public override bool OnMessage(Wife wife, Telegram msg) { switch (msg.Msg) { case (int)WestWorld.MessageType.HiHoneyImHome: Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Message handled by {0} at time:{1}", EnumsNames.GetNameOfEntity(wife.UniqueID), DateTime.Now.Second); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}: Hi honey. Let me make you some of mah fine country stew", EnumsNames.GetNameOfEntity(wife.UniqueID)); wife.StateMachine.ChangeState(CookStew.Instance); return(true); default: return(false); } }
public override void Execute(Miner miner) { //the miner digs for gold until he is carrying in excess of MaxNuggets. //'If he gets thirsty during his digging he packs up work for a while and //'changes state to go to the saloon for a whiskey. miner.GoldCarried += 1; miner.IncreaseFatigue(); Console.ForegroundColor = Color; Console.WriteLine("{0}: Pickin' up a nugget", EnumsNames.GetNameOfEntity(miner.UniqueID)); //If enough gold mined, go and put it int the bank if (miner.PocketsFull()) { miner.StateMachine.ChangeState(VisitBankAndDepositGold.Instance); } if (miner.Thirsty()) { miner.StateMachine.ChangeState(QuenchThirst.Instance); } }
public override void Execute(Miner miner) { //Deposit the gold miner.MoneyInBank += miner.GoldCarried; miner.GoldCarried = 0; Console.ForegroundColor = Color; Console.WriteLine("{0}: Depositing gold. Total savings now:{1}", EnumsNames.GetNameOfEntity(miner.UniqueID), miner.MoneyInBank); //Whealty enough to have a well earned rest? if (miner.MoneyInBank >= Common.ComfortLevel) { Console.ForegroundColor = Color; Console.WriteLine("{0}: WooHoo! Rich enough for now. Back home to mah li'lle lady", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.StateMachine.ChangeState(GoHomeAndSleepTilRested.Instance); } else { //Otherwise, get more gold miner.StateMachine.ChangeState(EnterMineAndDigForNugget.Instance); } }
public override void Execute(Wife wife) { int Chore = Common.Random.Next(0, 2); switch (Chore) { case 0: Console.WriteLine("{0}: Moppin' the floor", EnumsNames.GetNameOfEntity(wife.UniqueID)); break; case 1: Console.WriteLine("{0}: Washin' the dishes", EnumsNames.GetNameOfEntity(wife.UniqueID)); break; case 3: Console.WriteLine("{0}: Makin' the bed", EnumsNames.GetNameOfEntity(wife.UniqueID)); break; default: Console.WriteLine("ERROR"); break; } }
public override bool OnMessage(Wife wife, Telegram telegram) { switch (telegram.Msg) { case (int)MessageType.StewReady: Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("Message received by {0} at time: {1}", EnumsNames.GetNameOfEntity(wife.UniqueID), DateTime.Now.Second); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}: StewReady! Lets eat", EnumsNames.GetNameOfEntity(wife.UniqueID)); //Let hubby know the stew is ready MessageDispatcher.Instance.DispatchMessage(MessageDispatcher.SendMsgImmediately, wife.UniqueID, (int)EntityType.Miner, (int)MessageType.StewReady, MessageDispatcher.NoAdditionalInfo); wife.Cooking = false; wife.StateMachine.ChangeState(DoHouseWork.Instance); return(true); default: return(false); } }
public override void Execute(Wife wife) { Console.WriteLine("{0}: Ahhhhhhh! Sweet relief!", EnumsNames.GetNameOfEntity(wife.UniqueID)); wife.StateMachine.RevertToPreviousState(); }
public override void Execute(Wife wife) { Console.WriteLine("{0}: Fussin' over food", EnumsNames.GetNameOfEntity(wife.UniqueID)); }
public override void Exit(Wife wife) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}: Puttin' the stew on the table", EnumsNames.GetNameOfEntity(wife.UniqueID)); }
public override void Exit(Miner miner) { Console.ForegroundColor = Color; Console.WriteLine("{0}: Leavin' the bank", EnumsNames.GetNameOfEntity(miner.UniqueID)); }
public override void Exit(Miner miner) { Console.WriteLine("{0}: Thankya li'lle lady. Ah better get back to whatever ah wuz doin", EnumsNames.GetNameOfEntity(miner.UniqueID)); }
public override void Enter(Miner miner) { if (miner.Location != LocationType.Saloon) { Console.ForegroundColor = Color; Console.WriteLine("{0}: Boy, ah sure is thusty! Walking to the saloon!", EnumsNames.GetNameOfEntity(miner.UniqueID)); } }
public override void Exit(Miner miner) { Console.WriteLine("{0}: Leaving the house", EnumsNames.GetNameOfEntity(miner.UniqueID)); }
public override void Exit(Miner miner) { Console.ForegroundColor = Color; Console.WriteLine("{0}:Ah'm leavin' the gold mine with mah pockets full o' sweet gold", EnumsNames.GetNameOfEntity(miner.UniqueID)); }
public override void Enter(Wife wife) { Console.WriteLine("{0}: Walkin' to the can. Need to powda mah pretty li'lle nose", EnumsNames.GetNameOfEntity(wife.UniqueID)); }
public override void Execute(Miner miner) { Console.WriteLine("{0}: Tastes real good too!", EnumsNames.GetNameOfEntity(miner.UniqueID)); miner.StateMachine.RevertToPreviousState(); }
public override void Exit(Wife wife) { Console.WriteLine("{0}: leavin' the Jon", EnumsNames.GetNameOfEntity(wife.UniqueID)); }
public override void Enter(Miner miner) { Console.WriteLine("{0}: Smells Reaaaal gooood Elsa!", EnumsNames.GetNameOfEntity(miner.UniqueID)); }