$treeview $search $mathjax
Stratagus
2.2.6
$projectbrief
|
$projectbrief
|
$searchbox |
_________ __ __ / _____// |_____________ _/ |______ ____ __ __ ______ \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \ /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > \/ \/ \//_____/ \/ ______________________ ______________________ T H E W A R B E G I N S Stratagus - A free fantasy real time strategy game engine
00001 // _________ __ __ 00002 // / _____// |_____________ _/ |______ ____ __ __ ______ 00003 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/ 00004 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ | 00005 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ > 00006 // \/ \/ \//_____/ \/ 00007 // ______________________ ______________________ 00008 // T H E W A R B E G I N S 00009 // Stratagus - A free fantasy real time strategy game engine 00010 // 00012 // 00013 // (c) Copyright 1998-2007 by Lutz Sammer and Jimmy Salmon 00014 // 00015 // This program is free software; you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation; only version 2 of the License. 00018 // 00019 // This program is distributed in the hope that it will be useful, 00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 // GNU General Public License for more details. 00023 // 00024 // You should have received a copy of the GNU General Public License 00025 // along with this program; if not, write to the Free Software 00026 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00027 // 02111-1307, USA. 00028 // 00029 00030 #ifndef __UNIT_H__ 00031 #define __UNIT_H__ 00032 00034 00035 /*---------------------------------------------------------------------------- 00036 -- Documentation 00037 ----------------------------------------------------------------------------*/ 00038 00353 /*---------------------------------------------------------------------------- 00354 -- Includes 00355 ----------------------------------------------------------------------------*/ 00356 00357 #include <vector> 00358 #include "SDL.h" 00359 00360 #ifndef __UNITTYPE_H__ 00361 #include "unittype.h" 00362 #endif 00363 00364 #ifndef __MAP_TILE_H__ 00365 #include "tile.h" 00366 #endif 00367 00368 #ifndef __PLAYER_H__ 00369 #include "player.h" 00370 #endif 00371 00372 #include "vec2i.h" 00373 00374 /*---------------------------------------------------------------------------- 00375 -- Declarations 00376 ----------------------------------------------------------------------------*/ 00377 00378 class CUnit; 00379 class CUnitType; 00380 class CUnitStats; 00381 class CPlayer; 00382 class SpellType; 00383 class CUnitColors; 00384 class CConstructionFrame; 00385 class CVariable; 00386 class CUpgrade; 00387 class CBuildRestrictionOnTop; 00388 class CFile; 00389 struct lua_State; 00390 class CViewport; 00391 class CAnimation; 00392 00394 extern void SelectedUnitChanged(); 00395 00404 static inline int MapDistance(const Vec2i& pos1, const Vec2i &pos2) 00405 { 00406 const Vec2i diff = pos2 - pos1; 00407 00408 return isqrt(diff.x * diff.x + diff.y * diff.y); 00409 } 00410 00419 static inline int MapDistance(const PixelPos& pos1, const PixelPos &pos2) 00420 { 00421 const PixelDiff diff = pos2 - pos1; 00422 00423 return isqrt(diff.x * diff.x + diff.y * diff.y); 00424 } 00425 00427 extern int MapDistanceToType(const Vec2i &pos1, const CUnitType &type, const Vec2i &pos2); 00428 00430 extern int MapDistanceBetweenTypes(const CUnitType &src, const Vec2i &pos1, 00431 const CUnitType &dst, const Vec2i &pos2); 00432 00433 00437 typedef unsigned short UnitRef; 00438 00446 typedef enum _unit_action_ { 00447 UnitActionNone, 00448 00449 UnitActionStill, 00450 UnitActionStandGround, 00451 UnitActionFollow, 00452 UnitActionMove, 00453 UnitActionAttack, 00454 UnitActionAttackGround, 00455 UnitActionDie, 00456 00457 UnitActionSpellCast, 00458 00459 UnitActionTrain, 00460 UnitActionUpgradeTo, 00461 UnitActionResearch, 00462 UnitActionBuilt, 00463 00464 // Compound actions 00465 UnitActionBoard, 00466 UnitActionUnload, 00467 UnitActionPatrol, 00468 UnitActionBuild, 00469 00470 UnitActionRepair, 00471 UnitActionResource, 00472 UnitActionReturnGoods, 00473 UnitActionTransformInto 00474 } UnitAction; 00475 00479 enum UnitVoiceGroup { 00480 VoiceSelected, 00481 VoiceAcknowledging, 00482 VoiceReady, 00483 VoiceHelpMe, 00484 VoiceDying, 00485 VoiceWorkCompleted, 00486 VoiceBuilding, 00487 VoiceDocking, 00488 VoiceRepairing, 00489 VoiceHarvesting, 00490 VoiceAttack, 00491 VoiceExtraDying 00492 }; 00493 00502 enum _directions_ { 00503 LookingN = 0 * 32, 00504 LookingNE = 1 * 32, 00505 LookingE = 2 * 32, 00506 LookingSE = 3 * 32, 00507 LookingS = 4 * 32, 00508 LookingSW = 5 * 32, 00509 LookingW = 6 * 32, 00510 LookingNW = 7 * 32 00511 }; 00512 00513 #define NextDirection 32 00514 #define UnitNotSeen 0x7fffffff 00515 00517 class CUnit { 00518 public: 00519 00523 class COrder { 00524 friend void CclParseOrder(lua_State *l, COrder *order); 00525 CUnit *Goal; 00526 00527 public: 00528 COrder() : Goal(NULL), Range(0), MinRange(0), Width(0), 00529 Height(0),Action(UnitActionNone), CurrentResource(0) 00530 { 00531 goalPos.x = -1; 00532 goalPos.y = -1; 00533 memset(&Arg1, 0, sizeof(Arg1)); 00534 }; 00535 COrder(const COrder &ths); 00536 ~COrder() { Release(); } 00537 00538 void Release(); 00539 COrder& operator=(const COrder &rhs); 00540 bool CheckRange(); 00541 00542 void Init() { 00543 Assert(Action != UnitActionResource || 00544 (Action == UnitActionResource && Arg1.Resource.Mine == NULL)); 00545 Action = UnitActionNone; 00546 Range = 0; 00547 MinRange = 0; 00548 Width = 0; 00549 Height = 0; 00550 CurrentResource = 0; 00551 Assert(!Goal); 00552 goalPos.x = -1; 00553 goalPos.y = -1; 00554 memset(&Arg1, 0, sizeof(Arg1)); 00555 }; 00556 00557 int Range; 00558 unsigned int MinRange; 00559 unsigned char Width; 00560 unsigned char Height; 00561 unsigned char Action; 00562 unsigned char CurrentResource; //used in UnitActionResource and 00563 //UnitActionReturnGoods 00564 00565 Vec2i goalPos; 00566 00567 union { 00568 Vec2i Patrol; 00569 union { 00570 Vec2i Pos; 00571 CUnit *Mine; 00572 } Resource; 00573 SpellType *Spell; 00574 CUpgrade *Upgrade; 00575 CUnitType *Type; 00576 } Arg1; 00577 00578 inline bool HasGoal() const 00579 { 00580 return Goal != NULL; 00581 }; 00582 00583 inline CUnit * GetGoal() const 00584 { 00585 return Goal; 00586 }; 00587 00588 inline void SetGoal(CUnit *const new_goal) 00589 { 00590 if (new_goal) 00591 { 00592 new_goal->RefsIncrease(); 00593 } 00594 if (Goal) { 00595 Goal->RefsDecrease(); 00596 } 00597 Goal = new_goal; 00598 }; 00599 00600 inline void ClearGoal() 00601 { 00602 if (Goal) { 00603 Goal->RefsDecrease(); 00604 } 00605 Goal = NULL; 00606 }; 00607 00608 }; 00609 00610 CUnit() { Init(); } 00611 00612 void Init() { 00613 Refs = 0; 00614 Slot = 0; 00615 UnitSlot = NULL; 00616 PlayerSlot = NULL; 00617 Next = NULL; 00618 InsideCount = 0; 00619 BoardCount = 0; 00620 UnitInside = NULL; 00621 Container = NULL; 00622 NextContained = NULL; 00623 PrevContained = NULL; 00624 NextWorker = NULL; 00625 tilePos.x = 0; 00626 tilePos.y = 0; 00627 Offset = 0; 00628 Type = NULL; 00629 Player = NULL; 00630 Stats = NULL; 00631 CurrentSightRange = 0; 00632 Colors = NULL; 00633 IX = 0; 00634 IY = 0; 00635 Frame = 0; 00636 Direction = 0; 00637 DamagedType = ANIMATIONS_DEATHTYPES; 00638 Attacked = 0; 00639 Burning = 0; 00640 Destroyed = 0; 00641 Removed = 0; 00642 Selected = 0; 00643 TeamSelected = 0; 00644 Constructed = 0; 00645 Active = 0; 00646 Boarded = 0; 00647 RescuedFrom = NULL; 00648 memset(VisCount, 0, sizeof(VisCount)); 00649 memset(&Seen, 0, sizeof(Seen)); 00650 Variable = NULL; 00651 TTL = 0; 00652 GroupId = 0; 00653 LastGroup = 0; 00654 ResourcesHeld = 0; 00655 SubAction = 0; 00656 Wait = 0; 00657 State = 0; 00658 Blink = 0; 00659 Moving = 0; 00660 ReCast = 0; 00661 CacheLock = 0; 00662 GuardLock = 0; 00663 memset(&Anim, 0, sizeof(Anim)); 00664 CurrentResource = 0; 00665 OrderCount = 0; 00666 OrderFlush = 0; 00667 Orders.clear(); 00668 SavedOrder.Init(); 00669 NewOrder.Init(); 00670 CriticalOrder.Init(); 00671 AutoCastSpell = NULL; 00672 AutoRepair = 0; 00673 memset(&Data, 0, sizeof(Data)); 00674 Goal = NULL; 00675 } 00676 00677 // @note int is faster than shorts 00678 unsigned int Refs; 00679 int Slot; 00680 CUnit **UnitSlot; 00681 CUnit **PlayerSlot; 00682 00683 CUnit *Next; 00684 00685 int InsideCount; 00686 int BoardCount; 00687 CUnit *UnitInside; 00688 CUnit *Container; 00689 CUnit *NextContained; 00690 CUnit *PrevContained; 00691 CUnit *NextWorker; //pointer to next assigned worker to "Goal" resource. 00692 00693 Vec2i tilePos; 00694 00695 unsigned int Offset; 00696 00697 CUnitType *Type; 00698 CPlayer *Player; 00699 CUnitStats *Stats; 00700 int CurrentSightRange; 00701 00702 // DISPLAY: 00703 int Frame; 00704 CUnitColors *Colors; 00705 00706 signed char IX; 00707 signed char IY; 00708 unsigned char Direction; //: 8; /// angle (0-255) unit looking 00709 unsigned char CurrentResource; 00710 int ResourcesHeld; 00711 00712 00713 unsigned char DamagedType; 00714 unsigned long Attacked; 00715 unsigned SubAction : 8; 00716 unsigned State : 8; 00717 unsigned Blink : 3; 00718 unsigned Moving : 1; 00719 unsigned ReCast : 1; 00720 unsigned AutoRepair : 1; 00721 00722 unsigned Burning : 1; 00723 unsigned Destroyed : 1; 00724 unsigned Removed : 1; 00725 unsigned Selected : 1; 00726 00727 00728 unsigned Constructed : 1; 00729 unsigned Active : 1; 00730 unsigned Boarded : 1; 00731 unsigned CacheLock : 1; 00732 unsigned GuardLock : 1; 00733 00737 unsigned Rs : 8; 00738 00739 unsigned TeamSelected; 00740 CPlayer *RescuedFrom; 00741 00742 /* Seen stuff. */ 00743 int VisCount[PlayerMax]; 00744 struct _seen_stuff_ { 00745 CConstructionFrame *CFrame; 00746 int Frame; 00747 CUnitType *Type; 00748 int X; 00749 int Y; 00750 signed char IX; 00751 signed char IY; 00752 unsigned Constructed : 1; 00753 unsigned State : 3; 00754 unsigned Destroyed : PlayerMax; 00755 unsigned ByPlayer : PlayerMax; 00756 } Seen; 00757 00758 CVariable *Variable; 00759 00760 unsigned long TTL; 00761 00762 int GroupId; 00763 int LastGroup; 00764 00765 unsigned int Wait; 00766 00767 struct _unit_anim_ { 00768 const CAnimation *Anim; 00769 const CAnimation *CurrAnim; 00770 int Wait; 00771 int Unbreakable; 00772 } Anim; 00773 00774 00775 char OrderCount; 00776 char OrderFlush; 00777 std::vector<COrder *> Orders; 00778 COrder SavedOrder; 00779 COrder NewOrder; 00780 COrder CriticalOrder; 00781 char *AutoCastSpell; 00782 00783 union _order_data_ { 00784 struct _order_move_ { 00785 unsigned short int Cycles; 00786 char Fast; 00787 char Length; 00788 #define MAX_PATH_LENGTH 28 00789 char Path[MAX_PATH_LENGTH]; 00790 } Move; 00791 struct _order_built_ { 00792 CUnit *Worker; 00793 int Progress; 00794 int Cancel; 00795 CConstructionFrame *Frame; 00796 } Built; 00797 struct _order_build_ { 00798 int Cycles; 00799 } Build; 00800 struct _order_resource_ { 00801 CUnit *Workers; //pointer to first assigned worker to this resource. 00802 int Assigned; 00803 int Active; 00804 } Resource; 00805 struct _order_resource_worker_ { 00806 int TimeToHarvest; 00807 unsigned DoneHarvesting:1; 00808 } ResWorker; 00809 struct _order_repair_ { 00810 int Cycles; 00811 } Repair; 00812 struct _order_research_ { 00813 CUpgrade *Upgrade; 00814 } Research; 00815 struct _order_upgradeto_ { 00816 int Ticks; 00817 } UpgradeTo; 00818 struct _order_train_ { 00819 int Ticks; 00820 } Train; 00821 } Data; 00822 00823 CUnit *Goal; 00824 00825 inline COrder * CreateOrder() { 00826 Orders.push_back(new COrder); 00827 return Orders[(int)OrderCount++]; 00828 } 00829 00830 inline COrder *CurrentOrder() const 00831 { 00832 #if __GNUC__ < 4 00833 return Orders[0]; 00834 #else 00835 return *(Orders.data()); 00836 #endif 00837 } 00838 inline UnitAction CurrentAction() const 00839 { 00840 return (UnitAction)(CurrentOrder()->Action); 00841 } 00842 00843 inline bool IsIdle() const { 00844 return OrderCount == 1 && CurrentAction() == UnitActionStill; 00845 } 00846 00847 inline void ClearAction() { 00848 CurrentOrder()->Action = UnitActionStill; 00849 SubAction = 0; 00850 if (Selected) { 00851 SelectedUnitChanged(); 00852 } 00853 } 00854 00855 inline int GetReactRange() const 00856 { 00857 return (Player->Type == PlayerPerson ? 00858 Type->ReactRangePerson : Type->ReactRangeComputer); 00859 } 00860 00862 void RefsIncrease(); 00864 void RefsDecrease(); 00865 00867 void Init(CUnitType &type); 00869 void AssignToPlayer(CPlayer *player); 00870 00872 void Draw(const CViewport *vp) const; 00874 void Place(const Vec2i &pos); 00875 00877 void MoveToXY(const Vec2i &pos); 00879 void AddInContainer(CUnit &host); 00881 void ChangeOwner(CPlayer &newplayer); 00882 00884 void Remove(CUnit *host); 00885 00886 void AssignWorkerToMine(CUnit &mine); 00887 void DeAssignWorkerFromMine(CUnit &mine); 00888 00890 void Release(bool final = false); 00891 00892 bool RestoreOrder(); 00893 bool StoreOrder(); 00894 00895 // Cowards and invisible units don't attack unless ordered. 00896 bool IsAgressive() const 00897 { 00898 return (Type->CanAttack && !Type->Coward && 00899 Variable[INVISIBLE_INDEX].Value == 0); 00900 } 00901 00903 bool IsVisible(const CPlayer &player) const; 00904 00905 inline bool IsInvisibile(const CPlayer &player) const 00906 { 00907 return ((&player != Player) && !!Variable[INVISIBLE_INDEX].Value && 00908 (!player.IsBothSharedVision(*Player))); 00909 } 00910 00917 inline bool IsAlive() const 00918 { 00919 return !Destroyed && CurrentAction() != UnitActionDie; 00920 } 00921 00928 inline bool IsAliveOnMap() const 00929 { 00930 return !Removed && IsAlive(); 00931 } 00932 00940 inline bool IsVisibleAsGoal(const CPlayer &player) const 00941 { 00942 // Invisibility 00943 if (IsInvisibile(player)) { 00944 return false; 00945 } 00946 if ((player.Type == PlayerComputer && !this->Type->PermanentCloak) 00947 || IsVisible(player) || IsVisibleOnRadar(player)) { 00948 return IsAliveOnMap(); 00949 } else { 00950 return Type->VisibleUnderFog && 00951 (Seen.ByPlayer & (1 << player.Index)) && 00952 !(Seen.Destroyed & (1 << player.Index)); 00953 } 00954 } 00955 00964 inline bool IsVisibleOnMap(const CPlayer &player) const 00965 { 00966 return IsAliveOnMap() && !IsInvisibile(player) && IsVisible(player); 00967 } 00968 00970 bool IsVisibleOnMinimap() const; 00971 00972 // Returns true if unit is visible under radar (By player, or by shared vision) 00973 bool IsVisibleOnRadar(const CPlayer &pradar) const; 00974 00976 bool IsVisibleInViewport(const CViewport *vp) const; 00977 00979 bool IsVisibleOnScreen() const; 00980 00982 void GetMapArea(int *sx, int *sy, int *ex, int *ey) const; 00983 00984 bool IsEnemy(const CPlayer &player) const; 00985 bool IsEnemy(const CUnit &unit) const; 00986 bool IsAllied(const CPlayer &player) const; 00987 bool IsAllied(const CUnit &unit) const; 00988 bool IsSharedVision(const CPlayer &player) const; 00989 bool IsSharedVision(const CUnit &unit) const; 00990 bool IsBothSharedVision(const CPlayer &player) const; 00991 bool IsBothSharedVision(const CUnit &unit) const; 00992 bool IsTeamed(const CPlayer &player) const; 00993 bool IsTeamed(const CUnit &unit) const; 00994 00995 bool IsUnusable(bool ignore_built_state = false) const; 00996 01004 int MapDistanceTo(const CUnit &dst) const 01005 { 01006 return MapDistanceBetweenTypes(*Type, tilePos, *dst.Type, dst.tilePos); 01007 } 01008 01018 int MapDistanceTo(int x, int y) const 01019 { 01020 const Vec2i pos = {x, y}; 01021 return MapDistanceToType(pos, *Type, this->tilePos); 01022 } 01023 01030 bool CanMove() const 01031 { 01032 return Type->CanMove(); 01033 } 01034 01035 int GetDrawLevel() const 01036 { 01037 return ((Type->CorpseType && CurrentAction() == UnitActionDie) ? 01038 Type->CorpseType->DrawLevel : Type->DrawLevel); 01039 } 01040 01041 }; 01042 01043 typedef CUnit::COrder* COrderPtr; 01044 01045 class CUnitPtr { 01046 CUnit *unit; 01047 public: 01048 01049 void Reset() { 01050 if (unit) { 01051 unit->RefsDecrease(); 01052 } 01053 unit = NULL; 01054 } 01055 01056 CUnitPtr() : unit(NULL) {} 01057 CUnitPtr(CUnit *u) : unit(u) { 01058 if (unit) { 01059 unit->RefsIncrease(); 01060 } 01061 } 01062 CUnitPtr(const CUnitPtr &u) : unit(u.unit) { 01063 if (unit) { 01064 unit->RefsIncrease(); 01065 } 01066 } 01067 ~CUnitPtr() { 01068 Reset(); 01069 } 01070 01071 operator CUnit *() { 01072 return unit; 01073 } 01074 01075 CUnit & operator*() { 01076 return *unit; 01077 } 01078 CUnit *operator->() const 01079 { 01080 return unit; 01081 } 01082 01083 CUnitPtr& operator= (CUnit *u) { 01084 if (this->unit != u) { 01085 if (u) { 01086 u->RefsIncrease(); 01087 } 01088 if (unit) { 01089 unit->RefsDecrease(); 01090 } 01091 unit = u; 01092 } 01093 return *this; 01094 } 01095 01096 bool operator== (CUnit *u) const 01097 { 01098 return this->unit == u; 01099 } 01100 bool operator!= (CUnit *u) const 01101 { 01102 return this->unit != u; 01103 } 01104 01105 }; 01106 01107 class CUnitDrawProxy { 01108 01109 void DrawSelectionAt(int x, int y) const; 01110 void DrawDecorationAt(int x, int y) const; 01111 public: 01112 01113 CUnitDrawProxy(): Variable(0) {} 01114 ~CUnitDrawProxy() { 01115 if (Variable) { 01116 delete[] Variable; 01117 } 01118 } 01119 01120 int X; 01121 int Y; 01122 int frame; 01123 int TeamSelected; //unit->TeamSelected 01124 int GroupId; //unit->GroupId 01125 01126 signed char IX; 01127 signed char IY; 01128 unsigned char CurrentResource; 01129 01130 unsigned int IsAlive:1; 01131 unsigned int Selected:1; //unit->Selected 01132 unsigned int ResourcesHeld:1; 01133 unsigned int state: 2; 01134 unsigned int Blink: 3; //unit->Blink 01135 01136 const CConstructionFrame *cframe; 01137 const CUnitType *Type; 01138 const CPlayer *Player; 01139 01140 CVariable *Variable; 01141 01142 void operator=(const CUnit *unit); 01143 void Draw(const CViewport *vp) const; 01144 }; 01145 01146 //unit_find 01147 struct CUnitTypeFinder { 01148 const UnitTypeType type; 01149 CUnitTypeFinder(const UnitTypeType t) : type(t) {} 01150 inline bool operator() (const CUnit *const unit) const 01151 { 01152 const CUnitType *const t = unit->Type; 01153 if (t->Vanishes || (type != (UnitTypeType)-1 && t->UnitType != type)) 01154 return false; 01155 return true; 01156 } 01157 01158 inline CUnit *Find(const CUnitCache &cache) const 01159 { 01160 return cache.find(*this); 01161 } 01162 01163 inline CUnit *Find(const CMapField *const mf) const 01164 { 01165 return mf->UnitCache.find(*this); 01166 } 01167 }; 01168 01169 struct CResourceFinder { 01170 const int resource; 01171 const int mine_on_top; 01172 CResourceFinder(const int r, int on_top) : resource(r), mine_on_top(on_top) {} 01173 inline bool operator () (const CUnit *const unit) const 01174 { 01175 const CUnitType *const type = unit->Type; 01176 return (type->GivesResource == resource 01177 && unit->ResourcesHeld != 0 01178 && (mine_on_top ? type->CanHarvest : !type->CanHarvest) 01179 && !unit->IsUnusable(true) //allow mines under construction 01180 ); 01181 } 01182 inline CUnit *Find(const CMapField *const mf) const 01183 { 01184 return mf->UnitCache.find(*this); 01185 } 01186 }; 01187 01188 struct CResourceDepositFinder { 01189 const int resource; 01190 CResourceDepositFinder(const int r) : resource(r) {} 01191 inline bool operator () (const CUnit *const unit) const 01192 { 01193 return (unit->Type->CanStore[resource] && !unit->IsUnusable()); 01194 } 01195 inline CUnit *Find(const CMapField *const mf) const 01196 { 01197 return mf->UnitCache.find(*this); 01198 } 01199 }; 01200 01201 #define NoUnitP (CUnit *)0 01202 #define InfiniteDistance INT_MAX 01203 01204 #define FlushCommands 1 01205 01206 #define MAX_UNIT_SLOTS 65535 01207 01208 01211 #define UnitNumber(unit) ((unit).Slot) 01212 01216 #define NUM_GROUPS 10 01217 01221 class CPreference { 01222 public: 01223 CPreference() : ShowSightRange(false), ShowReactionRange(false), 01224 ShowAttackRange(false), ShowMessages(false), 01225 BigScreen(false),ShowOrders(0) {}; 01226 01227 bool ShowSightRange; 01228 bool ShowReactionRange; 01229 bool ShowAttackRange; 01230 bool ShowMessages; 01231 bool BigScreen; 01232 01233 int ShowOrders; 01234 }; 01235 01236 extern CPreference Preference; 01237 01238 /*---------------------------------------------------------------------------- 01239 -- Variables 01240 ----------------------------------------------------------------------------*/ 01241 01242 extern CUnit *Units[MAX_UNIT_SLOTS]; 01243 extern int NumUnits; 01244 01245 // in unit_draw.c 01247 extern unsigned long ShowOrdersCount; 01248 extern bool EnableTrainingQueue; 01249 extern bool EnableBuildingCapture; 01250 extern bool RevealAttacker; 01251 extern const CViewport *CurrentViewport; 01252 extern void DrawUnitSelection(const CViewport *vp,const CUnit &unit); 01253 extern void (*DrawSelection)(Uint32, int, int, int, int); 01254 extern int MaxSelectable; 01255 01256 extern CUnit **Selected; 01257 extern CUnit **TeamSelected[PlayerMax]; 01258 extern int NumSelected; 01259 extern int TeamNumSelected[PlayerMax]; 01260 01261 /*---------------------------------------------------------------------------- 01262 -- Functions 01263 ----------------------------------------------------------------------------*/ 01264 01266 void MarkUnitFieldFlags(const CUnit &unit); 01268 void UnmarkUnitFieldFlags(const CUnit &unit); 01270 void UpdateUnitSightRange(CUnit &unit); 01272 extern CUnit *MakeUnit(CUnitType &type, CPlayer *player); 01274 extern CUnit *MakeUnitAndPlace(const Vec2i &pos, CUnitType &type, CPlayer *player); 01276 extern void UnitLost(CUnit &unit); 01278 extern void UnitClearOrders(CUnit &unit); 01280 extern void UpdateForNewUnit(const CUnit &unit, int upgrade); 01282 extern void NearestOfUnit(const CUnit &unit, const Vec2i& pos, Vec2i *dpos); 01283 01285 extern void UnitGoesUnderFog(CUnit &unit, const CPlayer &player); 01287 extern void UnitGoesOutOfFog(CUnit &unit, const CPlayer &player); 01289 extern void UnitsOnTileMarkSeen(const CPlayer &player, int x, int y, int p); 01290 extern void UnitsOnTileMarkSeen(const CPlayer &player, unsigned int index, int p); 01291 01293 extern void UnitsOnTileUnmarkSeen(const CPlayer &player, int x, int y, int p); 01294 extern void UnitsOnTileUnmarkSeen(const CPlayer &player, unsigned int index, int p); 01295 01297 extern void UnitCountSeen(CUnit &unit); 01298 01300 extern void RescueUnits(); 01301 01303 extern int DirectionToHeading(const Vec2i &dir); 01305 extern int DirectionToHeading(const PixelDiff &dir); 01306 01308 extern void UnitUpdateHeading(CUnit &unit); 01310 extern void UnitHeadingFromDeltaXY(CUnit &unit, const Vec2i &delta); 01311 01312 01314 extern void DropOutOnSide(CUnit &unit, int heading, const CUnit *container); 01316 extern void DropOutNearest(CUnit &unit, const Vec2i &goalPos, const CUnit *container); 01317 01319 extern void DropOutAll(const CUnit &unit); 01320 01322 extern CBuildRestrictionOnTop *OnTopDetails(const CUnit &unit, const CUnitType *parent); 01324 extern CUnit *CanBuildHere(const CUnit *unit, const CUnitType &type, const Vec2i &pos); 01326 extern bool CanBuildOn(const Vec2i &pos, int mask); 01328 extern CUnit *CanBuildUnitType(const CUnit *unit, const CUnitType &type, const Vec2i &pos, int real); 01330 extern int GetAnimationDamagedState(CUnit &unit, int anim); 01331 01333 extern CUnit *UnitFindResource(const CUnit &unit, int x, int y, int range, 01334 int resource, bool check_usage = false, const CUnit *destu = NULL); 01335 extern CUnit *UnitFindMiningArea(const CUnit &unit, int x, int y, int range, int resource); 01337 extern CUnit *FindDeposit(const CUnit &unit, int range, int resource); 01339 extern CUnit *FindIdleWorker(const CPlayer &player, const CUnit *last); 01340 01342 extern int FindTerrainType(int movemask, int resmask, int rvresult, int range, 01343 const CPlayer *player, const Vec2i &startPos, Vec2i *pos); 01345 extern int FindWoodInSight(const CUnit &unit, Vec2i *pos); 01346 01348 extern CUnit *UnitOnScreen(CUnit *unit, int x, int y); 01349 01351 extern void LetUnitDie(CUnit &unit); 01353 extern void DestroyAllInside(CUnit &source); 01355 extern void HitUnit(CUnit *attacker, CUnit &target, int damage); 01356 01358 extern int ViewPointDistance(const Vec2i &pos); 01360 extern int ViewPointDistanceToUnit(const CUnit &dest); 01361 01363 extern int CanTarget(const CUnitType *type, const CUnitType *dest); 01365 extern int CanTransport(const CUnit &transporter, const CUnit &unit); 01366 01368 extern std::string UnitReference(const CUnit &unit); 01370 extern void SaveOrder(const COrderPtr order, CFile *file); 01372 extern void SaveUnit(const CUnit &unit, CFile *file); 01374 extern void SaveUnits(CFile *file); 01375 01377 extern void InitUnits(); 01379 extern void CleanUnits(); 01380 01381 // in unit_draw.c 01382 //-------------------- 01384 extern void DrawSelectionNone(Uint32, int, int, int, int); 01386 extern void DrawSelectionCircle(Uint32, int, int, int, int); 01388 extern void DrawSelectionCircleWithTrans(Uint32, int, int, int, int); 01390 extern void DrawSelectionRectangle(Uint32, int, int, int, int); 01392 extern void DrawSelectionRectangleWithTrans(Uint32, int, int, int, int); 01394 extern void DrawSelectionCorners(Uint32, int, int, int, int); 01395 01397 extern void DecorationCclRegister(); 01399 extern void LoadDecorations(); 01401 extern void CleanDecorations(); 01402 01404 extern void DrawShadow(const CUnitType &type, int frame, int x, int y); 01406 extern int FindAndSortUnits(const CViewport *vp, CUnit *table[]); 01407 extern int FindAndSortUnits(const CViewport *vp, CUnitDrawProxy table[]); 01409 extern void ShowOrder(const CUnit &unit); 01410 01411 // in unit_find.cpp 01413 extern int FindUnitsByType(const CUnitType &type, CUnit **table); 01415 extern int FindPlayerUnitsByType(const CPlayer &, const CUnitType &, CUnit **); 01417 extern CUnit *UnitOnMapTile(const Vec2i &pos, unsigned int type);// = -1); 01419 extern CUnit *TargetOnMap(const CUnit &unit, int x1, int y1, int x2, int y2); 01420 01422 extern CUnit *ResourceOnMap(const Vec2i &pos, int resource, bool mine_on_top = true); 01424 extern CUnit *ResourceDepositOnMap(const Vec2i &pos, int resource); 01425 01427 extern CUnit *AttackUnitsInDistance(const CUnit &unit, int range); 01429 extern CUnit *AttackUnitsInRange(const CUnit &unit); 01431 extern CUnit *AttackUnitsInReactRange(const CUnit &unit); 01432 01433 extern CUnit * 01434 AutoAttackUnitsInDistance(const CUnit &unit, int range, CUnitCache &autotargets); 01435 01436 // in groups.c 01437 01439 extern void InitGroups(); 01441 extern void SaveGroups(CFile *file); 01443 extern void CleanGroups(); 01444 01445 // 2 functions to conseal the groups internal data structures... 01447 extern int GetNumberUnitsOfGroup(int num, GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY); 01449 extern CUnit **GetUnitsOfGroup(int num); 01450 01452 extern void ClearGroup(int num); 01454 extern void AddToGroup(CUnit **units, int nunits, int num); 01456 extern void SetGroup(CUnit **units, int nunits, int num); 01458 extern void RemoveUnitFromGroups(CUnit &unit); 01460 extern void GroupCclRegister(); 01462 extern void GroupHelpMe(CUnit *attacker, CUnit &defender); 01463 extern int IsGroupTainted(int num); 01464 01465 // in selection.c 01466 01468 #define IsOnlySelected(unit) (NumSelected == 1 && Selected[0] == &(unit)) 01469 01471 extern void SaveSelection(); 01473 extern void RestoreSelection(); 01475 extern void UnSelectAll(); 01477 extern void ChangeSelectedUnits(CUnit **units, int num_units); 01479 extern void ChangeTeamSelectedUnits(CPlayer &player, CUnit **units, int adjust, int count); 01481 extern int SelectUnit(CUnit &unit); 01483 extern void SelectSingleUnit(CUnit &unit); 01485 extern void UnSelectUnit(CUnit &unit); 01487 extern int ToggleSelectUnit(CUnit &unit); 01489 extern int SelectUnitsByType(CUnit &base); 01491 extern int ToggleUnitsByType(CUnit &base); 01493 extern int SelectGroup(int group_number, GroupSelectionMode mode = SELECTABLE_BY_RECTANGLE_ONLY); 01495 extern int AddGroupFromUnitToSelection(CUnit &unit); 01497 extern int SelectGroupFromUnit(CUnit &unit); 01499 extern int SelectUnitsInRectangle(int tx, int ty, int w, int h); 01501 extern int SelectGroundUnitsInRectangle(int tx, int ty, int w, int h); 01503 extern int SelectAirUnitsInRectangle(int tx, int ty, int w, int h); 01505 extern int AddSelectedUnitsInRectangle(int tx, int ty, int w, int h); 01507 extern int AddSelectedGroundUnitsInRectangle(int tx, int ty, int w, int h); 01509 extern int AddSelectedAirUnitsInRectangle(int tx, int ty, int w, int h); 01510 01512 extern void InitSelections(); 01514 extern void SaveSelections(CFile *file); 01516 extern void CleanSelections(); 01518 extern void SelectionCclRegister(); 01519 01520 // in ccl_unit.c 01521 01523 extern void CclParseOrder(lua_State *l, COrderPtr order); 01525 extern void UnitCclRegister(); 01526 01528 01529 #endif // !__UNIT_H__