本文整理汇总了C++中CUnit::GetTransporter方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnit::GetTransporter方法的具体用法?C++ CUnit::GetTransporter怎么用?C++ CUnit::GetTransporter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnit
的用法示例。
在下文中一共展示了CUnit::GetTransporter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
}
示例2: 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;
}
}
}
示例3: GetUnitViewPosition
int LuaUnsyncedRead::GetUnitViewPosition(lua_State* L)
{
CUnit* unit = ParseUnit(L, __FUNCTION__, 1);
if (unit == NULL) {
return 0;
}
const bool midPos = (lua_isboolean(L, 2) && lua_toboolean(L, 2));
float3 pos = midPos ? (float3)unit->midPos : (float3)unit->pos;
CTransportUnit *trans=unit->GetTransporter();
if (trans == NULL) {
pos += (unit->speed * gu->timeOffset);
} else {
pos += (trans->speed * gu->timeOffset);
}
lua_pushnumber(L, pos.x);
lua_pushnumber(L, pos.y);
lua_pushnumber(L, pos.z);
return 3;
}
示例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.params.size() == 3) && (owner->commandShotCount > 0) && (commandQue.size() > 1)) {
FinishCommand();
return;
}
if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) {
FinishCommand();
return;
}
} else {
owner->commandShotCount = -1;
if (c.params.size() == 1) {
CUnit* targetUnit = uh->GetUnit(c.params[0]);
if (targetUnit == NULL) { FinishCommand(); return; }
if (targetUnit == owner) { FinishCommand(); return; }
if (targetUnit->GetTransporter() != NULL) { FinishCommand(); return; }
SetOrderTarget(targetUnit);
owner->AttackUnit(targetUnit, c.GetID() == CMD_MANUALFIRE);
inCommand = true;
} else {
float3 pos(c.params[0], c.params[1], c.params[2]);
owner->AttackGround(pos, c.GetID() == CMD_MANUALFIRE);
inCommand = true;
}
}
}
示例5: GenerateWeaponTargets
void CGameHelper::GenerateWeaponTargets(const CWeapon* weapon, const CUnit* lastTargetUnit, std::multimap<float, CUnit*>& targets)
{
const CUnit* attacker = weapon->owner;
const float radius = weapon->range;
const float3& pos = attacker->pos;
const float heightMod = weapon->heightMod;
const float aHeight = weapon->weaponPos.y;
const WeaponDef* weaponDef = weapon->weaponDef;
// how much damage the weapon deals over 1 second
const float secDamage = weaponDef->damages.GetDefaultDamage() * weapon->salvoSize / weapon->reloadTime * GAME_SPEED;
const bool paralyzer = (weaponDef->damages.paralyzeDamageTime != 0);
const std::vector<int>& quads = quadField->GetQuads(pos, radius + (aHeight - std::max(0.f, readmap->initMinHeight)) * heightMod);
const int tempNum = targetTempNum++;
typedef std::vector<int>::const_iterator VectorIt;
typedef std::list<CUnit*>::const_iterator ListIt;
for (VectorIt qi = quads.begin(); qi != quads.end(); ++qi) {
for (int t = 0; t < teamHandler->ActiveAllyTeams(); ++t) {
if (teamHandler->Ally(attacker->allyteam, t)) {
continue;
}
const std::list<CUnit*>& allyTeamUnits = quadField->GetQuad(*qi).teamUnits[t];
for (ListIt ui = allyTeamUnits.begin(); ui != allyTeamUnits.end(); ++ui) {
CUnit* targetUnit = *ui;
float targetPriority = 1.0f;
if (!(targetUnit->category & weapon->onlyTargetCategory)) {
continue;
}
if (targetUnit->GetTransporter() != NULL) {
if (!modInfo.targetableTransportedUnits)
continue;
// the transportee might be "hidden" below terrain, in which case we can't target it
if (targetUnit->pos.y < ground->GetHeightReal(targetUnit->pos.x, targetUnit->pos.z))
continue;
}
if (tempTargetUnits[targetUnit->id] == tempNum) {
continue;
}
tempTargetUnits[targetUnit->id] = tempNum;
if (targetUnit->isUnderWater && !weaponDef->waterweapon) {
continue;
}
if (targetUnit->isDead) {
continue;
}
float3 targPos;
const unsigned short targetLOSState = targetUnit->losStatus[attacker->allyteam];
if (targetLOSState & LOS_INLOS) {
targPos = targetUnit->aimPos;
} else if (targetLOSState & LOS_INRADAR) {
targPos = targetUnit->aimPos + (targetUnit->posErrorVector * radarhandler->radarErrorSize[attacker->allyteam]);
targetPriority *= 10.0f;
} else {
continue;
}
const float modRange = radius + (aHeight - targPos.y) * heightMod;
if ((pos - targPos).SqLength2D() > modRange * modRange) {
continue;
}
const float dist2D = (pos - targPos).Length2D();
const float rangeMul = (dist2D * weaponDef->proximityPriority + modRange * 0.4f + 100.0f);
const float damageMul = weaponDef->damages[targetUnit->armorType] * targetUnit->curArmorMultiple;
targetPriority *= rangeMul;
if (targetLOSState & LOS_INLOS) {
targetPriority *= (secDamage + targetUnit->health);
if (targetUnit == lastTargetUnit) {
targetPriority *= weapon->avoidTarget ? 10.0f : 0.4f;
}
if (paralyzer && targetUnit->paralyzeDamage > (modInfo.paralyzeOnMaxHealth? targetUnit->maxHealth: targetUnit->health)) {
targetPriority *= 4.0f;
}
if (weapon->hasTargetWeight) {
targetPriority *= weapon->TargetWeight(targetUnit);
}
} else {
targetPriority *= (secDamage + 10000.0f);
}
if (targetLOSState & LOS_PREVLOS) {
targetPriority /= (damageMul * targetUnit->power * (0.7f + gs->randFloat() * 0.6f));
//.........这里部分代码省略.........
示例6: ExecuteAttack
void CMobileCAI::ExecuteAttack(Command &c)
{
assert(owner->unitDef->canAttack);
// limit how far away we fly based on our movestate
if (tempOrder && orderTarget) {
const float3& closestPos = ClosestPointOnLine(commandPos1, commandPos2, owner->pos);
const float curTargetDist = LinePointDist(closestPos, commandPos2, orderTarget->pos);
const float maxTargetDist = (500 * owner->moveState + owner->maxRange);
if (owner->moveState < MOVESTATE_ROAM && curTargetDist > maxTargetDist) {
StopMove();
FinishCommand();
return;
}
}
// check if we are in direct command of attacker
if (!inCommand) {
if (c.params.size() == 1) {
CUnit* targetUnit = unitHandler->GetUnit(c.params[0]);
// check if we have valid target parameter and that we aren't attacking ourselves
if (targetUnit == NULL) { StopMove(); FinishCommand(); return; }
if (targetUnit == owner) { StopMove(); FinishCommand(); return; }
if (targetUnit->GetTransporter() != NULL && !modInfo.targetableTransportedUnits) {
StopMove(); FinishCommand(); return;
}
const float3 tgtErrPos = targetUnit->pos + owner->posErrorVector * 128;
const float3 tgtPosDir = (tgtErrPos - owner->pos).Normalize();
SetGoal(tgtErrPos - tgtPosDir * targetUnit->radius, owner->pos);
SetOrderTarget(targetUnit);
owner->AttackUnit(targetUnit, (c.options & INTERNAL_ORDER) == 0, c.GetID() == CMD_MANUALFIRE);
inCommand = true;
}
else if (c.params.size() >= 3) {
// user gave force-fire attack command
SetGoal(c.GetPos(0), owner->pos);
inCommand = true;
}
}
// if our target is dead or we lost it then stop attacking
// NOTE: unit should actually just continue to target area!
if (targetDied || (c.params.size() == 1 && UpdateTargetLostTimer(int(c.params[0])) == 0)) {
// cancel keeppointingto
StopMove();
FinishCommand();
return;
}
// user clicked on enemy unit (note that we handle aircrafts slightly differently)
if (orderTarget != NULL) {
bool tryTargetRotate = false;
bool tryTargetHeading = false;
float edgeFactor = 0.0f; // percent offset to target center
const float3 targetMidPosVec = owner->midPos - orderTarget->midPos;
const float targetGoalDist = (orderTarget->pos + owner->posErrorVector * 128.0f).SqDistance2D(goalPos);
const float targetPosDist = Square(10.0f + orderTarget->pos.distance2D(owner->pos) * 0.2f);
const float minPointingDist = std::min(1.0f * owner->losRadius * loshandler->losDiv, owner->maxRange * 0.9f);
// FIXME? targetMidPosMaxDist is 3D, but compared with a 2D value
const float targetMidPosDist2D = targetMidPosVec.Length2D();
//const float targetMidPosMaxDist = owner->maxRange - (orderTarget->speed.SqLength() / owner->unitDef->maxAcc);
if (!owner->weapons.empty()) {
if (!(c.options & ALT_KEY) && SkipParalyzeTarget(orderTarget)) {
StopMove();
FinishCommand();
return;
}
}
for (unsigned int wNum = 0; wNum < owner->weapons.size(); wNum++) {
CWeapon* w = owner->weapons[wNum];
if (c.GetID() == CMD_MANUALFIRE) {
assert(owner->unitDef->canManualFire);
if (!w->weaponDef->manualfire) {
continue;
}
}
tryTargetRotate = w->TryTargetRotate(orderTarget, (c.options & INTERNAL_ORDER) == 0);
tryTargetHeading = w->TryTargetHeading(GetHeadingFromVector(-targetMidPosVec.x, -targetMidPosVec.z), orderTarget->pos, orderTarget != NULL, orderTarget);
if (tryTargetRotate || tryTargetHeading)
break;
edgeFactor = math::fabs(w->targetBorder);
}
//.........这里部分代码省略.........