CWaitCommandsAI::DeathWait::DeathWait(const Command& cmd) : Wait(CMD_WAITCODE_DEATHWAIT) { GML_RECMUTEX_LOCK(sel); // DeathWait const CUnitSet& selUnits = selectedUnits.selectedUnits; if (cmd.params.size() == 1) { const int unitID = (int)cmd.params[0]; if ((unitID < 0) || (static_cast<size_t>(unitID) >= uh->MaxUnits())) { return; } CUnit* unit = uh->units[unitID]; if (unit == NULL) { return; } if (selUnits.find(unit) != selUnits.end()) { return; } deathUnits.insert(unit); } else if (cmd.params.size() == 6) { const float3 pos0(cmd.params[0], cmd.params[1], cmd.params[2]); const float3 pos1(cmd.params[3], cmd.params[4], cmd.params[5]); CUnitSet tmpSet; SelectAreaUnits(pos0, pos1, tmpSet, false); CUnitSet::iterator it; for (it = tmpSet.begin(); it != tmpSet.end(); ++it) { if (selUnits.find(*it) == selUnits.end()) { deathUnits.insert(*it); } } if (deathUnits.empty()) { return; } } else { return; // unknown param config } valid = true; key = GetNewKey(); waitUnits = selUnits; Command waitCmd(CMD_WAIT, cmd.options); waitCmd.params.push_back(code); waitCmd.params.push_back(GetFloatFromKey(key)); selectedUnits.GiveCommand(waitCmd); CUnitSet::iterator it; for (it = waitUnits.begin(); it != waitUnits.end(); ++it) { AddDeathDependence((CObject*)(*it)); } for (it = deathUnits.begin(); it != deathUnits.end(); ++it) { AddDeathDependence((CObject*)(*it)); } return; }
CWaitCommandsAI::TimeWait::TimeWait(const Command& cmd, CUnit* _unit) : Wait(CMD_WAITCODE_TIMEWAIT) { if (cmd.params.size() != 1) { return; } valid = true; key = GetNewKey(); unit = _unit; enabled = false; endFrame = 0; duration = GAME_SPEED * (int)cmd.params[0]; factory = (dynamic_cast<CFactory*>(unit) != NULL); Command waitCmd(CMD_WAIT, cmd.options); waitCmd.params.push_back(code); waitCmd.params.push_back(GetFloatFromKey(key)); selectedUnits.ClearSelected(); selectedUnits.AddUnit(unit); selectedUnits.GiveCommand(waitCmd); AddDeathDependence((CObject*)unit); return; }
/**************************************************************************** Function Check4Keystroke Parameters None Returns bool: true if a new key was detected & posted Description checks to see if a new key from the keyboard is detected and, if so, retrieves the key and posts an ES_NewKey event to TestHarnessService0 Notes The functions that actually check the serial hardware for characters and retrieve them are assumed to be in ES_Port.c Since we always retrieve the keystroke when we detect it, thus clearing the hardware flag that indicates that a new key is ready this event checker will only generate events on the arrival of new characters, even though we do not internally keep track of the last keystroke that we retrieved. Author J. Edward Carryer, 08/06/13, 13:48 ****************************************************************************/ bool Check4Keystroke(void) { if ( IsNewKeyReady() ) // new key waiting? { ES_Event ThisEvent; ThisEvent.EventType = ES_NEW_KEY; ThisEvent.EventParam = GetNewKey(); PostMapKeys( ThisEvent ); return true; } return false; }
CWaitCommandsAI::TimeWait::TimeWait(int _duration, CUnit* _unit) : Wait(CMD_WAITCODE_TIMEWAIT) { valid = true; key = GetNewKey(); unit = _unit; enabled = false; endFrame = 0; duration = _duration; factory = false; AddDeathDependence((CObject*)unit); }
CWaitCommandsAI::SquadWait::SquadWait(const Command& cmd) : Wait(CMD_WAITCODE_SQUADWAIT) { GML_RECMUTEX_LOCK(sel); // SquadWait if (cmd.params.size() != 1) { return; } squadCount = (int)cmd.params[0]; if (squadCount < 2) { return; } const CUnitSet& selUnits = selectedUnits.selectedUnits; CUnitSet::const_iterator it; for (it = selUnits.begin(); it != selUnits.end(); ++it) { CUnit* unit = *it; if (dynamic_cast<CFactory*>(unit)) { buildUnits.insert(unit); } else { waitUnits.insert(unit); } } if (buildUnits.empty() && ((int)waitUnits.size() < squadCount)) { return; } valid = true; key = GetNewKey(); Command waitCmd(CMD_WAIT, cmd.options); waitCmd.params.push_back(code); waitCmd.params.push_back(GetFloatFromKey(key)); SendCommand(waitCmd, buildUnits); SendCommand(waitCmd, waitUnits); for (it = buildUnits.begin(); it != buildUnits.end(); ++it) { AddDeathDependence((CObject*)(*it)); } for (it = waitUnits.begin(); it != waitUnits.end(); ++it) { AddDeathDependence((CObject*)(*it)); } UpdateText(); return; }
/**************************************************************************** Function Check4Keystroke Parameters None Returns bool: true if a new key was detected & posted Description checks to see if a new key from the keyboard is detected and, if so, retrieves the key and posts an ES_NewKey event to TestHarnessService0 Notes The functions that actually check the serial hardware for characters and retrieve them are assumed to be in ES_Port.c Since we always retrieve the keystroke when we detect it, thus clearing the hardware flag that indicates that a new key is ready this event checker will only generate events on the arrival of new characters, even though we do not internally keep track of the last keystroke that we retrieved. Author J. Edward Carryer, 08/06/13, 13:48 ****************************************************************************/ bool Check4Keystroke(void) { if ( IsNewKeyReady() ) // new key waiting? { ES_Event ThisEvent; ThisEvent.EventType = ES_NEW_KEY; ThisEvent.EventParam = GetNewKey(); // test distribution list functionality by sending the 'L' key out via // a distribution list. if ( ThisEvent.EventParam == 'L'){ // ES_PostList00( ThisEvent ); }else{ // otherwise post to Service 0 for processing PostTestHarnessService0( ThisEvent ); } return true; } return false; }
CWaitCommandsAI::GatherWait::GatherWait(const Command& cmd) : Wait(CMD_WAITCODE_GATHERWAIT) { GML_RECMUTEX_LOCK(sel); // GatherWait if (!cmd.params.empty()) { return; } // only add valid units const CUnitSet& selUnits = selectedUnits.selectedUnits; CUnitSet::const_iterator sit; for (sit = selUnits.begin(); sit != selUnits.end(); ++sit) { CUnit* unit = *sit; const UnitDef* ud = unit->unitDef; if (ud->canmove && (dynamic_cast<CFactory*>(unit) == NULL)) { waitUnits.insert(unit); } } if (waitUnits.size() < 2) { return; // one man does not a gathering make } valid = true; key = GetNewKey(); Command waitCmd(CMD_WAIT, SHIFT_KEY); waitCmd.params.push_back(code); waitCmd.params.push_back(GetFloatFromKey(key)); selectedUnits.GiveCommand(waitCmd, true); CUnitSet::iterator wit; for (wit = waitUnits.begin(); wit != waitUnits.end(); ++wit) { AddDeathDependence((CObject*)(*wit)); } return; }
/**************************************************************************** Function Check4Keystroke Parameters None Returns bool: true if a new key was detected & posted Description checks to see if a new key from the keyboard is detected and, if so, retrieves the key and posts an ES_NewKey event to TestHarnessService0 Notes The functions that actually check the serial hardware for characters and retrieve them are assumed to be in ES_Port.c Since we always retrieve the keystroke when we detect it, thus clearing the hardware flag that indicates that a new key is ready this event checker will only generate events on the arrival of new characters, even though we do not internally keep track of the last keystroke that we retrieved. Author J. Edward Carryer, 08/06/13, 13:48 ****************************************************************************/ bool Check4Keystroke(void) { if ( IsNewKeyReady() ) // new key waiting? { ES_Event ThisEvent; uint8_t keyPressed = GetNewKey(); // test distribution list functionality by sending the 'L' key out via // a distribution list. //PostToStrategy if(keyPressed == 'a') { ThisEvent.EventType = GET_KEYPRESS_STATUS; PostStrategySM(ThisEvent); } if(keyPressed == 'c') { ThisEvent.EventType = POTENTIAL_POLL_STATION; PostStrategySM(ThisEvent); } else if(keyPressed == 'g') { ThisEvent.EventType = FOLLOW_LINE; PostStrategySM(ThisEvent); } else if(keyPressed == 's') { ThisEvent.EventType = STOP_NOW_CHANGE_TO_CAPTURE; PostStrategySM(ThisEvent); } else if (keyPressed == 'p') { //Activate shooter ThisEvent.EventType = SHOOT_NOW; PostStrategySM(ThisEvent); } /* else if(keyPressed == 'h') { ThisEvent.EventType = EOT_TIMEOUT; PostStatusPAC(ThisEvent); } else if(keyPressed == 'g') { ThisEvent.EventType = ES_TIMEOUT; PostStatusPAC(ThisEvent); }*/ /*else if(keyPressed == 'r') { ThisEvent.EventType = CAPTURE_STATION_NOW; ThisEvent.EventParam = 9; PostCampaigningSM(ThisEvent); }*/ return true; } return false; }
/**************************************************************************** Function Check4Keystroke Parameters None Returns bool: true if a new key was detected & posted Description checks to see if a new key from the keyboard is detected and, if so, posts the appropriate command to the SPI service Notes The functions that actually check the serial hardware for characters and retrieve them are assumed to be in ES_Port.c Since we always retrieve the keystroke when we detect it, thus clearing the hardware flag that indicates that a new key is ready this event checker will only generate events on the arrival of new characters, even though we do not internally keep track of the last keystroke that we retrieved. Author J. Edward Carryer, 08/06/13, 13:48 ****************************************************************************/ bool Check4Keystroke(void) { if ( IsNewKeyReady() ) // new key waiting? { ES_Event ThisEvent; ThisEvent.EventType = ES_NEW_KEY; ThisEvent.EventParam = GetNewKey(); // test distribution list functionality by sending the 'L' key out via // a distribution list. if ( ThisEvent.EventParam == '1'){ ES_Event newEvent = {InShootingDecisionZone, 0}; PostMaster( newEvent ); printf("POST - In Shooting Decision Zone \r\n"); } else if ( ThisEvent.EventParam == '2'){ ES_Event newEvent = {InObstacleDecisionZone, 0}; PostMaster( newEvent ); printf("POST - In Obstacle Decision Zone \r\n"); } else if ( ThisEvent.EventParam == '3'){ ES_Event newEvent = {CautionFlagDropped, 0}; PostMaster( newEvent ); printf("POST - Caution Flag Dropped \r\n"); } else if ( ThisEvent.EventParam == '4'){ ES_Event newEvent = {FlagDropped, 0}; PostMaster( newEvent ); printf("POST - Flag Dropped \r\n"); } else if ( ThisEvent.EventParam == '5'){ ES_Event newEvent = {NextPointCalculated, 0}; PostMaster( newEvent ); printf("POST - Next Point Calculated \r\n"); } else if ( ThisEvent.EventParam == '6'){ ES_Event newEvent = {AtNextPoint, 0}; PostMaster( newEvent ); printf("POST - At Next Point \r\n"); } else if ( ThisEvent.EventParam == '7'){ ES_Event newEvent = {AtNextAngle, 0}; PostMaster( newEvent ); printf("POST - At Next Angle \r\n"); } else if ( ThisEvent.EventParam == '8'){ ES_Event newEvent = {DetectedLeftBeacon, 0}; PostMaster( newEvent ); printf("POST - Detected Left Beacon \r\n"); } else if ( ThisEvent.EventParam == '9'){ ES_Event newEvent = {DetectedRightBeacon, 0}; PostMaster( newEvent ); printf("POST - Detected Right Beacon \r\n"); } else if ( ThisEvent.EventParam == 'q'){ ES_Event newEvent = {BallFired, 0}; PostMaster( newEvent ); printf("POST - Ball Fired \r\n"); } else if ( ThisEvent.EventParam == 'w'){ ES_Event newEvent = {MiddleTapeTripped, 0}; PostMaster( newEvent ); printf("POST - Middle Tape Tripped \r\n"); } else if ( ThisEvent.EventParam == 'e'){ ES_Event newEvent = {MiddleTapeLost, 0}; PostMaster( newEvent ); printf("POST - Middle Tape Lost \r\n"); } else if ( ThisEvent.EventParam == 'r'){ ES_Event newEvent = {RightTapeTripped, 0}; PostMaster( newEvent ); printf("POST - Right Tape Tripped \r\n"); } else if ( ThisEvent.EventParam == 't'){ ES_Event newEvent = {LeftTapeTripped, 0}; PostMaster( newEvent ); printf("POST - Left Tape Tripped \r\n"); } else if ( ThisEvent.EventParam == 'y'){ ES_Event newEvent = {ObstacleTraversed, 0}; PostMaster( newEvent ); printf("POST - Obstacle Traversed \r\n"); } else if ( ThisEvent.EventParam == 'u'){ ES_Event newEvent = {CautionOver, 0}; PostMaster( newEvent ); printf("POST - Caution Over \r\n"); } else if ( ThisEvent.EventParam == 'i'){ ES_Event newEvent = {GameOver, 0}; PostMaster( newEvent ); printf("POST - Game Over \r\n"); } else if ( ThisEvent.EventParam == 'o'){ ES_Event newEvent = {EmergencyStop, 0}; PostMaster( newEvent ); printf("POST - Emergency Stop \r\n"); } else if ( ThisEvent.EventParam == 'z'){ ES_Event newEvent = {ChangeOpMode, 0}; PostMaster( newEvent ); printf("POST - Change Operation Mode \r\n"); } else if ( ThisEvent.EventParam == 'x'){ ES_Event newEvent = {Waypoint_BR, 0}; PostMaster( newEvent ); printf("POST - Bottom Right Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'c'){ ES_Event newEvent = {Waypoint_TR, 0}; PostMaster( newEvent ); printf("POST - Top Right Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'v'){ ES_Event newEvent = {Waypoint_TL, 0}; PostMaster( newEvent ); printf("POST - Top Left Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'b'){ ES_Event newEvent = {Waypoint_BL, 0}; PostMaster( newEvent ); printf("POST - Bottom Left Waypoint \r\n"); } else{ // otherwise post to Service 0 for processing PostMaster( ThisEvent ); printf("POST - Unknown key \r\n"); } return true; } return false; }
/**************************************************************************** Function Check4Keystroke Parameters None Returns bool: true if a new key was detected & posted Description checks to see if a new key from the keyboard is detected and, if so, posts the appropriate command to the SPI service Notes The functions that actually check the serial hardware for characters and retrieve them are assumed to be in ES_Port.c Since we always retrieve the keystroke when we detect it, thus clearing the hardware flag that indicates that a new key is ready this event checker will only generate events on the arrival of new characters, even though we do not internally keep track of the last keystroke that we retrieved. Author J. Edward Carryer, 08/06/13, 13:48 ****************************************************************************/ bool Check4Keystroke(void) { if ( IsNewKeyReady() ) // new key waiting? { ES_Event ThisEvent; ThisEvent.EventType = ES_NEW_KEY; ThisEvent.EventParam = GetNewKey(); // test distribution list functionality by sending the 'L' key out via // a distribution list. if ( ThisEvent.EventParam == '1'){ ES_Event newEvent = {InShootingDecisionZone, 0}; PostMaster( newEvent ); printf("POST - In Shooting Decision Zone \r\n"); } else if ( ThisEvent.EventParam == '2'){ ES_Event newEvent = {InObstacleDecisionZone, 0}; PostMaster( newEvent ); printf("POST - In Obstacle Decision Zone \r\n"); } else if ( ThisEvent.EventParam == '3'){ ES_Event newEvent = {CautionFlagDropped, 0}; PostMaster( newEvent ); printf("POST - Caution Flag Dropped \r\n"); } else if ( ThisEvent.EventParam == '4'){ ES_Event newEvent = {FlagDropped, 0}; PostMaster( newEvent ); printf("POST - Flag Dropped \r\n"); } else if ( ThisEvent.EventParam == '5'){ ES_Event newEvent = {NextPointCalculated, 0}; PostMaster( newEvent ); printf("POST - Next Point Calculated \r\n"); } else if ( ThisEvent.EventParam == '6'){ ES_Event newEvent = {AtNextPoint, 0}; PostMaster( newEvent ); printf("POST - At Next Point \r\n"); } else if ( ThisEvent.EventParam == '7'){ ES_Event newEvent = {AtNextAngle, 0}; PostMaster( newEvent ); printf("POST - At Next Angle \r\n"); } else if ( ThisEvent.EventParam == '8'){ ES_Event newEvent = {DetectedBeacon, 0}; PostMaster( newEvent ); printf("POST - Detected Beacon \r\n"); } else if ( ThisEvent.EventParam == '9'){ ES_Event newEvent = {ObstacleTraversed, 0}; PostMaster( newEvent ); printf("POST - Obstacle Traversed \r\n"); } else if ( ThisEvent.EventParam == '0'){ ES_Event newEvent = {GameOver, 0}; PostMaster( newEvent ); printf("POST - Game Over \r\n"); } else if ( ThisEvent.EventParam == 'q'){ ES_Event newEvent = {EmergencyStop, 0}; PostMaster( newEvent ); printf("POST - Emergency Stop \r\n"); } else if ( ThisEvent.EventParam == 'w'){ ES_Event newEvent = {SpeedChangePort, 10}; PostMaster( newEvent ); printf("POST - Speed Change Port \r\n"); } else if ( ThisEvent.EventParam == 'e'){ ES_Event newEvent = {SpeedChangeStarboard, 10}; PostMaster( newEvent ); printf("POST - Speed Change Starboard \r\n"); } else if ( ThisEvent.EventParam == 'r'){ ES_Event newEvent = {AtRatio, 0}; PostMaster( newEvent ); printf("POST - Tape Sensors At Correct Ratio \r\n"); } else if ( ThisEvent.EventParam == 't'){ ES_Event newEvent = {OffRatio, 0}; PostMaster( newEvent ); printf("POST - Tape Sensors Off Correct Ratio \r\n"); } else if ( ThisEvent.EventParam == 'y'){ ES_Event newEvent = {ToDriving, 0}; PostMaster( newEvent ); printf("POST - Move To Driving SM \r\n"); } else if ( ThisEvent.EventParam == 'u'){ ES_Event newEvent = {ToShooting, 0}; PostMaster( newEvent ); printf("POST - Move To Shooting SM \r\n"); } else if ( ThisEvent.EventParam == 'i'){ ES_Event newEvent = {ToObstacle, 0}; PostMaster( newEvent ); printf("POST - Move To Obstacle SM \r\n"); } else if ( ThisEvent.EventParam == 'o'){ ES_Event newEvent = {AtNextPoint, 1}; PostMaster( newEvent ); printf("POST - At Next Point \r\n"); } else if ( ThisEvent.EventParam == 'x'){ ES_Event newEvent = {Waypoint_BR, 0}; PostMaster( newEvent ); printf("POST - Bottom Right Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'c'){ ES_Event newEvent = {Waypoint_TR, 0}; PostMaster( newEvent ); printf("POST - Top Right Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'v'){ ES_Event newEvent = {Waypoint_TL, 0}; PostMaster( newEvent ); printf("POST - Top Left Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'b'){ ES_Event newEvent = {Waypoint_BL, 0}; PostMaster( newEvent ); printf("POST - Bottom Left Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'n'){ ES_Event newEvent = {Waypoint_S, 0}; PostMaster( newEvent ); printf("POST - Shooting Waypoint \r\n"); } else if ( ThisEvent.EventParam == 'm'){ ES_Event newEvent = {Waypoint_O, 0}; PostMaster( newEvent ); printf("POST - Obstacle Entry Waypoint \r\n"); } else{ // otherwise post to Service 0 for processing PostMaster( ThisEvent ); printf("POST - Unknown key \r\n"); } return true; } return false; }
CString CBibList::GenerateKey(CBibItem *item) { return GetNewKey(item, item); }