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

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
action_resource.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 1998-2012 by Lutz Sammer and 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 
30 #ifndef __ACTION_RESOURCE_H__
31 #define __ACTION_RESOURCE_H__
32 
33 #include "actions.h"
34 
36 
37 class COrder_Resource : public COrder
38 {
39  friend COrder *COrder::NewActionResource(CUnit &harvester, const Vec2i &pos);
40  friend COrder *COrder::NewActionResource(CUnit &harvester, CUnit &mine);
41  friend COrder *COrder::NewActionReturnGoods(CUnit &harvester, CUnit *depot);
42 
43 public:
44  COrder_Resource(CUnit &harvester) : COrder(UnitActionResource), worker(&harvester),
45  CurrentResource(0), State(0), TimeToHarvest(0), DoneHarvesting(false), Range(0)
46  {
47  Resource.Pos.x = Resource.Pos.y = -1;
48  goalPos.x = goalPos.y = -1;
49  }
50 
52 
53  virtual COrder_Resource *Clone() const { return new COrder_Resource(*this); }
54 
55  virtual bool IsValid() const;
56 
57  virtual void Save(CFile &file, const CUnit &unit) const;
58  virtual bool ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit);
59 
60  virtual void Execute(CUnit &unit);
61  virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const;
62  virtual void UpdatePathFinderData(PathFinderInput &input);
63  virtual bool OnAiHitUnit(CUnit &unit, CUnit *attacker, int /*damage*/);
64 
65 
66  int GetCurrentResource() const { return CurrentResource; }
67  Vec2i GetHarvestLocation() const;
68  bool IsGatheringStarted() const;
69  bool IsGatheringFinished() const;
70  bool IsGatheringWaiting() const;
71 private:
72  int MoveToResource_Terrain(CUnit &unit);
73  int MoveToResource_Unit(CUnit &unit);
74  int MoveToResource(CUnit &unit);
75  void UnitGotoGoal(CUnit &unit, CUnit *const goal, int state);
76  int StartGathering(CUnit &unit);
77  void LoseResource(CUnit &unit, CUnit &source);
78  int GatherResource(CUnit &unit);
79  int StopGathering(CUnit &unit);
80  int MoveToDepot(CUnit &unit);
81  bool WaitInDepot(CUnit &unit);
82  void DropResource(CUnit &unit);
83  void ResourceGiveUp(CUnit &unit);
84  bool FindAnotherResource(CUnit &unit);
85  bool ActionResourceInit(CUnit &unit);
86 private:
87  CUnitPtr worker;
88  unsigned char CurrentResource;
89  struct {
92  } Resource;
93  CUnitPtr Depot;
94  int State;
95  int TimeToHarvest;
96  bool DoneHarvesting;
97  int Range;
98 #if 1
99  // duplicate of Resource.Pos ?
100  Vec2i goalPos;
101 #endif
102 };
103 
105 
106 #endif // !__ACTION_RESOURCE_H__
virtual bool IsValid() const
Definition: action_resource.cpp:301
static COrder * NewActionReturnGoods(CUnit &harvester, CUnit *depot)
Definition: action_resource.cpp:159
unit repairing
Definition: actions.h:75
virtual bool OnAiHitUnit(CUnit &unit, CUnit *attacker, int)
Definition: action_resource.cpp:340
COrder_Resource(CUnit &harvester)
Definition: action_resource.h:44
Definition: actions.h:93
virtual void Execute(CUnit &unit)
Definition: action_resource.cpp:1227
T y
Definition: vec2i.h:43
virtual COrder_Resource * Clone() const
Definition: action_resource.h:53
The big unit structure.
Definition: unit.h:119
Definition: pathfinder.h:67
bool IsGatheringWaiting() const
Definition: action_resource.cpp:203
virtual void Save(CFile &file, const CUnit &unit) const
Definition: action_resource.cpp:227
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const
Definition: action_resource.cpp:306
static COrder * NewActionResource(CUnit &harvester, const Vec2i &pos)
Definition: action_resource.cpp:133
Definition: viewport.h:63
Definition: iolib.h:101
Vec2i GetHarvestLocation() const
Definition: action_resource.cpp:184
Definition: unitptr.h:41
T x
Definition: vec2i.h:42
CUnitPtr Mine
position for terrain resource.
Definition: action_resource.h:91
~COrder_Resource()
Definition: action_resource.cpp:208
Definition: action_resource.h:37
bool IsGatheringStarted() const
Definition: action_resource.cpp:193
virtual void UpdatePathFinderData(PathFinderInput &input)
Definition: action_resource.cpp:321
virtual bool ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit)
Definition: action_resource.cpp:257
bool IsGatheringFinished() const
Definition: action_resource.cpp:198
Vec2i Pos
Definition: action_resource.h:90
int GetCurrentResource() const
Definition: action_resource.h:66
(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.