____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "unittype.h"
#include "player.h"
#include "unit.h"
#include "actions.h"
#include "map.h"
#include "upgrade.h"
#include "pathfinder.h"
#include "spells.h"
#include "interface.h"
#include "ui.h"
Go to the source code of this file.
Functions | |
| static void | ReleaseOrder (COrder *order) |
| static void | ReleaseOrders (CUnit *unit) |
| static COrder * | GetNextOrder (CUnit *unit, int flush) |
| static void | RemoveOrder (CUnit *unit, int order) |
| static void | ClearSavedAction (CUnit *unit) |
| void | CommandStopUnit (CUnit *unit) |
| Prepare command stand ground. | |
| void | CommandAnyOrder (CUnit *unit, COrder *cpyorder, int flush) |
| Move an order in command queue. | |
| void | CommandMoveOrder (CUnit *unit, int src, int dst) |
| void | CommandStandGround (CUnit *unit, int flush) |
| Prepare command follow. | |
| void | CommandFollow (CUnit *unit, CUnit *dest, int flush) |
| Prepare command move. | |
| void | CommandMove (CUnit *unit, int x, int y, int flush) |
| Prepare command repair. | |
| void | CommandRepair (CUnit *unit, int x, int y, CUnit *dest, int flush) |
| Send auto repair command. | |
| void | CommandAutoRepair (CUnit *unit, int on) |
| Prepare command attack. | |
| void | CommandAttack (CUnit *unit, int x, int y, CUnit *attack, int flush) |
| Prepare command attack ground. | |
| void | CommandAttackGround (CUnit *unit, int x, int y, int flush) |
| Prepare command patrol. | |
| void | CommandPatrolUnit (CUnit *unit, int x, int y, int flush) |
| Prepare command board. | |
| void | CommandBoard (CUnit *unit, CUnit *dest, int flush) |
| Prepare command unload. | |
| void | CommandUnload (CUnit *unit, int x, int y, CUnit *what, int flush) |
| Prepare command build. | |
| void | CommandBuildBuilding (CUnit *unit, int x, int y, CUnitType *what, int flush) |
| Prepare command dismiss. | |
| void | CommandDismiss (CUnit *unit) |
| Prepare command resource. | |
| void | CommandResource (CUnit *unit, CUnit *dest, int flush) |
| Prepare command train. | |
| void | CommandTrainUnit (CUnit *unit, CUnitType *type, int flush) |
| Prepare command cancel training. | |
| void | CommandCancelTraining (CUnit *unit, int slot, const CUnitType *type) |
| Prepare command spellcast. | |
| void | CommandSpellCast (CUnit *unit, int x, int y, CUnit *dest, SpellType *spell, int flush) |
| Prepare command auto spellcast. | |
| void | CommandAutoSpellCast (CUnit *unit, int spellid, int on) |
| Prepare diplomacy command. | |
| void | CommandDiplomacy (int player, int state, int opponent) |
| Prepare shared vision command. | |
| void | CommandSharedVision (int player, bool state, int opponent) |
| Send any command. | |
| void | CommandQuit (int player) |
| < Prepare command quit | |
Definition in file command.cpp.
| static void ClearSavedAction | ( | CUnit * | unit | ) | [static] |
Clear the saved action.
| unit | Unit pointer, that get the saved action cleared. |
Internal functions, must protect it, if needed.
Definition at line 154 of file command.cpp.
References COrder::Action, COrder::Init(), ReleaseOrder(), CUnit::SavedOrder, and UnitActionStill.
Referenced by CommandAnyOrder(), CommandAttack(), CommandAttackGround(), CommandBoard(), CommandBuildBuilding(), CommandCancelTraining(), CommandDismiss(), CommandFollow(), CommandMove(), CommandPatrolUnit(), CommandRepair(), CommandResource(), CommandSpellCast(), CommandStandGround(), CommandTrainUnit(), and CommandUnload().
Move an order in command queue.
Order an already formed Order structure
| unit | pointer to unit | |
| cpyorder | pointer to valid order | |
| flush | if true, flush command queue. |
Definition at line 194 of file command.cpp.
References ClearSavedAction(), GetNextOrder(), COrder::Goal, and CUnit::RefsIncrease().
Prepare command attack ground.
Attack with unit at new position
| unit | pointer to unit. | |
| x | X map position to attack. | |
| y | Y map position to attack. | |
| attack | or unit to be attacked. | |
| flush | if true, flush command queue. |
Definition at line 418 of file command.cpp.
References COrder::Action, Assert, ATTACKRANGE_INDEX, CUnitType::CanAttack, ClearSavedAction(), CUnit::Destroyed, GetNextOrder(), COrder::Goal, CMap::Info, COrder::Init(), Map, CMapInfo::MapHeight, CMapInfo::MapWidth, CVariable::Max, CUnitType::MinAttackRange, COrder::MinRange, CUnit::NewOrder, CUnit::Orders, COrder::Range, CUnit::RefsIncrease(), ReleaseOrder(), CUnit::Removed, CUnit::Stats, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitActionAttack, UnitActionDie, CUnitStats::Variables, CUnit::X, COrder::X, CUnit::Y, and COrder::Y.
Referenced by AiAttackWithForce(), AiAttackWithForceAt(), AiForceAttacks(), AutoAttack(), CclOrderUnit(), HandleActionFollow(), HandleActionPatrol(), HitUnit(), ParseCommand(), and SendCommandAttack().
| void CommandAttackGround | ( | CUnit * | unit, | |
| int | x, | |||
| int | y, | |||
| int | flush | |||
| ) |
Prepare command patrol.
Attack ground with unit.
| unit | pointer to unit. | |
| x | X map position to fire on. | |
| y | Y map position to fire on. | |
| flush | if true, flush command queue. |
Definition at line 470 of file command.cpp.
References COrder::Action, Assert, ATTACKRANGE_INDEX, CUnitType::Building, ClearSavedAction(), DebugPrint, GetNextOrder(), CMap::Info, COrder::Init(), Map, CMapInfo::MapHeight, CMapInfo::MapWidth, CVariable::Max, CUnitType::MinAttackRange, COrder::MinRange, CUnit::NewOrder, CUnit::Orders, COrder::Range, ReleaseOrder(), CUnit::Removed, CUnit::Stats, CUnit::Type, UnitActionAttackGround, UnitActionDie, CUnitStats::Variables, COrder::X, and COrder::Y.
Referenced by ParseCommand(), and SendCommandAttackGround().
| void CommandAutoRepair | ( | CUnit * | unit, | |
| int | on | |||
| ) |
Prepare command attack.
Auto repair.
| unit | pointer to unit. | |
| on | 1 for auto repair on, 0 for off. |
Definition at line 399 of file command.cpp.
References CUnit::AutoRepair, CUnit::Orders, CUnit::Removed, and UnitActionDie.
Referenced by ParseCommand(), and SendCommandAutoRepair().
| void CommandAutoSpellCast | ( | CUnit * | unit, | |
| int | spellid, | |||
| int | on | |||
| ) |
Prepare diplomacy command.
Auto spell cast.
| unit | pointer to unit. | |
| spellid | Spell id. | |
| on | 1 for auto cast on, 0 for off. |
Definition at line 887 of file command.cpp.
References CUnit::AutoCastSpell, CUnit::Orders, CUnit::Removed, and UnitActionDie.
Referenced by ParseCommand(), and SendCommandAutoSpellCast().
Prepare command unload.
Board a transporter with unit.
| unit | pointer to unit. | |
| dest | unit to be boarded. | |
| flush | if true, flush command queue. |
Definition at line 546 of file command.cpp.
References COrder::Action, CUnitType::Building, ClearSavedAction(), CUnit::Destroyed, GetNextOrder(), COrder::Goal, COrder::Init(), CUnit::NewOrder, CUnit::Orders, COrder::Range, CUnit::RefsIncrease(), ReleaseOrder(), CUnit::Removed, CUnit::Type, UnitActionBoard, and UnitActionDie.
Referenced by ParseCommand(), and SendCommandBoard().
Prepare command dismiss.
Send a unit building
| unit | pointer to unit. | |
| x | X map position to build. | |
| y | Y map position to build. | |
| what | Unit type to build. | |
| flush | if true, flush command queue. |
Definition at line 627 of file command.cpp.
References COrder::Action, CUnitType::BuilderOutside, CUnitType::Building, ClearSavedAction(), GetNextOrder(), COrder::Height, COrder::Init(), COrder::MinRange, CUnit::NewOrder, CUnit::Orders, COrder::Range, ReleaseOrder(), CUnit::Removed, CUnitType::RepairRange, CUnitType::ShoreBuilding, CUnitType::TileHeight, CUnitType::TileWidth, COrder::Type, CUnit::Type, UnitActionBuild, UnitActionDie, CUnitType::UnitType, UnitTypeLand, COrder::Width, COrder::X, and COrder::Y.
Referenced by AiBuildBuilding(), ParseCommand(), and SendCommandBuildBuilding().
Prepare command spellcast.
Cancel the training of a unit.
| unit | pointer to unit. | |
| slot | slot number to cancel. | |
| type | Unit-type to cancel. |
Definition at line 766 of file command.cpp.
References _C_, ClearSavedAction(), CUnit::Data, DebugPrint, CUnitType::Ident, CUnit::OrderCount, CUnit::Orders, CUnit::Player, CPlayer::RemoveFromUnitsConsumingResources(), RemoveOrder(), CUnit::Selected, SelectedUnitChanged(), ThisPlayer, CUnit::_order_data_::_order_train_::Ticks, CUnit::_order_data_::Train, and UnitActionTrain.
Referenced by ParseCommand(), and SendCommandCancelTraining().
| void CommandDiplomacy | ( | int | player, | |
| int | state, | |||
| int | opponent | |||
| ) |
Prepare shared vision command.
Diplomacy changed.
| player | Player which changes his state. | |
| state | New diplomacy state. | |
| opponent | Opponent. |
Definition at line 904 of file command.cpp.
References CPlayer::Allied, DiplomacyAllied, DiplomacyCrazy, DiplomacyEnemy, DiplomacyNeutral, CPlayer::Enemy, and Players.
Referenced by GameTypeFreeForAll(), GameTypeLeftVsRight(), GameTypeManTeamVsMachine(), GameTypeManVsMachine(), GameTypeTopVsBottom(), ParseExtendedCommand(), and SendCommandDiplomacy().
| void CommandDismiss | ( | CUnit * | unit | ) |
Prepare command resource.
Cancel the building construction, or kill a unit.
| unit | pointer to unit. |
Definition at line 672 of file command.cpp.
References CUnit::_order_data_::Built, CUnit::_order_data_::_order_built_::Cancel, ClearSavedAction(), CUnit::Data, DebugPrint, LetUnitDie(), CUnit::Orders, and UnitActionBuilt.
Referenced by ParseCommand(), and SendCommandDismiss().
Prepare command move.
Follow unit to new position
| unit | pointer to unit. | |
| dest | unit to be followed | |
| flush | if true, flush command queue. |
Definition at line 275 of file command.cpp.
References COrder::Action, CanMove(), ClearSavedAction(), CUnit::Destroyed, GetNextOrder(), COrder::Goal, COrder::Init(), CUnit::NewOrder, CUnit::Orders, COrder::Range, CUnit::RefsIncrease(), ReleaseOrder(), CUnit::Removed, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitActionDie, UnitActionFollow, CUnit::X, COrder::X, CUnit::Y, and COrder::Y.
Referenced by ParseCommand(), and SendCommandFollow().
| void CommandMove | ( | CUnit * | unit, | |
| int | x, | |||
| int | y, | |||
| int | flush | |||
| ) |
Prepare command repair.
Move unit to new position
| unit | pointer to unit. | |
| x | X map position to move to. | |
| y | Y map position to move to. | |
| flush | if true, flush command queue. |
Definition at line 318 of file command.cpp.
References COrder::Action, Assert, CanMove(), ClearSavedAction(), GetNextOrder(), CMap::Info, COrder::Init(), Map, CMapInfo::MapHeight, CMapInfo::MapWidth, CUnit::NewOrder, CUnit::Orders, ReleaseOrder(), CUnit::Removed, UnitActionDie, UnitActionMove, COrder::X, and COrder::Y.
Referenced by AiAttackWithForce(), AiAttackWithForceAt(), AiForceAttacks(), AiMoveUnitInTheWay(), AiSendExplorers(), CclOrderUnit(), HitUnit(), ParseCommand(), and SendCommandMove().
| void CommandMoveOrder | ( | CUnit * | unit, | |
| int | src, | |||
| int | dst | |||
| ) |
Move an order in the order queue. ( Cannot move the order 0 ! )
| unit | pointer to unit | |
| src | the order to move | |
| dst | the new position of the order |
Definition at line 217 of file command.cpp.
References Assert, and CUnit::Orders.
| void CommandPatrolUnit | ( | CUnit * | unit, | |
| int | x, | |||
| int | y, | |||
| int | flush | |||
| ) |
Prepare command board.
Let a unit patrol from current to new position
FIXME: want to support patroling between units.
| unit | pointer to unit. | |
| x | X map position to patrol between. | |
| y | Y map position to patrol between. | |
| flush | if true, flush command queue. |
Definition at line 510 of file command.cpp.
References COrder::Action, COrder::Arg1, Assert, CanMove(), ClearSavedAction(), GetNextOrder(), CMap::Info, COrder::Init(), Map, CMapInfo::MapHeight, CMapInfo::MapWidth, CUnit::NewOrder, CUnit::Orders, COrder::Patrol, ReleaseOrder(), CUnit::Removed, UnitActionDie, UnitActionPatrol, CUnit::X, COrder::X, CUnit::Y, and COrder::Y.
Referenced by CclOrderUnit(), ParseCommand(), and SendCommandPatrol().
| void CommandQuit | ( | int | player | ) |
< Prepare command quit
Player quit.
| player | Player number that quit. |
Definition at line 995 of file command.cpp.
References _, CPlayer::Allied, ChangeTeamSelectedUnits(), CommandSharedVision(), CPlayer::Enemy, NumPlayers, PlayerNeutral, Players, SetMessage(), and CPlayer::Type.
Referenced by DoNextReplay(), and ParseNetworkCommand().
Send auto repair command.
Repair unit
| unit | pointer to unit. | |
| x | X map position to repair. | |
| y | Y map position to repair. | |
| dest | or unit to be repaired. FIXME: not supported | |
| flush | if true, flush command queue. |
Definition at line 353 of file command.cpp.
References COrder::Action, CUnitType::Building, ClearSavedAction(), CUnit::Destroyed, GetNextOrder(), COrder::Goal, COrder::Init(), CUnit::NewOrder, CUnit::Orders, COrder::Range, CUnit::RefsIncrease(), ReleaseOrder(), CUnit::Removed, CUnitType::RepairRange, CUnitType::TileHeight, CUnitType::TileWidth, CUnit::Type, UnitActionDie, UnitActionRepair, CUnit::X, COrder::X, CUnit::Y, and COrder::Y.
Referenced by AiRepairBuilding(), AutoRepair(), ParseCommand(), and SendCommandRepair().
Prepare command train.
Send unit to harvest resources
| unit | pointer to unit. | |
| dest | destination unit. | |
| flush | if true, flush command queue. |
Definition at line 693 of file command.cpp.
References COrder::Action, CUnitType::Building, ClearSavedAction(), CUnit::Destroyed, GetNextOrder(), COrder::Goal, CUnitType::Harvester, COrder::Init(), CUnit::NewOrder, CUnit::Orders, COrder::Range, CUnit::RefsIncrease(), ReleaseOrder(), CUnit::Removed, CUnit::Type, UnitActionDie, and UnitActionResource.
Referenced by AiAssignHarvester(), HandleActionBuilt(), ParseCommand(), and SendCommandResource().
| void CommandSharedVision | ( | int | player, | |
| bool | state, | |||
| int | opponent | |||
| ) |
Send any command.
Shared vision changed.
| player | Player which changes his state. | |
| state | New shared vision state. | |
| opponent | Opponent. |
Definition at line 934 of file command.cpp.
References CMap::Field(), CMap::Info, CPlayer::IsBothSharedVision(), Map, CMapInfo::MapHeight, MapMarkUnitSight(), MapUnmarkUnitSight(), CMapInfo::MapWidth, NumUnits, Players, CPlayer::SharedVision, Units, CMapField::Visible, and y.
Referenced by CommandQuit(), ParseExtendedCommand(), and SendCommandSharedVision().
Prepare command auto spellcast.
Cast a spell at position or unit.
| unit | Pointer to unit. | |
| x | X map position to spell cast on. | |
| y | Y map position to spell cast on. | |
| dest | Spell cast on unit (if exist). | |
| spell | Spell type pointer. | |
| flush | If true, flush command queue. |
Definition at line 830 of file command.cpp.
References _C_, COrder::Action, COrder::Arg1, Assert, CUnitType::CanCastSpell, ClearSavedAction(), DebugPrint, CUnit::Destroyed, GetNextOrder(), COrder::Goal, SpellType::Ident, CMap::Info, COrder::Init(), Map, CMapInfo::MapHeight, CMapInfo::MapWidth, CUnit::Orders, SpellType::Range, COrder::Range, CUnit::RefsIncrease(), CUnit::Removed, SpellType::Slot, COrder::Spell, CUnit::Type, UnitActionDie, UnitActionSpellCast, UnitNumber, CUnit::X, COrder::X, CUnit::Y, and COrder::Y.
Referenced by AutoCastSpell(), ParseCommand(), and SendCommandSpellCast().
| void CommandStandGround | ( | CUnit * | unit, | |
| int | flush | |||
| ) |
Prepare command follow.
Stand ground.
| unit | pointer to unit. | |
| flush | if true, flush command queue. |
Definition at line 250 of file command.cpp.
References COrder::Action, CUnitType::Building, ClearSavedAction(), GetNextOrder(), COrder::Init(), CUnit::NewOrder, ReleaseOrder(), CUnit::Type, and UnitActionStandGround.
Referenced by ParseCommand(), and SendCommandStandGround().
| void CommandStopUnit | ( | CUnit * | unit | ) |
Prepare command stand ground.
Stop unit.
| unit | pointer to unit. |
Definition at line 171 of file command.cpp.
References COrder::Action, Assert, FlushCommands, GetNextOrder(), COrder::Init(), CUnit::NewOrder, ReleaseOrder(), CUnit::SavedOrder, and UnitActionStill.
Referenced by HitUnit(), ParseCommand(), and SendCommandStopUnit().
Prepare command cancel training.
Building starts training a unit.
| unit | pointer to unit. | |
| type | unit type to train. | |
| flush | if true, flush command queue. |
Definition at line 732 of file command.cpp.
References COrder::Action, CPlayer::CheckLimits(), ClearSavedAction(), GetNextOrder(), COrder::Init(), CUnit::Orders, CUnit::Player, CUnit::Removed, COrder::Type, UnitActionDie, and UnitActionTrain.
Referenced by AiTrainUnit(), ParseCommand(), and SendCommandTrainUnit().
Prepare command build.
Unload a transporter.
| unit | pointer to unit. | |
| x | X map position to unload. | |
| y | Y map position to unload. | |
| what | unit to be unloaded, NoUnitP all. | |
| flush | if true, flush command queue. |
Definition at line 589 of file command.cpp.
References COrder::Action, ClearSavedAction(), CUnit::Destroyed, GetNextOrder(), COrder::Goal, COrder::Init(), CUnit::Orders, CUnit::RefsIncrease(), CUnit::Removed, UnitActionDie, UnitActionUnload, COrder::X, and COrder::Y.
Referenced by ParseCommand(), and SendCommandUnload().
Get next free order slot.
| unit | pointer to unit. | |
| flush | if true, flush order queue. |
Definition at line 97 of file command.cpp.
References int(), CUnit::OrderCount, CUnit::Orders, and ReleaseOrders().
Referenced by CommandAnyOrder(), CommandAttack(), CommandAttackGround(), CommandBoard(), CommandBuildBuilding(), CommandFollow(), CommandMove(), CommandPatrolUnit(), CommandRepair(), CommandResource(), CommandSpellCast(), CommandStandGround(), CommandStopUnit(), CommandTrainUnit(), and CommandUnload().
| static void ReleaseOrder | ( | COrder * | order | ) | [static] |
Release an order.
| order | Pointer to order. |
Definition at line 60 of file command.cpp.
References COrder::Goal, NoUnitP, and CUnit::RefsDecrease().
Referenced by ClearSavedAction(), CommandAttack(), CommandAttackGround(), CommandBoard(), CommandBuildBuilding(), CommandFollow(), CommandMove(), CommandPatrolUnit(), CommandRepair(), CommandResource(), CommandStandGround(), CommandStopUnit(), and ReleaseOrders().
| static void ReleaseOrders | ( | CUnit * | unit | ) | [static] |
Release all orders of a unit.
| unit | Pointer to unit. |
Definition at line 73 of file command.cpp.
References CUnit::OrderCount, CUnit::OrderFlush, CUnit::Orders, and ReleaseOrder().
Referenced by GetNextOrder().
| static void RemoveOrder | ( | CUnit * | unit, | |
| int | order | |||
| ) | [static] |
Remove an order from the list of orders pending
| unit | pointer to unit | |
| order | number of the order to remove |
Definition at line 118 of file command.cpp.
References Assert, CUnit::OrderCount, CUnit::Orders, CUnit::SubAction, and UnitActionStill.
Referenced by CommandCancelTraining().
1.5.6