本文整理汇总了C++中CUnit::KillUnit方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnit::KillUnit方法的具体用法?C++ CUnit::KillUnit怎么用?C++ CUnit::KillUnit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnit
的用法示例。
在下文中一共展示了CUnit::KillUnit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SelfDestruct
void CTeam::SelfDestruct()
{
for (CUnitSet::iterator ui = units.begin(); ui != units.end(); ++ui) {
CUnit* unit = (*ui);
if (unit != NULL && unit->unitDef->canSelfD) {
if (unit->beingBuilt) {
unit->KillUnit(false, true, NULL); // kill units under construction without explosion
} else {
unit->KillUnit(true, false, NULL);
}
}
}
Died();
}
示例2: KillUnit
void CTransportUnit::KillUnit(bool selfDestruct, bool reclaimed, CUnit* attacker, bool)
{
std::list<TransportedUnit>::iterator ti;
for (ti = transported.begin(); ti != transported.end(); ++ti) {
CUnit* u = ti->unit;
u->transporter = 0;
u->DeleteDeathDependence(this);
// prevent a position teleport on the next movetype update if
// the transport died in a place that the unit being carried
// could not get to on its own
if (!u->pos.IsInBounds()) {
u->KillUnit(false, false, 0x0, false);
continue;
} else {
const float gh = ground->GetHeight2(u->pos.x, u->pos.z);
if (gh < -u->unitDef->maxWaterDepth || gh > -u->unitDef->minWaterDepth) {
// note: should also check movedef restraints?
u->KillUnit(false, false, 0x0, false);
continue;
}
}
if (!unitDef->releaseHeld) {
if (!selfDestruct) {
// we don't want it to leave a corpse
u->DoDamage(DamageArray() * 1000000, 0, ZeroVector);
}
u->KillUnit(selfDestruct, reclaimed, attacker);
} else {
u->stunned = (u->paralyzeDamage > u->health);
if (CGroundMoveType* mt = dynamic_cast<CGroundMoveType*>(u->moveType)) {
mt->StartFlying();
}
u->speed = speed;
eventHandler.UnitUnloaded(u, this);
}
}
CUnit::KillUnit(selfDestruct, reclaimed, attacker);
}
示例3: GetUnitVal
//.........这里部分代码省略.........
case KTAN:
return int(1024*math::tanf(TAANG2RAD*(float)p1));
case SQRT:
return int(math::sqrt((float)p1));
case FLANK_B_MODE:
return unit->flankingBonusMode;
case FLANK_B_DIR:
switch (p1) {
case 1: return int(unit->flankingBonusDir.x * COBSCALE);
case 2: return int(unit->flankingBonusDir.y * COBSCALE);
case 3: return int(unit->flankingBonusDir.z * COBSCALE);
case 4: unit->flankingBonusDir.x = (p2/(float)COBSCALE); return 0;
case 5: unit->flankingBonusDir.y = (p2/(float)COBSCALE); return 0;
case 6: unit->flankingBonusDir.z = (p2/(float)COBSCALE); return 0;
case 7: unit->flankingBonusDir = float3(p2/(float)COBSCALE, p3/(float)COBSCALE, p4/(float)COBSCALE).Normalize(); return 0;
default: return(-1);
}
case FLANK_B_MOBILITY_ADD:
return int(unit->flankingBonusMobilityAdd * COBSCALE);
case FLANK_B_MAX_DAMAGE:
return int((unit->flankingBonusAvgDamage + unit->flankingBonusDifDamage) * COBSCALE);
case FLANK_B_MIN_DAMAGE:
return int((unit->flankingBonusAvgDamage - unit->flankingBonusDifDamage) * COBSCALE);
case KILL_UNIT: {
//! ID 0 is reserved for the script's owner
CUnit* u = (p1 > 0)? uh->GetUnit(p1): this->unit;
if (u == NULL) {
return 0;
}
if (u->beingBuilt) {
// no explosions and no corpse for units under construction
u->KillUnit(false, true, NULL);
} else {
u->KillUnit(p2 != 0, p3 != 0, NULL);
}
return 1;
}
case WEAPON_RELOADSTATE: {
const int np1 = -p1;
if (p1 > 0 && static_cast<size_t>(p1) <= unit->weapons.size()) {
return unit->weapons[p1-1]->reloadStatus;
}
else if (np1 > 0 && static_cast<size_t>(np1) <= unit->weapons.size()) {
const int old = unit->weapons[np1 - 1]->reloadStatus;
unit->weapons[np1 - 1]->reloadStatus = p2;
return old;
}
else {
return -1;
}
}
case WEAPON_RELOADTIME: {
const int np1 = -p1;
if (p1 > 0 && static_cast<size_t>(p1) <= unit->weapons.size()) {
return unit->weapons[p1-1]->reloadTime;
}
else if (np1 > 0 && static_cast<size_t>(np1) <= unit->weapons.size()) {
const int old = unit->weapons[np1 - 1]->reloadTime;
unit->weapons[np1 - 1]->reloadTime = p2;
return old;
}
else {
return -1;
示例4: Update
void CUnitHandler::Update()
{
auto UNIT_SANITY_CHECK = [](const CUnit* unit) {
unit->pos.AssertNaNs();
unit->midPos.AssertNaNs();
unit->relMidPos.AssertNaNs();
unit->speed.AssertNaNs();
unit->deathSpeed.AssertNaNs();
unit->rightdir.AssertNaNs();
unit->updir.AssertNaNs();
unit->frontdir.AssertNaNs();
if (unit->unitDef->IsGroundUnit()) {
assert(unit->pos.x >= -(float3::maxxpos * 16.0f));
assert(unit->pos.x <= (float3::maxxpos * 16.0f));
assert(unit->pos.z >= -(float3::maxzpos * 16.0f));
assert(unit->pos.z <= (float3::maxzpos * 16.0f));
}
};
DeleteUnitsNow();
{
SCOPED_TIMER("Unit::MoveType::Update");
for (activeUpdateUnit = 0; activeUpdateUnit < activeUnits.size();++activeUpdateUnit) {
CUnit* unit = activeUnits[activeUpdateUnit];
AMoveType* moveType = unit->moveType;
UNIT_SANITY_CHECK(unit);
if (moveType->Update()) {
eventHandler.UnitMoved(unit);
}
if (!unit->pos.IsInBounds() && (unit->speed.w > MAX_UNIT_SPEED)) {
// this unit is not coming back, kill it now without any death
// sequence (so deathScriptFinished becomes true immediately)
unit->KillUnit(nullptr, false, true, false);
}
UNIT_SANITY_CHECK(unit);
assert(activeUnits[activeUpdateUnit] == unit);
}
}
{
// Delete dead units
for (activeUpdateUnit = 0; activeUpdateUnit < activeUnits.size();++activeUpdateUnit) {
CUnit* unit = activeUnits[activeUpdateUnit];
if (!unit->deathScriptFinished)
continue;
// there are many ways to fiddle with "deathScriptFinished", so a unit
// may arrive here not having been properly killed (with isDead still
// false)
// make sure we always call Killed; no-op if isDead is already true
unit->KillUnit(nullptr, false, true, true);
DeleteUnit(unit);
assert(activeUnits[activeUpdateUnit] == unit);
}
}
{
SCOPED_TIMER("Unit::UpdateLocalModel");
for (CUnit* unit: activeUnits) {
// UnitScript only applies piece-space transforms so
// we apply the forward kinematics update separately
// (only if we have any dirty pieces)
// add ID as offset so the bounding-box update does
// not run at the same time for every model
unit->localModel.Update(gs->frameNum + unit->id);
}
}
{
SCOPED_TIMER("Unit::SlowUpdate");
assert(activeSlowUpdateUnit >= 0);
// reset the iterator every <UNIT_SLOWUPDATE_RATE> frames
if ((gs->frameNum % UNIT_SLOWUPDATE_RATE) == 0) {
activeSlowUpdateUnit = 0;
}
// stagger the SlowUpdate's
unsigned int n = (activeUnits.size() / UNIT_SLOWUPDATE_RATE) + 1;
for (; activeSlowUpdateUnit < activeUnits.size() && n != 0; ++activeSlowUpdateUnit) {
CUnit* unit = activeUnits[activeSlowUpdateUnit];
UNIT_SANITY_CHECK(unit);
unit->SlowUpdate();
unit->SlowUpdateWeapons();
UNIT_SANITY_CHECK(unit);
n--;
}
}
{
SCOPED_TIMER("Unit::Update");
//.........这里部分代码省略.........
示例5: Update
void CUnitHandler::Update()
{
{
GML_STDMUTEX_LOCK(runit); // Update
if (!unitsToBeRemoved.empty()) {
GML_RECMUTEX_LOCK(obj); // Update
while (!unitsToBeRemoved.empty()) {
eventHandler.DeleteSyncedObjects(); // the unit destructor may invoke eventHandler, so we need to call these for every unit to clear invaild references from the batching systems
GML_RECMUTEX_LOCK(unit); // Update
eventHandler.DeleteSyncedUnits();
GML_RECMUTEX_LOCK(proj); // Update - projectile drawing may access owner() and lead to crash
GML_RECMUTEX_LOCK(sel); // Update - unit is removed from selectedUnits in ~CObject, which is too late.
GML_RECMUTEX_LOCK(quad); // Update - make sure unit does not get partially deleted before before being removed from the quadfield
CUnit* delUnit = unitsToBeRemoved.back();
unitsToBeRemoved.pop_back();
DeleteUnitNow(delUnit);
}
}
eventHandler.UpdateUnits();
}
GML::UpdateTicks();
#define VECTOR_SANITY_CHECK(v) \
assert(!math::isnan(v.x) && !math::isinf(v.x)); \
assert(!math::isnan(v.y) && !math::isinf(v.y)); \
assert(!math::isnan(v.z) && !math::isinf(v.z));
#define MAPPOS_SANITY_CHECK(unit) \
if (unit->unitDef->IsGroundUnit()) { \
assert(unit->pos.x >= -(float3::maxxpos * 16.0f)); \
assert(unit->pos.x <= (float3::maxxpos * 16.0f)); \
assert(unit->pos.z >= -(float3::maxzpos * 16.0f)); \
assert(unit->pos.z <= (float3::maxzpos * 16.0f)); \
}
#define UNIT_SANITY_CHECK(unit) \
VECTOR_SANITY_CHECK(unit->pos); \
VECTOR_SANITY_CHECK(unit->midPos); \
VECTOR_SANITY_CHECK(unit->relMidPos); \
VECTOR_SANITY_CHECK(unit->speed); \
VECTOR_SANITY_CHECK(unit->deathSpeed); \
VECTOR_SANITY_CHECK(unit->residualImpulse); \
VECTOR_SANITY_CHECK(unit->rightdir); \
VECTOR_SANITY_CHECK(unit->updir); \
VECTOR_SANITY_CHECK(unit->frontdir); \
MAPPOS_SANITY_CHECK(unit);
{
SCOPED_TIMER("Unit::MoveType::Update");
std::list<CUnit*>::iterator usi;
for (usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
AMoveType* moveType = unit->moveType;
UNIT_SANITY_CHECK(unit);
if (moveType->Update()) {
eventHandler.UnitMoved(unit);
}
if (!unit->pos.IsInBounds() && (unit->speed.SqLength() > (MAX_UNIT_SPEED * MAX_UNIT_SPEED))) {
// this unit is not coming back, kill it now without any death
// sequence (so deathScriptFinished becomes true immediately)
unit->KillUnit(NULL, false, true, false);
}
UNIT_SANITY_CHECK(unit);
GML::GetTicks(unit->lastUnitUpdate);
}
}
{
SCOPED_TIMER("Unit::Update");
std::list<CUnit*>::iterator usi;
for (usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
UNIT_SANITY_CHECK(unit);
if (unit->deathScriptFinished) {
// there are many ways to fiddle with "deathScriptFinished", so a unit may
// arrive here without having been properly killed (and isDead still false),
// which can result in MT deadlocking -- FIXME verify this
// (KU returns early if isDead)
unit->KillUnit(NULL, false, true);
DeleteUnit(unit);
} else {
unit->Update();
}
UNIT_SANITY_CHECK(unit);
}
}
//.........这里部分代码省略.........
示例6: Update
void CUnitHandler::Update()
{
{
if (!unitsToBeRemoved.empty()) {
while (!unitsToBeRemoved.empty()) {
eventHandler.DeleteSyncedObjects(); // the unit destructor may invoke eventHandler, so we need to call these for every unit to clear invaild references from the batching systems
eventHandler.DeleteSyncedUnits();
CUnit* delUnit = unitsToBeRemoved.back();
unitsToBeRemoved.pop_back();
DeleteUnitNow(delUnit);
}
}
eventHandler.UpdateUnits();
}
#define MAPPOS_SANITY_CHECK(unit) \
if (unit->unitDef->IsGroundUnit()) { \
assert(unit->pos.x >= -(float3::maxxpos * 16.0f)); \
assert(unit->pos.x <= (float3::maxxpos * 16.0f)); \
assert(unit->pos.z >= -(float3::maxzpos * 16.0f)); \
assert(unit->pos.z <= (float3::maxzpos * 16.0f)); \
}
#define UNIT_SANITY_CHECK(unit) \
unit->pos.AssertNaNs(); \
unit->midPos.AssertNaNs(); \
unit->relMidPos.AssertNaNs(); \
unit->speed.AssertNaNs(); \
unit->deathSpeed.AssertNaNs(); \
unit->rightdir.AssertNaNs(); \
unit->updir.AssertNaNs(); \
unit->frontdir.AssertNaNs(); \
MAPPOS_SANITY_CHECK(unit);
{
SCOPED_TIMER("Unit::MoveType::Update");
for (auto usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
AMoveType* moveType = unit->moveType;
UNIT_SANITY_CHECK(unit);
if (moveType->Update()) {
eventHandler.UnitMoved(unit);
}
if (!unit->pos.IsInBounds() && (Square(unit->speed.w) > (MAX_UNIT_SPEED * MAX_UNIT_SPEED))) {
// this unit is not coming back, kill it now without any death
// sequence (so deathScriptFinished becomes true immediately)
unit->KillUnit(NULL, false, true, false);
}
UNIT_SANITY_CHECK(unit);
}
}
{
// Delete dead units
for (auto usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
if (unit->deathScriptFinished) {
// there are many ways to fiddle with "deathScriptFinished", so a unit may
// arrive here without having been properly killed (and isDead still false),
// which can result in MT deadlocking -- FIXME verify this
// (KU returns early if isDead)
unit->KillUnit(NULL, false, true);
DeleteUnit(unit);
}
}
}
{
SCOPED_TIMER("Unit::UpdatePieceMatrices");
for (auto usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
// UnitScript only applies piece-space transforms so
// we apply the forward kinematics update separately
// (only if we have any dirty pieces)
CUnit* unit = *usi;
unit->localModel->UpdatePieceMatrices();
}
}
{
SCOPED_TIMER("Unit::Update");
for (auto usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
UNIT_SANITY_CHECK(unit);
unit->Update();
UNIT_SANITY_CHECK(unit);
}
}
{
SCOPED_TIMER("Unit::SlowUpdate");
//.........这里部分代码省略.........
示例7: assert
void CTransportUnit::KillUnit(bool selfDestruct, bool reclaimed, CUnit* attacker, bool)
{
if (!isDead) {
// guard against recursive invocation via
// transportee->KillUnit
// helper->Explosion
// helper->DoExplosionDamage
// unit->DoDamage
// unit->KillUnit
// in the case that unit == this
isDead = true;
// ::KillUnit might be called multiple times while !deathScriptFinished,
// but it makes no sense to kill/detach our transportees more than once
std::list<TransportedUnit>::iterator ti;
for (ti = transportedUnits.begin(); ti != transportedUnits.end(); ++ti) {
CUnit* transportee = ti->unit;
assert(transportee != this);
if (transportee->isDead)
continue;
const float gh = ground->GetHeightReal(transportee->pos.x, transportee->pos.z);
transportee->transporter = NULL;
transportee->DeleteDeathDependence(this, DEPENDENCE_TRANSPORTER);
// prevent a position teleport on the next movetype update if
// the transport died in a place that the unit being carried
// could not get to on its own
if (!transportee->pos.IsInBounds()) {
transportee->KillUnit(false, false, NULL, false);
continue;
} else {
// immobile units can still be transported
// via script trickery, guard against this
if (!transportee->unitDef->IsAllowedTerrainHeight(gh)) {
transportee->KillUnit(false, false, NULL, false);
continue;
}
}
if (!unitDef->releaseHeld) {
if (!selfDestruct) {
// we don't want it to leave a corpse
transportee->DoDamage(DamageArray(1e6f), ZeroVector, NULL, -DAMAGE_EXTSOURCE_KILLED);
}
transportee->KillUnit(selfDestruct, reclaimed, attacker);
} else {
// place unit near the place of death of the transport
// if it's a ground transport and uses a piece-in-ground method
// to hide units
if (transportee->pos.y < gh) {
const float k = (transportee->radius + radius) * std::max(unitDef->unloadSpread, 1.0f);
// try to unload in a presently unoccupied spot
// unload on a wreck if suitable position not found
for (int i = 0; i < 10; ++i) {
float3 pos = transportee->pos;
pos.x += (gs->randFloat() * 2 * k - k);
pos.z += (gs->randFloat() * 2 * k - k);
pos.y = ground->GetHeightReal(transportee->pos.x, transportee->pos.z);
if (qf->GetUnitsExact(pos, transportee->radius + 2).empty()) {
transportee->Move3D(pos, false);
break;
}
}
} else if (CGroundMoveType* mt = dynamic_cast<CGroundMoveType*>(transportee->moveType)) {
mt->StartFlying();
}
transportee->moveType->SlowUpdate();
transportee->moveType->LeaveTransport();
// issue a move order so that unit won't try to return to pick-up pos in IdleCheck()
if (unitDef->canfly && transportee->unitDef->canmove) {
Command c(CMD_MOVE);
c.params.push_back(transportee->pos.x);
c.params.push_back(ground->GetHeightAboveWater(transportee->pos.x, transportee->pos.z));
c.params.push_back(transportee->pos.z);
transportee->commandAI->GiveCommand(c);
}
transportee->stunned = (transportee->paralyzeDamage > (modInfo.paralyzeOnMaxHealth? transportee->maxHealth: transportee->health));
transportee->speed = speed * (0.5f + 0.5f * gs->randFloat());
if (CBuilding* building = dynamic_cast<CBuilding*>(transportee)) {
// this building may end up in a strange position, so kill it
building->KillUnit(selfDestruct, reclaimed, attacker);
}
eventHandler.UnitUnloaded(transportee, this);
}
}
transportedUnits.clear();
//.........这里部分代码省略.........
示例8: if
void CTransportUnit::KillUnit(bool selfDestruct, bool reclaimed, CUnit* attacker, bool)
{
std::list<TransportedUnit>::iterator ti;
for (ti = transported.begin(); ti != transported.end(); ++ti) {
CUnit* u = ti->unit;
const float gh = ground->GetHeight2(u->pos.x, u->pos.z);
u->transporter = 0;
u->DeleteDeathDependence(this);
// prevent a position teleport on the next movetype update if
// the transport died in a place that the unit being carried
// could not get to on its own
if (!u->pos.IsInBounds()) {
u->KillUnit(false, false, NULL, false);
continue;
} else {
// immobile units can still be transported
// via script trickery, guard against this
if (u->unitDef->movedata != NULL && gh < -u->unitDef->movedata->depth) {
// always treat depth as maxWaterDepth (fails if
// the transportee is a ship, but so does using
// UnitDef::{min, max}WaterDepth)
u->KillUnit(false, false, NULL, false);
continue;
}
}
if (!unitDef->releaseHeld) {
if (!selfDestruct) {
// we don't want it to leave a corpse
u->DoDamage(DamageArray() * 1000000, 0, ZeroVector);
}
u->KillUnit(selfDestruct, reclaimed, attacker);
} else {
// place unit near the place of death of the transport
// if it's a ground transport and uses a piece-in-ground method
// to hide units
if (u->pos.y < gh) {
const float k = (u->radius + radius)*std::max(unitDef->unloadSpread, 1.f);
// try to unload in a presently unoccupied spot
// unload on a wreck if suitable position not found
for (int i = 0; i<10; ++i) {
float3 pos = u->pos;
pos.x += gs->randFloat()*2*k - k;
pos.z += gs->randFloat()*2*k - k;
pos.y = ground->GetHeight2(u->pos.x, u->pos.z);
if (qf->GetUnitsExact(pos, u->radius + 2).empty()) {
u->pos = pos;
break;
}
}
u->UpdateMidPos();
} else if (CGroundMoveType* mt = dynamic_cast<CGroundMoveType*>(u->moveType)) {
mt->StartFlying();
}
u->stunned = (u->paralyzeDamage > u->health);
u->moveType->LeaveTransport();
u->speed = speed*(0.5f + 0.5f*gs->randFloat());
eventHandler.UnitUnloaded(u, this);
}
}
CUnit::KillUnit(selfDestruct, reclaimed, attacker);
}
示例9: Update
void CUnitHandler::Update()
{
{
GML_STDMUTEX_LOCK(runit); // Update
if (!toBeRemoved.empty()) {
GML_RECMUTEX_LOCK(unit); // Update - for anti-deadlock purposes.
GML_RECMUTEX_LOCK(sel); // Update - unit is removed from selectedUnits in ~CObject, which is too late.
GML_RECMUTEX_LOCK(quad); // Update - make sure unit does not get partially deleted before before being removed from the quadfield
GML_STDMUTEX_LOCK(proj); // Update - projectile drawing may access owner() and lead to crash
eventHandler.DeleteSyncedUnits();
while (!toBeRemoved.empty()) {
CUnit* delUnit = toBeRemoved.back();
toBeRemoved.pop_back();
DeleteUnitNow(delUnit);
}
}
eventHandler.UpdateUnits();
}
GML_UPDATE_TICKS();
{
SCOPED_TIMER("Unit Movetype update");
std::list<CUnit*>::iterator usi;
for (usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
AMoveType* moveType = unit->moveType;
if (moveType->Update()) {
eventHandler.UnitMoved(unit);
}
GML_GET_TICKS(unit->lastUnitUpdate);
}
}
{
SCOPED_TIMER("Unit update");
std::list<CUnit*>::iterator usi;
for (usi = activeUnits.begin(); usi != activeUnits.end(); ++usi) {
CUnit* unit = *usi;
if (unit->deathScriptFinished) {
// there are many ways to fiddle with "deathScriptFinished", so a unit may
// arrive here without having been properly killed (and isDead still false),
// which can result in MT deadlocking -- FIXME verify this
// (KU returns early if isDead)
unit->KillUnit(false, true, NULL);
DeleteUnit(unit);
} else {
unit->Update();
}
}
}
{
SCOPED_TIMER("Unit slow update");
if (!(gs->frameNum & (UNIT_SLOWUPDATE_RATE - 1))) {
slowUpdateIterator = activeUnits.begin();
}
int n = (activeUnits.size() / UNIT_SLOWUPDATE_RATE) + 1;
for (; slowUpdateIterator != activeUnits.end() && n != 0; ++ slowUpdateIterator) {
(*slowUpdateIterator)->SlowUpdate(); n--;
}
} // for timer destruction
}