本文整理汇总了C++中Command::GetPos方法的典型用法代码示例。如果您正苦于以下问题:C++ Command::GetPos方法的具体用法?C++ Command::GetPos怎么用?C++ Command::GetPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command::GetPos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteAttack
void CAirCAI::ExecuteAttack(Command& c)
{
assert(owner->unitDef->canAttack);
targetAge++;
if (tempOrder && owner->moveState == MOVESTATE_MANEUVER) {
// limit how far away we fly
if (orderTarget && LinePointDist(commandPos1, commandPos2, orderTarget->pos) > 1500) {
owner->AttackUnit(NULL, false, false);
FinishCommand();
return;
}
}
if (inCommand) {
if (targetDied || (c.params.size() == 1 && UpdateTargetLostTimer(int(c.params[0])) == 0)) {
FinishCommand();
return;
}
if (orderTarget != NULL) {
if (orderTarget->unitDef->canfly && orderTarget->IsCrashing()) {
owner->AttackUnit(NULL, false, false);
FinishCommand();
return;
}
if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) {
owner->AttackUnit(NULL, false, false);
FinishCommand();
return;
}
}
} else {
targetAge = 0;
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;
}
SetGoal(targetUnit->pos, owner->pos, cancelDistance);
SetOrderTarget(targetUnit);
owner->AttackUnit(targetUnit, (c.options & INTERNAL_ORDER) == 0, false);
inCommand = true;
} else {
SetGoal(c.GetPos(0), owner->pos, cancelDistance);
owner->AttackGround(c.GetPos(0), (c.options & INTERNAL_ORDER) == 0, false);
inCommand = true;
}
}
}
示例2: ExecuteCapture
void CBuilderCAI::ExecuteCapture(Command& c)
{
// not all builders are capture-capable by default
if (!owner->unitDef->canCapture)
return;
if (c.params.size() == 1 || c.params.size() == 5) {
// capture unit
CUnit* unit = unitHandler->GetUnit(c.params[0]);
if (unit == NULL) {
FinishCommand();
return;
}
if (c.params.size() == 5) {
const float3& pos = c.GetPos(1);
const float radius = c.params[4] + 100; // do not walk too far outside capture area
if (((pos - unit->pos).SqLength2D() > (radius * radius) ||
(ownerBuilder->curCapture == unit && unit->IsMoving() && !IsInBuildRange(unit)))) {
StopMove();
FinishCommand();
return;
}
}
if (unit->unitDef->capturable && unit->team != owner->team && UpdateTargetLostTimer(unit->id)) {
if (MoveInBuildRange(unit)) {
ownerBuilder->SetCaptureTarget(unit);
}
} else {
StopMove();
FinishCommand();
}
} else if (c.params.size() == 4) {
// area capture
const float3 pos = c.GetPos(0);
const float radius = c.params[3];
ownerBuilder->StopBuild();
if (FindCaptureTargetAndCapture(pos, radius, c.options, (c.options & META_KEY))) {
inCommand = false;
SlowUpdate();
return;
}
if (!(c.options & ALT_KEY)) {
FinishCommand();
}
} else {
FinishCommand();
}
}
示例3: 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);
}
示例4: 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;
}
}
}
示例5: ExecuteResurrect
void CBuilderCAI::ExecuteResurrect(Command& c)
{
// not all builders are resurrect-capable by default
if (!owner->unitDef->canResurrect)
return;
if (c.params.size() == 1) {
unsigned int id = (unsigned int) c.params[0];
if (id >= unitHandler->MaxUnits()) { // resurrect feature
CFeature* feature = featureHandler->GetFeature(id - unitHandler->MaxUnits());
if (feature && feature->udef != NULL) {
if (((c.options & INTERNAL_ORDER) && !(c.options & CONTROL_KEY) && IsFeatureBeingReclaimed(feature->id, owner)) ||
!ResurrectObject(feature)) {
StopMove();
RemoveUnitFromResurrecters(owner);
FinishCommand();
}
else {
AddUnitToResurrecters(owner);
}
} else {
RemoveUnitFromResurrecters(owner);
if (ownerBuilder->lastResurrected && unitHandler->GetUnitUnsafe(ownerBuilder->lastResurrected) != NULL && owner->unitDef->canRepair) {
// resurrection finished, start repair (by overwriting the current order)
c = Command(CMD_REPAIR, c.options | INTERNAL_ORDER, ownerBuilder->lastResurrected);
ownerBuilder->lastResurrected = 0;
inCommand = false;
SlowUpdate();
return;
}
StopMove();
FinishCommand();
}
} else { // resurrect unit
RemoveUnitFromResurrecters(owner);
FinishCommand();
}
} else if (c.params.size() == 4) {
// area resurrect
const float3 pos = c.GetPos(0);
const float radius = c.params[3];
if (FindResurrectableFeatureAndResurrect(pos, radius, c.options, (c.options & META_KEY))) {
inCommand = false;
SlowUpdate();
return;
}
if (!(c.options & ALT_KEY)) {
FinishCommand();
}
} else {
// wrong number of parameters
RemoveUnitFromResurrecters(owner);
FinishCommand();
}
}
示例6: 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;
}
示例7: ExecuteAreaAttack
void CAirCAI::ExecuteAreaAttack(Command& c)
{
assert(owner->unitDef->canAttack);
// FIXME: check owner->UsingScriptMoveType() and skip rest if true?
AAirMoveType* myPlane = GetStrafeAirMoveType(owner);
if (targetDied) {
targetDied = false;
inCommand = false;
}
const float3& pos = c.GetPos(0);
const float radius = c.params[3];
if (inCommand) {
if (myPlane->aircraftState == AAirMoveType::AIRCRAFT_LANDED)
inCommand = false;
if (orderTarget && orderTarget->pos.SqDistance2D(pos) > Square(radius)) {
inCommand = false;
// target wandered out of the attack-area
SetOrderTarget(NULL);
SelectNewAreaAttackTargetOrPos(c);
}
} else {
if (myPlane->aircraftState != AAirMoveType::AIRCRAFT_LANDED) {
inCommand = true;
SelectNewAreaAttackTargetOrPos(c);
}
}
}
示例8: 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;
}
示例9: IsCommandInMap
static inline bool IsCommandInMap(const Command& c)
{
// TODO:
// extend the check to commands for which
// position is not stored in params[0..2]
if (c.params.size() < 3) {
return true;
}
if ((c.GetPos(0)).IsInBounds()) {
return true;
}
const float3 pos = c.GetPos(0);
LOG_L(L_DEBUG, "Dropped command %d: outside of map (x:%f y:%f z:%f)", c.GetID(), pos.x, pos.y, pos.z);
return false;
}
示例10: UnloadDrop
void CTransportCAI::UnloadDrop(Command& c)
{
// fly over and drop unit
if (inCommand) {
if (!owner->script->IsBusy()) {
FinishCommand();
}
} else {
auto transport = static_cast<CTransportUnit*>(owner);
const auto& transportees = transport->GetTransportedUnits();
if (transportees.empty() || dropSpots.empty()) {
FinishCommand();
return;
}
float3 pos = c.GetPos(0);
// head towards goal
// note that HoverAirMoveType must be modified to allow
// non-stop movement through goals for this to work well
if (goalPos.SqDistance2D(pos) > Square(20.0f)) {
SetGoal(lastDropPos = pos, owner->pos);
}
CHoverAirMoveType* am = dynamic_cast<CHoverAirMoveType*>(owner->moveType);
CUnit* transportee = (transportees.front()).unit;
if (am != NULL) {
pos.y = CGround::GetHeightAboveWater(pos.x, pos.z);
am->maxDrift = 1.0f;
// if near target or passed it accidentally, drop unit
if (owner->pos.SqDistance2D(pos) < Square(40.0f) || (((pos - owner->pos).Normalize()).SqDistance(owner->frontdir) > 0.25 && owner->pos.SqDistance2D(pos)< (205*205))) {
am->SetAllowLanding(false);
owner->script->EndTransport();
transport->DetachUnitFromAir(transportee, pos);
dropSpots.pop_back();
if (dropSpots.empty()) {
// move the transport away after last drop
SetGoal(owner->pos + owner->frontdir * 200, owner->pos);
}
FinishCommand();
}
} else {
inCommand = true;
StopMove();
owner->script->TransportDrop(transportee, pos);
}
}
}
示例11: IsCommandInMap
static inline bool IsCommandInMap(const Command& c)
{
// TODO:
// extend the check to commands for which
// position is not stored in params[0..2]
if (c.params.size() >= 3) {
return ((c.GetPos(0)).IsInBounds());
}
return true;
}
示例12: UnloadUnits_Drop
void CTransportCAI::UnloadUnits_Drop(Command& c, CTransportUnit* transport)
{
// called repeatedly for each unit till units are unloaded
if (lastCall == gs->frameNum) {
// avoid infinite loops
return;
}
lastCall = gs->frameNum;
const auto& transportees = transport->GetTransportedUnits();
if (transportees.empty()) {
FinishCommand();
return;
}
bool canUnload = false;
// at the start of each user command
if (isFirstIteration) {
dropSpots.clear();
startingDropPos = c.GetPos(0);
approachVector = (startingDropPos - owner->pos).Normalize();
canUnload = FindEmptyDropSpots(startingDropPos, startingDropPos + approachVector * std::max(16.0f, c.params[3]), dropSpots);
} else if (!dropSpots.empty() ) {
// make sure we check current spot in front of us each
// unload, take last landing pos as new start spot
// pos = dropSpots.back();
canUnload = !dropSpots.empty();
}
if (canUnload) {
if (SpotIsClear(dropSpots.back(), (transportees.front()).unit)) {
Command c2(CMD_UNLOAD_UNIT, c.options | INTERNAL_ORDER, dropSpots.back());
commandQue.push_front(c2);
SlowUpdate();
isFirstIteration = false;
return;
} else {
dropSpots.pop_back();
}
} else {
startingDropPos = -OnesVector;
isFirstIteration = true;
dropSpots.clear();
FinishCommand();
}
}
示例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: ExecuteMove
/**
* @brief executes the move command
*/
void CMobileCAI::ExecuteMove(Command &c)
{
const float3 cmdPos = c.GetPos(0);
if (cmdPos != goalPos) {
SetGoal(cmdPos, owner->pos);
}
if ((owner->pos - goalPos).SqLength2D() < cancelDistance || owner->moveType->progressState == AMoveType::Failed) {
FinishCommand();
}
return;
}
示例15: UnloadUnits_Drop
void CTransportCAI::UnloadUnits_Drop(Command& c, CTransportUnit* transport)
{
// called repeatedly for each unit till units are unloaded
if (lastCall == gs->frameNum) { // avoid infinite loops
return;
}
lastCall = gs->frameNum;
if (static_cast<CTransportUnit*>(owner)->GetTransportedUnits().empty()) {
FinishCommand();
return;
}
float3 pos = c.GetPos(0);
float radius = c.params[3];
bool canUnload = false;
// at the start of each user command
if (isFirstIteration) {
dropSpots.clear();
startingDropPos = pos;
approachVector = startingDropPos - owner->pos;
approachVector.Normalize();
canUnload = FindEmptyDropSpots(pos, pos + approachVector * std::max(16.0f,radius), dropSpots);
} else if (!dropSpots.empty() ) {
// make sure we check current spot infront of us each unload
pos = dropSpots.back(); // take last landing pos as new start spot
canUnload = !dropSpots.empty();
}
if (canUnload) {
if (SpotIsClear(dropSpots.back(), static_cast<CTransportUnit*>(owner)->GetTransportedUnits().front().unit)) {
const float3 pos = dropSpots.back();
Command c2(CMD_UNLOAD_UNIT, c.options | INTERNAL_ORDER, pos);
commandQue.push_front(c2);
SlowUpdate();
isFirstIteration = false;
return;
} else {
dropSpots.pop_back();
}
} else {
startingDropPos = float3(-1.0f, -1.0f, -1.0f);
isFirstIteration = true;
dropSpots.clear();
FinishCommand();
}
}