void Position::CancelOrders( void ) { // may have a problem getting out of sync with broker if orders are cancelled by broker // todo: on power up, need to relink these active orders back in with the position for ( std::vector<pOrder_t>::iterator iter = m_vOpenOrders.begin(); iter != m_vOpenOrders.end(); ++iter ) { CancelOrder( iter ); // this won't work as the iterator is invalidated with each order removal } //m_OpenOrders.clear(); }
void Position::CancelOrder( idOrder_t idOrder ) { for ( vOrders_t::iterator iter = m_vOpenOrders.begin(); iter != m_vOpenOrders.end(); ++iter ) { if ( idOrder == iter->get()->GetOrderId() ) { CancelOrder( iter ); //m_OpenOrders.erase( iter ); break; } } }
//-------------------------------------------------------------------------------------- // Processes an inbox message that the manoeuvre received. // Param1: A pointer to the message to process. //-------------------------------------------------------------------------------------- void RunTheFlagHome::ProcessMessage(Message* pMessage) { switch(pMessage->GetType()) { case ScoreUpdateMessageType: { ScoreUpdateMessage* pMsg = reinterpret_cast<ScoreUpdateMessage*>(pMessage); if(pMsg->GetData().m_team == GetTeamAI()->GetTeam()) { // The flag was captured -> the manoeuvre succeeded SetSucceeded(true); } break; } case EntityKilledMessageType: { EntityKilledMessage* pMsg = reinterpret_cast<EntityKilledMessage*>(pMessage); if(IsParticipant(pMsg->GetData().m_id) && pMsg->GetData().m_team == GetTeamAI()->GetTeam()) { // Participants that get killed, drop out of the manoeuvre m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_id); } break; } case UpdateOrderStateMessageType: { // Cancel old order, Send Follow-Up Orders, finish manoeuvre etc UpdateOrderStateMessage* pMsg = reinterpret_cast<UpdateOrderStateMessage*>(pMessage); if(IsParticipant(pMsg->GetData().m_entityId)) { if(pMsg->GetData().m_orderState == SucceededOrderState) { // Officially cancel the old order that was fulfilled and delete it. CancelOrder(pMsg->GetData().m_entityId); m_activeOrders.erase(m_activeOrders.find(pMsg->GetData().m_entityId)); // The entity arrived at the home base, take on a defense position until the flag is captured // (might have to wait for the own flag to be returned) Order* pNewOrder = new DefendOrder(pMsg->GetData().m_entityId, DefendPositionOrder, MediumPriority, XMFLOAT2(GetTeamAI()->GetFlagData(GetTeamAI()->GetTeam()).m_basePosition), XMFLOAT2(0.0f, 0.0f)); if(!pNewOrder) { SetFailed(true); }else { // Find the entity std::vector<Entity*>::iterator foundIt = std::find_if(m_participants.begin(), m_participants.end(), Entity::FindEntityById(pMsg->GetData().m_entityId)); FollowOrderMessageData data(pNewOrder); SendMessage(*foundIt, FollowOrderMessageType, &data); m_activeOrders.insert(std::pair<unsigned long, Order*>(pMsg->GetData().m_entityId, pNewOrder)); } }else if(pMsg->GetData().m_orderState == FailedOrderState) { // Entities executing a defend manoeuvre won't send success messages concerning the order state // as the defend order is a passive behaviour that is unlimited in time and thus cannot succeed. // It is thus sufficient to check for failure. // The order failed -> release the entity from the manoeuvre m_pTeamAI->ReleaseEntityFromManoeuvre(pMsg->GetData().m_entityId); } } break; } default: TeamManoeuvre::ProcessMessage(pMessage); } }