//a std::set is used as the container for the delayed messages //because of the benefit of automatic sorting and avoidance //of duplicates. Messages are sorted by their dispatch time. // private HashSet<Telegram> PriorityQ; //this method is utilized by DispatchMsg or DispatchDelayedMessages. //This method calls the message handling member function of the receiving //entity, pReceiver, with the newly created telegram private void Discharge(BaseGameEntity receiver, ref Telegram msg) { if (!receiver.HandleMessage(msg)) { //telegram could not be handled Logger.log("Message not handled", Logger.LogLevel.DEBUG); } }
public Player(int number, player_role role, Team team) : base(BaseGameEntity.GetNextValidID()) { //varibale initialization position = new Position(); this.team = team; playerNumber = number; //player number is the id of the player id = playerNumber; this.role = role; }
//send a message to another agent. Receiving agent is referenced by ID. public void DispatchMsg(double delay, int sender, int receiver, Messages.MessageType msg, dynamic extraInfo) { //get a pointer to the receiver BaseGameEntity receiverRef = EntityManager.instance.GetEntityFromID(receiver); //make sure the receiver is valid if (receiverRef == null) { Logger.log("\nWarning! No Receiver with ID of " + receiver + " found", Logger.LogLevel.WARNING); return; } //create the telegram Telegram telegram = new Telegram(0, sender, receiver, msg, extraInfo); //if there is no delay, route telegram immediately if (delay <= 0.0) { Logger.log("Telegram dispatched by " + sender + " for " + receiver + ". Msg is " + msg + "", Logger.LogLevel.INFO); //send the telegram to the recipient Discharge(receiverRef, ref telegram); } //else calculate the time when the telegram should be dispatched //else //{ // double CurrentTime = TickCounter->GetCurrentFrame(); // telegram.DispatchTime = CurrentTime + delay; // //and put it in the queue // PriorityQ.insert(telegram); // #ifdef SHOW_MESSAGING_INFO // debug_con << "\nDelayed telegram from " << sender << " recorded at time " // << TickCounter->GetCurrentFrame() << " for " << receiver // << ". Msg is " << msg << ""; // #endif //} }
public void RegisterEntity(BaseGameEntity NewEntity) { //m_EntityMap.insert(std::make_pair(NewEntity->ID(), NewEntity)); EntityDic.Add(NewEntity.id, NewEntity); }
public Player() : base(BaseGameEntity.GetNextValidID()) { }