本文整理汇总了C++中CUnit::CurrentAction方法的典型用法代码示例。如果您正苦于以下问题:C++ CUnit::CurrentAction方法的具体用法?C++ CUnit::CurrentAction怎么用?C++ CUnit::CurrentAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUnit
的用法示例。
在下文中一共展示了CUnit::CurrentAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AutoAttack
/**
** Auto attack nearby units if possible
*/
bool AutoAttack(CUnit &unit)
{
if (unit.Type->CanAttack == false) {
return false;
}
// Normal units react in reaction range.
CUnit *goal = AttackUnitsInReactRange(unit);
if (goal == NULL) {
return false;
}
COrder *savedOrder = NULL;
if (unit.CurrentAction() == UnitActionStill) {
savedOrder = COrder::NewActionAttack(unit, unit.tilePos);
} else if (unit.CanStoreOrder(unit.CurrentOrder())) {
savedOrder = unit.CurrentOrder()->Clone();
}
// Weak goal, can choose other unit, come back after attack
CommandAttack(unit, goal->tilePos, NULL, FlushCommands);
if (savedOrder != NULL) {
unit.SavedOrder = savedOrder;
}
return true;
}
示例2: AutoCastSpell
/**
** Check if the spell can be auto cast and cast it.
**
** @param caster Unit who can cast the spell.
** @param spell Spell-type pointer.
**
** @return 1 if spell is casted, 0 if not.
*/
int AutoCastSpell(CUnit &caster, const SpellType &spell)
{
// Check for mana and cooldown time, trivial optimization.
if (!SpellIsAvailable(*caster.Player, spell.Slot)
|| caster.Variable[MANA_INDEX].Value < spell.ManaCost
|| caster.SpellCoolDownTimers[spell.Slot]) {
return 0;
}
Target *target = SelectTargetUnitsOfAutoCast(caster, spell);
if (target == NULL) {
return 0;
} else {
// Save previous order
COrder *savedOrder = NULL;
if (caster.CurrentAction() != UnitActionStill && caster.CanStoreOrder(caster.CurrentOrder())) {
savedOrder = caster.CurrentOrder()->Clone();
}
// Must move before ?
CommandSpellCast(caster, target->targetPos, target->Unit, spell, FlushCommands);
delete target;
if (savedOrder != NULL) {
caster.SavedOrder = savedOrder;
}
}
return 1;
}
示例3: ButtonCheckNoWork
/**
** Check for button enabled, if the unit isn't working.
** Working is training, upgrading, researching.
**
** @param unit Pointer to unit for button.
** @param button Pointer to button to check/enable.
**
** @return True if enabled.
*/
bool ButtonCheckNoWork(const CUnit &unit, const ButtonAction &)
{
int action = unit.CurrentAction();
return action != UnitActionTrain
&& action != UnitActionUpgradeTo
&& action != UnitActionResearch;
}
示例4: AutoAttack
/**
** @brief Auto attack nearby units if possible
*/
bool AutoAttack(CUnit &unit)
{
//Wyrmgus start
// if (unit.Type->CanAttack == false) {
if (unit.CanAttack() == false) {
//Wyrmgus end
return false;
}
// Normal units react in reaction range.
CUnit *goal = AttackUnitsInReactRange(unit);
if (goal == nullptr) {
return false;
}
COrder *savedOrder = nullptr;
if (unit.CurrentAction() == UnitActionStill) {
//Wyrmgus start
// savedOrder = COrder::NewActionAttack(unit, unit.tilePos);
savedOrder = COrder::NewActionAttack(unit, unit.tilePos, unit.MapLayer->ID);
//Wyrmgus end
} else if (unit.CanStoreOrder(unit.CurrentOrder())) {
savedOrder = unit.CurrentOrder()->Clone();
}
// Weak goal, can choose other unit, come back after attack
CommandAttack(unit, goal->tilePos, nullptr, FlushCommands, goal->MapLayer->ID);
if (savedOrder != nullptr) {
unit.SavedOrder = savedOrder;
}
return true;
}
示例5: ButtonCheckUpgradeTo
/**
** Check for button enabled, if all requirements for an upgrade to unit
** are met.
**
** @param unit Pointer to unit for button.
** @param button Pointer to button to check/enable.
**
** @return True if enabled.
*/
bool ButtonCheckUpgradeTo(const CUnit &unit, const ButtonAction &button)
{
if (unit.CurrentAction() != UnitActionStill) {
return false;
}
return CheckDependByIdent(*unit.Player, button.ValueStr);
}
示例6: MissileHitsGoal
/**
** Missile hits the goal.
**
** @param missile Missile hitting the goal.
** @param goal Goal of the missile.
** @param splash Splash damage divisor.
*/
static void MissileHitsGoal(const Missile &missile, CUnit &goal, int splash)
{
if (!missile.Type->CanHitOwner && missile.SourceUnit == &goal) {
return;
}
if (goal.CurrentAction() != UnitActionDie) {
int damage;
if (missile.Type->Damage) { // custom formula
Assert(missile.SourceUnit != NULL);
damage = CalculateDamage(*missile.SourceUnit, goal, missile.Type->Damage) / splash;
} else if (missile.Damage) { // direct damage, spells mostly
damage = missile.Damage / splash;
} else {
Assert(missile.SourceUnit != NULL);
damage = CalculateDamage(*missile.SourceUnit, goal, Damage) / splash;
}
if (missile.Type->Pierce) { // Handle pierce factor
for (size_t i = 0; i < (missile.PiercedUnits.size() - 1); ++i) {
damage *= (double)missile.Type->ReduceFactor / 100;
}
}
HitUnit(missile.SourceUnit, goal, damage, &missile);
}
}
示例7: RepairUnit
/**
** Repair a unit.
**
** @param unit unit repairing
** @param goal unit being repaired
**
** @return true when action is finished/canceled.
*/
bool COrder_Repair::RepairUnit(const CUnit &unit, CUnit &goal)
{
CPlayer &player = *unit.Player;
if (goal.CurrentAction() == UnitActionBuilt) {
COrder_Built &order = *static_cast<COrder_Built *>(goal.CurrentOrder());
order.ProgressHp(goal, 100 * this->RepairCycle);
this->RepairCycle = 0;
if (ResourcesMultiBuildersMultiplier && SubRepairCosts(unit, player, goal)) {
return true;
}
return false;
}
if (goal.Variable[HP_INDEX].Value >= goal.Variable[HP_INDEX].Max) {
return true;
}
Assert(goal.Stats->Variables[HP_INDEX].Max);
if (SubRepairCosts(unit, player, goal)) {
return true;
}
goal.Variable[HP_INDEX].Value += goal.Type->RepairHP;
if (goal.Variable[HP_INDEX].Value >= goal.Variable[HP_INDEX].Max) {
goal.Variable[HP_INDEX].Value = goal.Variable[HP_INDEX].Max;
return true;
}
return false;
}
示例8: CommandDismiss
/**
** Cancel the building construction, or kill a unit.
**
** @param unit pointer to unit.
*/
void CommandDismiss(CUnit &unit)
{
// Check if building is still under construction? (NETWORK!)
if (unit.CurrentAction() == UnitActionBuilt) {
unit.CurrentOrder()->Cancel(unit);
} else {
DebugPrint("Suicide unit ... \n");
LetUnitDie(unit, true);
}
ClearSavedAction(unit);
}
示例9: CommandCancelResearch
/**
** Cancel Building researching.
**
** @param unit Pointer to unit.
*/
void CommandCancelResearch(CUnit &unit)
{
// Check if unit is still researching? (NETWORK!)
if (unit.CurrentAction() == UnitActionResearch) {
unit.CurrentOrder()->Cancel(unit);
RemoveOrder(unit, 0);
if (!Selected.empty()) {
SelectedUnitChanged();
}
}
ClearSavedAction(unit);
}
示例10: DrawInformations
/**
** Draw additional informations of a unit.
**
** @param unit Unit pointer of drawn unit.
** @param type Unit-type pointer.
** @param screenPos screen pixel (top left) position of unit.
**
** @todo FIXME: The different styles should become a function call.
*/
static void DrawInformations(const CUnit &unit, const CUnitType &type, const PixelPos &screenPos)
{
#if 0 && DEBUG // This is for showing vis counts and refs.
char buf[10];
sprintf(buf, "%d%c%c%d", unit.VisCount[ThisPlayer->Index],
unit.Seen.ByPlayer & (1 << ThisPlayer->Index) ? 'Y' : 'N',
unit.Seen.Destroyed & (1 << ThisPlayer->Index) ? 'Y' : 'N',
unit.Refs);
CLabel(GetSmallFont()).Draw(screenPos.x + 10, screenPos.y + 10, buf);
#endif
const CUnitStats &stats = *unit.Stats;
// For debug draw sight, react and attack range!
if (IsOnlySelected(unit)) {
const PixelPos center(screenPos + type.GetPixelSize() / 2);
if (Preference.ShowSightRange) {
const int value = stats.Variables[SIGHTRANGE_INDEX].Max;
const int radius = value * PixelTileSize.x + (type.TileWidth - 1) * PixelTileSize.x / 2;
if (value) {
// Radius -1 so you can see all ranges
Video.DrawCircleClip(ColorGreen, center.x, center.y, radius - 1);
}
}
if (type.CanAttack) {
if (Preference.ShowReactionRange) {
const int value = (unit.Player->Type == PlayerPerson) ? type.ReactRangePerson : type.ReactRangeComputer;
const int radius = value * PixelTileSize.x + (type.TileWidth - 1) * PixelTileSize.x / 2;
if (value) {
Video.DrawCircleClip(ColorBlue, center.x, center.y, radius);
}
}
if (Preference.ShowAttackRange) {
const int value = stats.Variables[ATTACKRANGE_INDEX].Max;
const int radius = value * PixelTileSize.x + (type.TileWidth - 1) * PixelTileSize.x / 2;
if (value) {
// Radius +1 so you can see all ranges
Video.DrawCircleClip(ColorGreen, center.x, center.y, radius - 1);
}
}
}
}
// FIXME: johns: ugly check here, should be removed!
if (unit.CurrentAction() != UnitActionDie && (unit.IsVisible(*ThisPlayer) || ReplayRevealMap)) {
DrawDecoration(unit, type, screenPos);
}
}
示例11: IsReadyToRepair
static bool IsReadyToRepair(const CUnit &unit)
{
if (unit.IsIdle()) {
return true;
} else if (unit.Orders.size() == 1 && unit.CurrentAction() == UnitActionResource) {
COrder_Resource &order = *static_cast<COrder_Resource *>(unit.CurrentOrder());
if (order.IsGatheringStarted() == false) {
return true;
}
}
return false;
}
示例12: MissileHitsGoal
/**
** Missile hits the goal.
**
** @param missile Missile hitting the goal.
** @param goal Goal of the missile.
** @param splash Splash damage divisor.
*/
static void MissileHitsGoal(const Missile &missile, CUnit &goal, int splash)
{
if (!missile.Type->CanHitOwner && missile.SourceUnit == &goal) {
return;
}
//Wyrmgus start
if (CalculateHit(*missile.SourceUnit, *goal.Stats, &goal) == false) {
if (splash == 1 && missile.Type->SplashFactor == 0) {
return;
} else if (splash == 1 && missile.Type->SplashFactor > 0) {
splash = missile.Type->SplashFactor; // if missile has splash factor but missed, apply splash damage
}
}
//Wyrmgus end
if (goal.CurrentAction() != UnitActionDie) {
int damage;
if (missile.Type->Damage) { // custom formula
Assert(missile.SourceUnit != NULL);
damage = CalculateDamage(*missile.SourceUnit, goal, missile.Type->Damage) / splash;
} else if (missile.Damage) { // direct damage, spells mostly
damage = missile.Damage / splash;
} else {
Assert(missile.SourceUnit != NULL);
damage = CalculateDamage(*missile.SourceUnit, goal, Damage) / splash;
}
if (missile.Type->Pierce) { // Handle pierce factor
for (size_t i = 0; i < (missile.PiercedUnits.size() - 1); ++i) {
damage *= (double)missile.Type->ReduceFactor / 100;
}
}
HitUnit(missile.SourceUnit, goal, damage, &missile);
//Wyrmgus start
//apply Thorns damage if attacker is at melee range
if (&goal && goal.Variable[THORNSDAMAGE_INDEX].Value && missile.SourceUnit->MapDistanceTo(goal) <= 1) {
int thorns_damage = std::max<int>(goal.Variable[THORNSDAMAGE_INDEX].Value - missile.SourceUnit->Variable[ARMOR_INDEX].Value, 1);
if (GameSettings.NoRandomness) {
thorns_damage -= ((thorns_damage + 2) / 2) / 2; //if no randomness setting is used, then the damage will always return what would have been the average damage with randomness
} else {
thorns_damage -= SyncRand() % ((thorns_damage + 2) / 2);
}
HitUnit(&goal, *missile.SourceUnit, thorns_damage);
}
//Wyrmgus end
}
}
示例13: MoveToDropZone
/**
** Move to dropzone.
**
** @param unit Pointer to unit.
**
** @return -1 if unreachable, True if reached, False otherwise.
*/
static int MoveToDropZone(CUnit &unit)
{
switch (DoActionMove(unit)) { // reached end-point?
case PF_UNREACHABLE:
return PF_UNREACHABLE;
case PF_REACHED:
break;
default:
return 0;
}
Assert(unit.CurrentAction() == UnitActionUnload);
return 1;
}
示例14: GetNumWaitingWorkers
int GetNumWaitingWorkers(const CUnit &mine)
{
int ret = 0;
CUnit *worker = mine.Resource.Workers;
for (int i = 0; NULL != worker; worker = worker->NextWorker, ++i) {
Assert(worker->CurrentAction() == UnitActionResource);
COrder_Resource &order = *static_cast<COrder_Resource *>(worker->CurrentOrder());
if (order.IsGatheringWaiting()) {
ret++;
}
Assert(i <= mine.Resource.Assigned);
}
return ret;
}
示例15: AiAssignHarvester
/**
** Assign worker to gather a certain resource.
**
** @param unit pointer to the unit.
** @param resource resource identification.
**
** @return 1 if the worker was assigned, 0 otherwise.
*/
static int AiAssignHarvester(CUnit &unit, int resource)
{
// It can't.
//Wyrmgus start
// if (unit.Removed) {
if (unit.Removed || unit.CurrentAction() == UnitActionBuild) { //prevent units building from outside to being assigned to gather a resource, and then leaving the construction unbuilt forever and ever
//Wyrmgus end
return 0;
}
if (std::find(AiPlayer->Scouts.begin(), AiPlayer->Scouts.end(), &unit) != AiPlayer->Scouts.end()) { //if a scouting unit was assigned to harvest, remove it from the scouts vector
AiPlayer->Scouts.erase(std::remove(AiPlayer->Scouts.begin(), AiPlayer->Scouts.end(), &unit), AiPlayer->Scouts.end());
}
const ResourceInfo &resinfo = *unit.Type->ResInfo[resource];
Assert(&resinfo);
//Wyrmgus start
/*
if (resinfo.TerrainHarvester) {
return AiAssignHarvesterFromTerrain(unit, resource);
} else {
return AiAssignHarvesterFromUnit(unit, resource);
}
*/
int ret = 0;
int resource_range = 0;
for (int i = 0; i < 3; ++i) { //search for resources first in a 16 tile radius, then in a 32 tile radius, and then in the whole map
resource_range += 16;
if (i == 2) {
resource_range = 1000;
}
ret = AiAssignHarvesterFromUnit(unit, resource, resource_range);
if (ret == 0) {
ret = AiAssignHarvesterFromTerrain(unit, resource, resource_range);
}
if (ret != 0) {
return ret;
}
}
return ret;
//Wyrmgus end
}