本文整理汇总了C++中CUnit::GetAnimations方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnit::GetAnimations方法的具体用法?C++ CUnit::GetAnimations怎么用?C++ CUnit::GetAnimations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnit
的用法示例。
在下文中一共展示了CUnit::GetAnimations方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AnimateActionHarvest
/**
** Animate a unit that is harvesting
**
** @param unit Unit to animate
*/
static void AnimateActionHarvest(CUnit &unit)
{
//Wyrmgus start
// Assert(unit.Type->Animations->Harvest[unit.CurrentResource]);
// UnitShowAnimation(unit, unit.Type->Animations->Harvest[unit.CurrentResource]);
Assert(unit.GetAnimations()->Harvest[unit.CurrentResource]);
UnitShowAnimation(unit, unit.GetAnimations()->Harvest[unit.CurrentResource]);
//Wyrmgus end
}
示例2:
/**
** Research upgrade.
**
** @return true when finished.
*/
/* virtual */ void COrder_Research::Execute(CUnit &unit)
{
const CUpgrade &upgrade = this->GetUpgrade();
const CUnitType &type = *unit.Type;
//Wyrmgus start
// UnitShowAnimation(unit, type.Animations->Research ? type.Animations->Research : type.Animations->Still);
UnitShowAnimation(unit, unit.GetAnimations()->Research ? unit.GetAnimations()->Research : unit.GetAnimations()->Still);
//Wyrmgus end
if (unit.Wait) {
unit.Wait--;
return ;
}
#if 0
if (unit.Anim.Unbreakable) {
return ;
}
#endif
//Wyrmgus start
// CPlayer &player = *unit.Player;
CPlayer &player = Players[this->Player];
// player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, player.SpeedResearch / SPEEDUP_FACTOR);
player.UpgradeTimers.Upgrades[upgrade.ID] += std::max(1, (player.SpeedResearch + unit.Variable[TIMEEFFICIENCYBONUS_INDEX].Value + unit.Variable[RESEARCHSPEEDBONUS_INDEX].Value) / SPEEDUP_FACTOR);
//Wyrmgus end
if (player.UpgradeTimers.Upgrades[upgrade.ID] >= upgrade.Costs[TimeCost]) {
if (upgrade.Name.empty()) {
//Wyrmgus start
// player.Notify(NotifyGreen, unit.tilePos, _("%s: research complete"), type.Name.c_str());
player.Notify(NotifyGreen, unit.tilePos, unit.MapLayer->ID, _("%s: research complete"), type.GetDefaultName(player).c_str());
//Wyrmgus end
} else {
player.Notify(NotifyGreen, unit.tilePos, unit.MapLayer->ID, _("%s: research complete"), upgrade.Name.c_str());
}
if (&player == ThisPlayer) {
//Wyrmgus start
// CSound *sound = GameSounds.ResearchComplete[player.Race].Sound;
CSound *sound = GameSounds.ResearchComplete[unit.Player->Race].Sound;
//Wyrmgus end
if (sound) {
PlayGameSound(sound, MaxSampleVolume);
}
}
if (player.AiEnabled) {
AiResearchComplete(unit, &upgrade);
}
UpgradeAcquire(player, &upgrade);
this->Finished = true;
return ;
}
unit.Wait = CYCLES_PER_SECOND / 6;
}
示例3: AutoRepair
/* virtual */ void COrder_Still::Execute(CUnit &unit)
{
// If unit is not bunkered and removed, wait
if (unit.Removed
//Wyrmgus start
// && (unit.Container == nullptr || unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value == false)) {
&& (unit.Container == nullptr || !unit.Container->Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value || !unit.Type->BoolFlag[ATTACKFROMTRANSPORTER_INDEX].value)) { // make both the unit and the transporter have the tag be necessary for the attack to be possible
if (unit.Container != nullptr) {
LeaveShelter(unit); // leave shelter if surrounded
}
//Wyrmgus end
return ;
}
this->Finished = false;
switch (this->State) {
case SUB_STILL_STANDBY:
//Wyrmgus start
// UnitShowAnimation(unit, unit.Type->Animations->Still);
if (unit.Variable[STUN_INDEX].Value == 0) { //only show the idle animation when still if the unit is not stunned
UnitShowAnimation(unit, unit.GetAnimations()->Still);
}
if (SyncRand(100000) == 0) {
PlayUnitSound(unit, VoiceIdle);
}
unit.StepCount = 0;
//Wyrmgus end
break;
case SUB_STILL_ATTACK: // attacking unit in attack range.
AnimateActionAttack(unit, *this);
break;
}
if (unit.Anim.Unbreakable) { // animation can't be aborted here
return;
}
//Wyrmgus start
if (unit.Variable[STUN_INDEX].Value > 0) { //if unit is stunned, remain still
return;
}
//Wyrmgus end
this->State = SUB_STILL_STANDBY;
this->Finished = (this->Action == UnitActionStill);
if (this->Action == UnitActionStandGround || unit.Removed || unit.CanMove() == false) {
if (unit.AutoCastSpell) {
this->AutoCastStand(unit);
}
if (unit.IsAgressive()) {
this->AutoAttackStand(unit);
}
} else {
if (AutoCast(unit) || (unit.IsAgressive() && AutoAttack(unit))
|| AutoRepair(unit)
//Wyrmgus start
// || MoveRandomly(unit)) {
|| MoveRandomly(unit) || PickUpItem(unit)) {
//Wyrmgus end
}
}
}
示例4: AnimateActionUpgradeTo
static void AnimateActionUpgradeTo(CUnit &unit)
{
//Wyrmgus start
// CAnimations &animations = *unit.Type->Animations;
// UnitShowAnimation(unit, animations.Upgrade ? animations.Upgrade : animations.Still);
CAnimations &animations = *unit.GetAnimations();
UnitShowAnimation(unit, animations.Upgrade ? animations.Upgrade : animations.Still);
//Wyrmgus end
}
示例5: AnimateActionDie
static bool AnimateActionDie(CUnit &unit)
{
//Wyrmgus start
// const CAnimations *animations = unit.Type->Animations;
const CAnimations *animations = unit.GetAnimations();
//Wyrmgus end
if (animations == NULL) {
return false;
}
if (animations->Death[unit.DamagedType]) {
UnitShowAnimation(unit, animations->Death[unit.DamagedType]);
return true;
} else if (animations->Death[ANIMATIONS_DEATHTYPES]) {
UnitShowAnimation(unit, animations->Death[ANIMATIONS_DEATHTYPES]);
return true;
}
return false;
}
示例6: AttackUnitsInReactRange
/* virtual */ void COrder_Follow::Execute(CUnit &unit)
{
if (unit.Wait) {
if (!unit.Waiting) {
unit.Waiting = 1;
unit.WaitBackup = unit.Anim;
}
//Wyrmgus start
// UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, unit.GetAnimations()->Still);
//Wyrmgus end
unit.Wait--;
return;
}
if (unit.Waiting) {
unit.Anim = unit.WaitBackup;
unit.Waiting = 0;
}
CUnit *goal = this->GetGoal();
// Reached target
if (this->State == State_TargetReached) {
if (!goal || !goal->IsVisibleAsGoal(*unit.Player)) {
DebugPrint("Goal gone\n");
this->Finished = true;
return ;
}
// Don't follow after immobile units
if (goal && goal->CanMove() == false) {
this->Finished = true;
return;
}
//Wyrmgus start
// if (goal->tilePos == this->goalPos) {
if (goal->tilePos == this->goalPos && goal->MapLayer == this->MapLayer) {
//Wyrmgus end
// Move to the next order
if (unit.Orders.size() > 1) {
this->Finished = true;
return ;
}
unit.Wait = 10;
if (this->Range > 1) {
this->Range = 1;
this->State = State_Init;
}
return ;
}
this->State = State_Init;
}
if (this->State == State_Init) { // first entry
this->State = State_Initialized;
}
switch (DoActionMove(unit)) { // reached end-point?
case PF_UNREACHABLE:
//Wyrmgus start
if ((Map.Field(unit.tilePos, unit.MapLayer)->Flags & MapFieldBridge) && !unit.Type->BoolFlag[BRIDGE_INDEX].value && unit.Type->UnitType == UnitTypeLand) {
std::vector<CUnit *> table;
Select(unit.tilePos, unit.tilePos, table, unit.MapLayer);
for (size_t i = 0; i != table.size(); ++i) {
if (!table[i]->Removed && table[i]->Type->BoolFlag[BRIDGE_INDEX].value && table[i]->CanMove()) {
if (table[i]->CurrentAction() == UnitActionStill) {
CommandStopUnit(*table[i]);
CommandMove(*table[i], this->HasGoal() ? this->GetGoal()->tilePos : this->goalPos, FlushCommands, this->HasGoal() ? this->GetGoal()->MapLayer : this->MapLayer);
}
return;
}
}
}
//Wyrmgus end
// Some tries to reach the goal
this->Range++;
break;
case PF_REACHED: {
if (!goal) { // goal has died
this->Finished = true;
return ;
}
// Handle Teleporter Units
// FIXME: BAD HACK
// goal shouldn't be busy and portal should be alive
if (goal->Type->BoolFlag[TELEPORTER_INDEX].value && goal->Goal && goal->Goal->IsAlive() && unit.MapDistanceTo(*goal) <= 1) {
if (!goal->IsIdle()) { // wait
unit.Wait = 10;
return;
}
// Check if we have enough mana
if (goal->Goal->Type->TeleportCost > goal->Variable[MANA_INDEX].Value) {
this->Finished = true;
return;
} else {
goal->Variable[MANA_INDEX].Value -= goal->Goal->Type->TeleportCost;
}
// Everything is OK, now teleport the unit
unit.Remove(NULL);
if (goal->Type->TeleportEffectIn) {
//.........这里部分代码省略.........
示例7: if
/* virtual */ void COrder_Defend::Execute(CUnit &unit)
{
if (unit.Wait) {
if (!unit.Waiting) {
unit.Waiting = 1;
unit.WaitBackup = unit.Anim;
}
//Wyrmgus start
// UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, unit.GetAnimations()->Still);
//Wyrmgus end
unit.Wait--;
return;
}
if (unit.Waiting) {
unit.Anim = unit.WaitBackup;
unit.Waiting = 0;
}
CUnit *goal = this->GetGoal();
if (this->State == State_Init) {
if (!goal || !goal->IsVisibleAsGoal(*unit.Player)) {
this->Finished = true;
return;
}
this->State = State_MovingToTarget;
} else if (this->State == State_Defending) {
if (!goal || !goal->IsVisibleAsGoal(*unit.Player)) {
this->Finished = true;
return;
}
}
if (!unit.Anim.Unbreakable) {
if (AutoCast(unit) || AutoAttack(unit) || AutoRepair(unit)) {
return;
}
}
switch (DoActionMove(unit)) {
case PF_UNREACHABLE:
//Wyrmgus start
//if is unreachable and is on a raft, see if the raft can move closer to the enemy
if ((Map.Field(unit.tilePos)->Flags & MapFieldBridge) && !unit.Type->BoolFlag[BRIDGE_INDEX].value && unit.Type->UnitType == UnitTypeLand) {
std::vector<CUnit *> table;
Select(unit.tilePos, unit.tilePos, table);
for (size_t i = 0; i != table.size(); ++i) {
if (!table[i]->Removed && table[i]->Type->BoolFlag[BRIDGE_INDEX].value && table[i]->CanMove()) {
if (table[i]->CurrentAction() == UnitActionStill) {
CommandStopUnit(*table[i]);
CommandMove(*table[i], this->HasGoal() ? this->GetGoal()->tilePos : this->goalPos, FlushCommands);
}
return;
}
}
}
//Wyrmgus end
// Some tries to reach the goal
this->Range++;
break;
case PF_REACHED: {
if (!goal || !goal->IsVisibleAsGoal(*unit.Player)) { // goal has died
this->Finished = true;
return;
}
// Now defend the goal
this->goalPos = goal->tilePos;
this->State = State_Defending;
}
default:
break;
}
// Target destroyed?
if (goal && !goal->IsVisibleAsGoal(*unit.Player)) {
DebugPrint("Goal gone\n");
this->goalPos = goal->tilePos + goal->Type->GetHalfTileSize();
this->ClearGoal();
goal = NULL;
if (this->State == State_Defending) {
this->Finished = true;
return;
}
}
}
示例8: Execute
/**
** Control the unit action: getting a resource.
**
** This the generic function for oil, gold, ...
**
** @param unit Pointer to unit.
*/
void COrder_Resource::Execute(CUnit &unit)
{
// can be different by Cloning (trained unit)...
this->worker = &unit;
if (unit.Wait) {
if (!unit.Waiting) {
unit.Waiting = 1;
unit.WaitBackup = unit.Anim;
}
//Wyrmgus start
// UnitShowAnimation(unit, unit.Type->Animations->Still);
UnitShowAnimation(unit, unit.GetAnimations()->Still);
//Wyrmgus end
unit.Wait--;
return;
}
if (unit.Waiting) {
unit.Anim = unit.WaitBackup;
unit.Waiting = 0;
}
// Let's start mining.
if (this->State == SUB_START_RESOURCE) {
if (ActionResourceInit(unit) == false) {
ResourceGiveUp(unit);
return;
}
}
// Move to the resource location.
if (SUB_MOVE_TO_RESOURCE <= this->State && this->State < SUB_UNREACHABLE_RESOURCE) {
const int ret = MoveToResource(unit);
switch (ret) {
case -1: { // Can't Reach
this->State++;
unit.Wait = 5;
return;
}
case 1: { // Reached
this->State = SUB_START_GATHERING;
break;
}
case 0: // Move along.
return;
default: {
Assert(0);
break;
}
}
}
// Resource seems to be unreachable
if (this->State == SUB_UNREACHABLE_RESOURCE) {
if (this->FindAnotherResource(unit) == false) {
ResourceGiveUp(unit);
return;
}
}
// Start gathering the resource
if (this->State == SUB_START_GATHERING) {
if (StartGathering(unit)) {
this->State = SUB_GATHER_RESOURCE;
} else {
return;
}
}
// Gather the resource.
if (this->State == SUB_GATHER_RESOURCE) {
if (GatherResource(unit)) {
this->State = SUB_STOP_GATHERING;
} else {
return;
}
}
// Stop gathering the resource.
if (this->State == SUB_STOP_GATHERING) {
if (StopGathering(unit)) {
this->State = SUB_MOVE_TO_DEPOT;
unit.pathFinderData->output.Cycles = 0; //moving counter
} else {
return;
}
}
// Move back home.
if (SUB_MOVE_TO_DEPOT <= this->State && this->State < SUB_UNREACHABLE_DEPOT) {
const int ret = MoveToDepot(unit);
//.........这里部分代码省略.........