// add a droid to a command group void cmdDroidAddDroid(DROID *psCommander, DROID *psDroid) { DROID_GROUP *psGroup; if (psCommander->psGroup == NULL) { if (!grpCreate(&psGroup)) { return; } grpJoin(psGroup, psCommander); psDroid->group = UBYTE_MAX; } if (grpNumMembers(psCommander->psGroup) < cmdDroidMaxGroup(psCommander)) { grpJoin(psCommander->psGroup, psDroid); psDroid->group = UBYTE_MAX; // set the secondary states for the unit secondarySetState(psDroid, DSO_ATTACK_RANGE, (SECONDARY_STATE)(psCommander->secondaryOrder & DSS_ARANGE_MASK)); secondarySetState(psDroid, DSO_REPAIR_LEVEL, (SECONDARY_STATE)(psCommander->secondaryOrder & DSS_REPLEV_MASK)); secondarySetState(psDroid, DSO_ATTACK_LEVEL, (SECONDARY_STATE)(psCommander->secondaryOrder & DSS_ALEV_MASK)); secondarySetState(psDroid, DSO_HALTTYPE, (SECONDARY_STATE)(psCommander->secondaryOrder & DSS_HALT_MASK)); orderDroidObj(psDroid, DORDER_GUARD, (BASE_OBJECT *)psCommander, ModeQueue); } }
/** This function adds the droid to the command group commanded by psCommander. * It creates a group if it doesn't exist. * If the group is not full, it adds the droid to it and sets all the droid's states and orders to the group's. */ void cmdDroidAddDroid(DROID *psCommander, DROID *psDroid) { DROID_GROUP *psGroup; if (psCommander->psGroup == NULL) { psGroup = grpCreate(); psGroup->add(psCommander); psDroid->group = UBYTE_MAX; } if (psCommander->psGroup->getNumMembers() < cmdDroidMaxGroup(psCommander)) { psCommander->psGroup->add(psDroid); psDroid->group = UBYTE_MAX; // set the secondary states for the unit secondarySetState(psDroid, DSO_REPAIR_LEVEL, (SECONDARY_STATE)(psCommander->secondaryOrder & DSS_REPLEV_MASK), ModeImmediate); secondarySetState(psDroid, DSO_ATTACK_LEVEL, (SECONDARY_STATE)(psCommander->secondaryOrder & DSS_ALEV_MASK), ModeImmediate); orderDroidObj(psDroid, DORDER_GUARD, (BASE_OBJECT *)psCommander, ModeImmediate); } else { audio_PlayTrack( ID_SOUND_BUILD_FAIL ); addConsoleMessage(_("Commander needs a higher level to command more units"), DEFAULT_JUSTIFY, SYSTEM_MESSAGE); } }
// returns max number of droids in a commander group bool scrCmdDroidMaxGroup(void) { DROID *psCommander; if (!stackPopParams(1, ST_DROID, &psCommander)) { return false; } ASSERT(psCommander != NULL, "scrCmdDroidMaxGroup: NULL pointer passed"); scrFunctionResult.v.ival = cmdDroidMaxGroup(psCommander); if (!stackPushResult(VAL_INT, &scrFunctionResult)) { return false; } return true; }