本文整理汇总了C++中Command::GetID方法的典型用法代码示例。如果您正苦于以下问题:C++ Command::GetID方法的具体用法?C++ Command::GetID怎么用?C++ Command::GetID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command::GetID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SelectNewAreaAttackTargetOrPos
bool CAirCAI::SelectNewAreaAttackTargetOrPos(const Command& ac) {
assert(ac.GetID() == CMD_AREA_ATTACK || (ac.GetID() == CMD_ATTACK && ac.GetParamsCount() >= 3));
if (ac.GetID() == CMD_ATTACK) {
FinishCommand();
return false;
}
const float3& pos = ac.GetPos(0);
const float radius = ac.params[3];
std::vector<int> enemyUnitIDs;
CGameHelper::GetEnemyUnits(pos, radius, owner->allyteam, enemyUnitIDs);
if (enemyUnitIDs.empty()) {
float3 attackPos = pos + (gs->randVector() * radius);
attackPos.y = CGround::GetHeightAboveWater(attackPos.x, attackPos.z);
owner->AttackGround(attackPos, (ac.options & INTERNAL_ORDER) == 0, false);
SetGoal(attackPos, owner->pos);
} else {
// note: the range of randFloat() is inclusive of 1.0f
const unsigned int unitIdx = std::min<int>(gs->randFloat() * enemyUnitIDs.size(), enemyUnitIDs.size() - 1);
const unsigned int unitID = enemyUnitIDs[unitIdx];
CUnit* targetUnit = unitHandler->GetUnitUnsafe(unitID);
SetOrderTarget(targetUnit);
owner->AttackUnit(targetUnit, (ac.options & INTERNAL_ORDER) == 0, false);
SetGoal(targetUnit->pos, owner->pos);
}
return true;
}
示例2: ExecuteAttack
void CCommandAI::ExecuteAttack(Command& c)
{
assert(owner->unitDef->canAttack);
if (inCommand) {
if (targetDied || (c.params.size() == 1 && UpdateTargetLostTimer(int(c.params[0])) == 0)) {
FinishCommand();
return;
}
if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) {
FinishCommand();
return;
}
} else {
if (c.params.size() == 1) {
CUnit* targetUnit = unitHandler->GetUnit(c.params[0]);
if (targetUnit == NULL) { FinishCommand(); return; }
if (targetUnit == owner) { FinishCommand(); return; }
if (targetUnit->GetTransporter() != NULL && !modInfo.targetableTransportedUnits) {
FinishCommand(); return;
}
SetOrderTarget(targetUnit);
owner->AttackUnit(targetUnit, (c.options & INTERNAL_ORDER) == 0, c.GetID() == CMD_MANUALFIRE);
inCommand = true;
} else {
owner->AttackGround(c.GetPos(0), (c.options & INTERNAL_ORDER) == 0, c.GetID() == CMD_MANUALFIRE);
inCommand = true;
}
}
}
示例3: DecreaseQueueCount
void CFactoryCAI::DecreaseQueueCount(const Command& buildCommand, BuildOption& buildOption, bool)
{
// copy in case we get pop'ed
// NOTE: the queue should not be empty at this point!
const Command frontCommand = commandQue.empty()? Command(CMD_STOP): commandQue.front();
if (!repeatOrders || (buildCommand.options & INTERNAL_ORDER))
buildOption.numQued--;
UpdateIconName(buildCommand.GetID(), buildOption);
// if true, factory was set to wait and its buildee
// could only have been finished by assisting units
// --> make sure not to cancel the wait-order
if (frontCommand.GetID() == CMD_WAIT)
commandQue.pop_front();
// can only finish the real build-command command if
// we still have it in our queue (FinishCommand also
// asserts this)
if (!commandQue.empty())
FinishCommand();
if (frontCommand.GetID() == CMD_WAIT)
commandQue.push_front(frontCommand);
}
示例4: AllowedCommand
bool CTransportCAI::AllowedCommand(const Command& c, bool fromSynced)
{
if (!CMobileCAI::AllowedCommand(c, fromSynced)) {
return false;
}
switch (c.GetID()) {
case CMD_UNLOAD_UNIT:
case CMD_UNLOAD_UNITS: {
const CTransportUnit* transport = static_cast<CTransportUnit*>(owner);
const std::list<CTransportUnit::TransportedUnit>& transportees = transport->GetTransportedUnits();
// allow unloading empty transports for easier setup of transport bridges
if (transportees.empty())
return true;
if (c.GetParamsCount() == 5) {
if (fromSynced) {
// point transported buildings (...) in their wanted direction after unloading
for (auto it = transportees.begin(); it != transportees.end(); ++it) {
CBuilding* building = dynamic_cast<CBuilding*>(it->unit);
if (building == NULL)
continue;
building->buildFacing = std::abs(int(c.GetParam(4))) % NUM_FACINGS;
}
}
}
if (c.GetParamsCount() >= 4) {
// find unload positions for transportees (WHY can this run in unsynced context?)
for (auto it = transportees.begin(); it != transportees.end(); ++it) {
CUnit* u = it->unit;
const float radius = (c.GetID() == CMD_UNLOAD_UNITS)? c.GetParam(3): 0.0f;
const float spread = u->radius * transport->unitDef->unloadSpread;
float3 foundPos;
if (FindEmptySpot(c.GetPos(0), radius, spread, foundPos, u, fromSynced)) {
return true;
}
// FIXME: support arbitrary unloading order for other unload types also
if (unloadType != UNLOAD_LAND) {
return false;
}
}
// no empty spot found for any transported unit
return false;
}
break;
}
}
return true;
}
示例5: cbi
std::vector<Command> CCommandAI::GetOverlapQueued(const Command& c, CCommandQueue& q)
{
CCommandQueue::iterator ci = q.end();
std::vector<Command> v;
BuildInfo cbi(c);
if (ci != q.begin()) {
do {
--ci; //iterate from the end and dont check the current order
const Command& t = *ci;
if (t.params.size() != c.params.size())
continue;
if (t.GetID() == c.GetID() || (c.GetID() < 0 && t.GetID() < 0)) {
if (c.params.size() == 1) {
// assume the param is a unit or feature id
if (t.params[0] == c.params[0]) {
v.push_back(t);
}
}
else if (c.params.size() >= 3) {
// assume c and t are positional commands
// NOTE: uses a BuildInfo structure, but <t> can be ANY command
BuildInfo tbi;
if (tbi.Parse(t)) {
const float dist2X = 2.0f * math::fabs(cbi.pos.x - tbi.pos.x);
const float dist2Z = 2.0f * math::fabs(cbi.pos.z - tbi.pos.z);
const float addSizeX = SQUARE_SIZE * (cbi.GetXSize() + tbi.GetXSize());
const float addSizeZ = SQUARE_SIZE * (cbi.GetZSize() + tbi.GetZSize());
const float maxSizeX = SQUARE_SIZE * std::max(cbi.GetXSize(), tbi.GetXSize());
const float maxSizeZ = SQUARE_SIZE * std::max(cbi.GetZSize(), tbi.GetZSize());
if (cbi.def == NULL) continue;
if (tbi.def == NULL) continue;
if (((dist2X > maxSizeX) || (dist2Z > maxSizeZ)) &&
((dist2X < addSizeX) && (dist2Z < addSizeZ))) {
v.push_back(t);
}
} else {
if ((cbi.pos - tbi.pos).SqLength2D() >= (COMMAND_CANCEL_DIST * COMMAND_CANCEL_DIST))
continue;
if ((c.options & SHIFT_KEY) != 0 && (c.options & INTERNAL_ORDER) != 0)
continue;
v.push_back(t);
}
}
}
} while (ci != q.begin());
}
return v;
}
示例6: GiveCommandReal
void CBuilderCAI::GiveCommandReal(const Command& c, bool fromSynced)
{
if (!AllowedCommand(c, fromSynced))
return;
// don't guard yourself
if ((c.GetID() == CMD_GUARD) &&
(c.params.size() == 1) && ((int)c.params[0] == owner->id)) {
return;
}
// stop building/reclaiming/... if the new command is not queued, i.e. replaces our current activity
// FIXME should happen just before CMobileCAI::GiveCommandReal? (the new cmd can still be skipped!)
if ((c.GetID() != CMD_WAIT && c.GetID() != CMD_SET_WANTED_MAX_SPEED) && !(c.options & SHIFT_KEY)) {
if (nonQueingCommands.find(c.GetID()) == nonQueingCommands.end()) {
building = false;
static_cast<CBuilder*>(owner)->StopBuild();
}
}
if (buildOptions.find(c.GetID()) != buildOptions.end()) {
if (c.params.size() < 3)
return;
BuildInfo bi;
bi.pos = c.GetPos(0);
if (c.params.size() == 4)
bi.buildFacing = abs((int)c.params[3]) % NUM_FACINGS;
bi.def = unitDefHandler->GetUnitDefByID(-c.GetID());
bi.pos = CGameHelper::Pos2BuildPos(bi, true);
// We are a static building, check if the buildcmd is in range
if (!owner->unitDef->canmove) {
if (!IsInBuildRange(bi.pos, GetBuildOptionRadius(bi.def, c.GetID()))) {
return;
}
}
const CUnit* nanoFrame = NULL;
// check if the buildpos is blocked
if (IsBuildPosBlocked(bi, &nanoFrame))
return;
// if it is a nanoframe help to finish it
if (nanoFrame != NULL) {
Command c2(CMD_REPAIR, c.options | INTERNAL_ORDER, nanoFrame->id);
CMobileCAI::GiveCommandReal(c2, fromSynced);
CMobileCAI::GiveCommandReal(c, fromSynced);
return;
}
} else {
if (c.GetID() < 0)
return;
}
CMobileCAI::GiveCommandReal(c, fromSynced);
}
示例7: InsertBuildCommand
void CFactoryCAI::InsertBuildCommand(CCommandQueue::iterator& it,
const Command& newCmd)
{
map<int, BuildOption>::iterator boi = buildOptions.find(newCmd.GetID());
if (boi != buildOptions.end()) {
boi->second.numQued++;
UpdateIconName(newCmd.GetID(), boi->second);
}
if (!commandQue.empty() && (it == commandQue.begin())) {
// ExecuteStop(), without the pop_front()
CFactory* fac = static_cast<CFactory*>(owner);
fac->StopBuild();
}
commandQue.insert(it, newCmd);
}
示例8: PushUnitAndCommand
/// pushes 7 items on the stack
static void PushUnitAndCommand(lua_State* L, const CUnit* unit, const Command& cmd)
{
// push the unit info
lua_pushnumber(L, unit->id);
lua_pushnumber(L, unit->unitDef->id);
lua_pushnumber(L, unit->team);
// push the command id
lua_pushnumber(L, cmd.GetID());
// push the params list
lua_newtable(L);
for (int p = 0; p < (int)cmd.params.size(); p++) {
lua_pushnumber(L, p + 1);
lua_pushnumber(L, cmd.params[p]);
lua_rawset(L, -3);
}
// push the options table
lua_newtable(L);
HSTR_PUSH_NUMBER(L, "coded", cmd.options);
HSTR_PUSH_BOOL(L, "alt", !!(cmd.options & ALT_KEY));
HSTR_PUSH_BOOL(L, "ctrl", !!(cmd.options & CONTROL_KEY));
HSTR_PUSH_BOOL(L, "shift", !!(cmd.options & SHIFT_KEY));
HSTR_PUSH_BOOL(L, "right", !!(cmd.options & RIGHT_MOUSE_KEY));
HSTR_PUSH_BOOL(L, "meta", !!(cmd.options & META_KEY));
// push the command tag
lua_pushnumber(L, cmd.tag);
}
示例9: OutOfImmobileRange
inline bool CBuilderCAI::OutOfImmobileRange(const Command& cmd) const
{
if (owner->unitDef->canmove) {
return false; // builder can move
}
if (((cmd.options & INTERNAL_ORDER) == 0) || (cmd.params.size() != 1)) {
return false; // not an internal object targetted command
}
const int objID = cmd.params[0];
const CWorldObject* obj = uh->GetUnit(objID);
if (obj == NULL) {
// features don't move, but maybe the unit was transported?
obj = featureHandler->GetFeature(objID - uh->MaxUnits());
if (obj == NULL) {
return false;
}
}
switch (cmd.GetID()) {
case CMD_REPAIR:
case CMD_RECLAIM:
case CMD_RESURRECT:
case CMD_CAPTURE: {
if (!IsInBuildRange(obj)) {
return true;
}
break;
}
}
return false;
}
示例10: SendCommand
void CSelectedUnits::SendCommand(const Command& c)
{
if (selectionChanged) {
// send new selection
SendSelection();
}
net->Send(CBaseNetProtocol::Get().SendCommand(gu->myPlayerNum, c.GetID(), c.options, c.params));
}
示例11: IntToString
inline void CCommandAI::SetCommandDescParam0(const Command& c)
{
for (unsigned int n = 0; n < possibleCommands.size(); n++) {
if (possibleCommands[n].id != c.GetID())
continue;
possibleCommands[n].params[0] = IntToString(int(c.params[0]), "%d");
break;
}
}
示例12: UpdateTable
/**
* Update the network tables associated with the Scheduler object on the
* SmartDashboard.
*/
void Scheduler::UpdateTable() {
CommandSet::iterator commandIter;
if (m_table != nullptr) {
// Get the list of possible commands to cancel
auto new_toCancel = m_table->GetValue("Cancel");
if (new_toCancel)
toCancel = new_toCancel->GetDoubleArray();
else
toCancel.resize(0);
// m_table->RetrieveValue("Ids", *ids);
// cancel commands that have had the cancel buttons pressed
// on the SmartDashboad
if (!toCancel.empty()) {
for (commandIter = m_commands.begin(); commandIter != m_commands.end();
++commandIter) {
for (unsigned i = 0; i < toCancel.size(); i++) {
Command* c = *commandIter;
if (c->GetID() == toCancel[i]) {
c->Cancel();
}
}
}
toCancel.resize(0);
m_table->PutValue("Cancel", nt::Value::MakeDoubleArray(toCancel));
}
// Set the running commands
if (m_runningCommandsChanged) {
commands.resize(0);
ids.resize(0);
for (commandIter = m_commands.begin(); commandIter != m_commands.end();
++commandIter) {
Command* c = *commandIter;
commands.push_back(c->GetName());
ids.push_back(c->GetID());
}
m_table->PutValue("Names", nt::Value::MakeStringArray(commands));
m_table->PutValue("Ids", nt::Value::MakeDoubleArray(ids));
}
}
}
示例13: GetCancelQueued
CCommandQueue::iterator CCommandAI::GetCancelQueued(const Command& c, CCommandQueue& q)
{
CCommandQueue::iterator ci = q.end();
while (ci != q.begin()) {
--ci; //iterate from the end and dont check the current order
const Command& c2 = *ci;
const int cmdID = c.GetID();
const int cmd2ID = c2.GetID();
const bool attackAndFight = (cmdID == CMD_ATTACK && cmd2ID == CMD_FIGHT && c2.params.size() == 1);
if (c2.params.size() != c.params.size())
continue;
if ((cmdID == cmd2ID) || (cmdID < 0 && cmd2ID < 0) || attackAndFight) {
if (c.params.size() == 1) {
// assume the param is a unit-ID or feature-ID
if ((c2.params[0] == c.params[0]) &&
(cmd2ID != CMD_SET_WANTED_MAX_SPEED)) {
return ci;
}
}
else if (c.params.size() >= 3) {
if (cmdID < 0) {
BuildInfo bc1(c);
BuildInfo bc2(c2);
if (bc1.def == NULL) continue;
if (bc2.def == NULL) continue;
if (math::fabs(bc1.pos.x - bc2.pos.x) * 2 <= std::max(bc1.GetXSize(), bc2.GetXSize()) * SQUARE_SIZE &&
math::fabs(bc1.pos.z - bc2.pos.z) * 2 <= std::max(bc1.GetZSize(), bc2.GetZSize()) * SQUARE_SIZE) {
return ci;
}
} else {
// assume c and c2 are positional commands
const float3& c1p = c.GetPos(0);
const float3& c2p = c2.GetPos(0);
if ((c1p - c2p).SqLength2D() >= (COMMAND_CANCEL_DIST * COMMAND_CANCEL_DIST))
continue;
if ((c.options & SHIFT_KEY) != 0 && (c.options & INTERNAL_ORDER) != 0)
continue;
return ci;
}
}
}
}
return q.end();
}
示例14: FinishCommand
void CCommandAI::FinishCommand()
{
assert(!commandQue.empty());
const Command cmd = commandQue.front(); //cppcheck false positive, copy is needed here
const bool dontRepeat = (cmd.options & INTERNAL_ORDER);
if (repeatOrders
&& !dontRepeat
&& (cmd.GetID() != CMD_STOP)
&& (cmd.GetID() != CMD_PATROL)
&& (cmd.GetID() != CMD_SET_WANTED_MAX_SPEED)){
commandQue.push_back(cmd);
}
commandQue.pop_front();
inCommand = false;
targetDied = false;
unimportantMove = false;
SetOrderTarget(NULL);
eoh->CommandFinished(*owner, cmd);
eventHandler.UnitCmdDone(owner, cmd);
ClearTargetLock(cmd);
if (commandQue.empty()) {
if (!owner->group) {
eoh->UnitIdle(*owner);
}
eventHandler.UnitIdle(owner);
}
// avoid infinite loops
if (lastFinishCommand != gs->frameNum) {
lastFinishCommand = gs->frameNum;
if (!owner->IsStunned()) {
SlowUpdate();
}
}
}
示例15: MayRequireSetMaxSpeedCommand
static inline bool MayRequireSetMaxSpeedCommand(const Command &c)
{
switch (c.GetID()) {
// this is not a complete list
case CMD_STOP:
case CMD_WAIT:
case CMD_SELFD:
case CMD_FIRE_STATE:
case CMD_MOVE_STATE:
case CMD_ONOFF:
case CMD_REPEAT: {
return false;
}
}
return true;
}