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

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  virtual const Vec2i GetGoalPos() const;
72 private:
73  int MoveToResource_Terrain(CUnit &unit);
74  int MoveToResource_Unit(CUnit &unit);
75  int MoveToResource(CUnit &unit);
76  void UnitGotoGoal(CUnit &unit, CUnit *const goal, int state);
77  int StartGathering(CUnit &unit);
78  void LoseResource(CUnit &unit, CUnit &source);
79  int GatherResource(CUnit &unit);
80  int StopGathering(CUnit &unit);
81  int MoveToDepot(CUnit &unit);
82  bool WaitInDepot(CUnit &unit);
83  void DropResource(CUnit &unit);
84  void ResourceGiveUp(CUnit &unit);
85  bool FindAnotherResource(CUnit &unit);
86  bool ActionResourceInit(CUnit &unit);
87 private:
88  CUnitPtr worker;
89  unsigned char CurrentResource;
90  struct {
93  } Resource;
94  CUnitPtr Depot;
95  int State;
96  int TimeToHarvest;
97  bool DoneHarvesting;
98  int Range;
99 #if 1
100  // duplicate of Resource.Pos ?
101  Vec2i goalPos;
102 #endif
103 };
104 
106 
107 #endif // !__ACTION_RESOURCE_H__
COrder_Resource::IsGatheringFinished
bool IsGatheringFinished() const
Definition: action_resource.cpp:212
CUnitPtr
Definition: unitptr.h:41
COrder_Resource::Save
virtual void Save(CFile &file, const CUnit &unit) const
Definition: action_resource.cpp:243
COrder_Resource::GetCurrentResource
int GetCurrentResource() const
Definition: action_resource.h:66
COrder_Resource::Mine
CUnitPtr Mine
position for terrain resource.
Definition: action_resource.h:92
COrder_Resource::~COrder_Resource
~COrder_Resource()
Definition: action_resource.cpp:222
COrder_Resource::Show
virtual PixelPos Show(const CViewport &vp, const PixelPos &lastScreenPos) const
Definition: action_resource.cpp:322
COrder
Definition: actions.h:94
Vec2T::y
T y
Definition: vec2i.h:43
COrder_Resource
Definition: action_resource.h:37
CViewport
Definition: viewport.h:63
COrder_Resource::Pos
Vec2i Pos
Definition: action_resource.h:91
COrder_Resource::GetHarvestLocation
Vec2i GetHarvestLocation() const
Definition: action_resource.cpp:198
Vec2T< short int >
COrder_Resource::UpdatePathFinderData
virtual void UpdatePathFinderData(PathFinderInput &input)
Definition: action_resource.cpp:337
PathFinderInput
Definition: pathfinder.h:67
COrder_Resource::COrder_Resource
COrder_Resource(CUnit &harvester)
Definition: action_resource.h:44
COrder_Resource::ParseSpecificData
virtual bool ParseSpecificData(lua_State *l, int &j, const char *value, const CUnit &unit)
Definition: action_resource.cpp:273
actions.h
COrder_Resource::GetGoalPos
virtual const Vec2i GetGoalPos() const
Definition: action_resource.cpp:1406
COrder_Resource::IsValid
virtual bool IsValid() const
Definition: action_resource.cpp:317
COrder_Resource::IsGatheringWaiting
bool IsGatheringWaiting() const
Definition: action_resource.cpp:217
COrder::NewActionReturnGoods
static COrder * NewActionReturnGoods(CUnit &harvester, CUnit *depot)
Definition: action_resource.cpp:173
UnitActionResource
@ UnitActionResource
unit repairing
Definition: actions.h:76
COrder_Resource::OnAiHitUnit
virtual bool OnAiHitUnit(CUnit &unit, CUnit *attacker, int)
Definition: action_resource.cpp:356
COrder_Resource::Execute
virtual void Execute(CUnit &unit)
Definition: action_resource.cpp:1272
Vec2T::x
T x
Definition: vec2i.h:42
COrder_Resource::IsGatheringStarted
bool IsGatheringStarted() const
Definition: action_resource.cpp:207
COrder::NewActionResource
static COrder * NewActionResource(CUnit &harvester, const Vec2i &pos)
Definition: action_resource.cpp:132
COrder_Resource::Clone
virtual COrder_Resource * Clone() const
Definition: action_resource.h:53
CFile
Definition: iolib.h:102
CUnit
The big unit structure.
Definition: unit.h:135
(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.