_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

unit_manager.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 2007 by Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 
29 #ifndef __UNITMANAGER_H__
30 #define __UNITMANAGER_H__
31 
33 
34 /*----------------------------------------------------------------------------
35 -- Includes
36 ----------------------------------------------------------------------------*/
37 
38 #include <vector>
39 #include <list>
40 
41 
42 /*----------------------------------------------------------------------------
43 -- Declarations
44 ----------------------------------------------------------------------------*/
45 
46 class CUnit;
47 class CFile;
48 struct lua_State;
49 
51 {
52 public:
53  typedef std::vector<CUnit *>::iterator Iterator;
54 public:
55  CUnitManager();
56  void Init();
57 
58  CUnit *AllocUnit();
59  void ReleaseUnit(CUnit *unit);
60  void Save(CFile &file) const;
61  void Load(lua_State *Lua);
62 
63  // Following is for already allocated Unit (no specific order)
64  void Add(CUnit *unit);
65  Iterator begin();
66  Iterator end();
67  const std::vector<CUnit *> &GetUnits() const
68  {
69  return units;
70  }
71 
72  bool empty() const;
73 
75 
76  // Following is mainly for scripting
77  CUnit &GetSlotUnit(int index) const;
78  unsigned int GetUsedSlotCount() const;
79 
80 private:
81  std::vector<CUnit *> units;
82  std::vector<CUnit *> unitSlots;
83  std::list<CUnit *> releasedUnits;
84  CUnit *lastCreated;
85 };
86 
87 
88 /*----------------------------------------------------------------------------
89 -- Variables
90 ----------------------------------------------------------------------------*/
91 
92 extern CUnitManager *UnitManager;
93 
95 
96 #endif // !__UNITMANAGER_H__
CUnitManager::AllocUnit
CUnit * AllocUnit()
Definition: unit_manager.cpp:82
CUnitManager::ReleaseUnit
void ReleaseUnit(CUnit *unit)
Definition: unit_manager.cpp:107
CUnitManager::Add
void Add(CUnit *unit)
Definition: unit_manager.cpp:159
Lua
lua_State * Lua
Definition: script.cpp:68
CUnitManager::end
Iterator end()
Definition: unit_manager.cpp:144
CUnitManager::GetUsedSlotCount
unsigned int GetUsedSlotCount() const
Definition: unit_manager.cpp:134
CUnitManager::Save
void Save(CFile &file) const
Definition: unit_manager.cpp:171
CUnitManager::begin
Iterator begin()
Definition: unit_manager.cpp:139
CUnitManager::CUnitManager
CUnitManager()
Unit manager.
Definition: unit_manager.cpp:54
CUnitManager::GetSlotUnit
CUnit & GetSlotUnit(int index) const
Definition: unit_manager.cpp:129
CUnitManager
Definition: unit_manager.h:50
CUnitManager::empty
bool empty() const
Definition: unit_manager.cpp:149
CUnitManager::GetUnits
const std::vector< CUnit * > & GetUnits() const
Definition: unit_manager.h:67
CUnitManager::Iterator
std::vector< CUnit * >::iterator Iterator
Definition: unit_manager.h:53
CUnitManager::lastCreatedUnit
CUnit * lastCreatedUnit()
Definition: unit_manager.cpp:154
CUnitManager::Init
void Init()
Definition: unit_manager.cpp:61
CUnitManager::Load
void Load(lua_State *Lua)
Definition: unit_manager.cpp:187
CFile
Definition: iolib.h:102
CUnit
The big unit structure.
Definition: unit.h:135
UnitManager
CUnitManager * UnitManager
Definition: unit_manager.cpp:48
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.