Advanced Strategic Command
servicing.h
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 
22 #ifndef servicingH
23 #define servicingH
24 
25 #include "../containerbase.h"
26 #include "../vehicletype.h"
27 
28 class Context;
29 
31  ContainerBase* container;
32  Resources available;
33  Resources storagelimit;
34  Resources orgAmount;
35  public:
36  ResourceWatch( ContainerBase* container );
38  sigc::signal<void, int> sigChanged;
39 
40  const Resources amount();
41  const Resources avail();
42  const Resources limit();
43  bool putResource( int resourcetype, int amount );
44  bool getResource( int resourcetype, int amount );
45  bool getResources( Resources res );
46 };
47 
48 class Transferrable: public sigc::trackable {
49  protected:
52 
56 
57  void show( const ContainerBase* unit );
58 
59  public:
61  virtual ASCString getName() = 0;
62 
67  virtual int getMax( ContainerBase* c, bool avail ) = 0;
68  virtual int getMin( ContainerBase* c, bool avail ) = 0;
69  virtual int transfer( ContainerBase* target, int delta ) = 0;
70  virtual int getAmount ( const ContainerBase* target ) = 0;
71 
72  virtual void commit( const Context& context ) = 0;
73  virtual bool isExchangable() const = 0;
74 
76  virtual int getID() = 0;
77 
80  bool setDestAmount( long amount );
81  void showAll();
82 
83  sigc::signal<void,const std::string&> sigSourceAmount;
84  sigc::signal<void,const std::string&> sigDestAmount;
85 
86  int setAmount( ContainerBase* target, int newamount );
87  void fill( ContainerBase* target );
88  void empty( ContainerBase* target );
89  virtual ~Transferrable() {};
90 };
91 
92 
93 
94 
95 
97  protected:
100 
102  virtual void ammo( ContainerBase* dest, int type ) = 0;
103  virtual void resource( ContainerBase* dest, int type, bool active ) = 0;
104  virtual void repair( ContainerBase* dest ) = 0;
105 
106  private:
107  bool serviceWeaponFits( ContainerBase* dest );
108 
109  public:
110  static const int ignoreHeight = 1;
111  static const int ignoreDistance = 2;
112  ServiceChecker( ContainerBase* src, int skipChecks = 0 );
113 
114 
115  void check( ContainerBase* dest );
116  virtual ~ServiceChecker() {};
117 };
118 
119 
121 
122  private:
123  GameMap* gamemap;
124  int checks;
125 
126  void fieldChecker( const MapCoordinate& pos );
127  void addTarget( ContainerBase* target );
128  public:
129  typedef vector<ContainerBase*> Targets;
130  protected:
132 
133  void ammo( ContainerBase* dest, int type );
134  void resource( ContainerBase* dest, int type, bool active );
135  void repair( ContainerBase* dest );
136 
137  public:
138  bool externallyAvailable();
139  static const int checkAmmo = 1;
140  static const int checkResources = 2;
141  static const int checkRepair = 4;
142 
143  ServiceTargetSearcher( ContainerBase* src, int checkFlags );
144  void startSearch();
145  const Targets& getTargets() const { return targets; };
146 };
147 
148 
149 
150 
151 class TransferHandler : public sigc::trackable, protected ServiceChecker {
152  private:
153  ResourceWatch sourceRes;
154  ResourceWatch destRes;
155  public:
157  private:
158  Transfers transfers;
159 
160  bool allowProduction;
161 
162  ContainerBase* source;
163  ContainerBase* dest;
164 
165  protected:
166  void ammo( ContainerBase* dest, int type );
167  void resource( ContainerBase* dest, int type, bool active );
168  void repair( ContainerBase* dest ) {};
169 
170  public:
171  TransferHandler( ContainerBase* src, ContainerBase* dst, int flags = 0 );
172 
175 
176  bool allowAmmoProduction( bool allow );
177  bool ammoProductionPossible();
179  void fillDest();
180  void fillDestAmmo();
181  void fillDestResource();
182  void emptyDest();
183  bool commit( const Context& context );
184 
185  sigc::signal<bool> updateRanges;
187 };
188 
189 
190 
191 #endif
192 
void fillDestAmmo()
Definition: servicing.cpp:852
bool ammoProductionPossible()
Definition: servicing.cpp:835
virtual ~ServiceChecker()
Definition: servicing.h:116
void fill(ContainerBase *target)
Definition: servicing.cpp:198
sigc::signal< void, int > sigChanged
Definition: servicing.h:38
virtual ~Transferrable()
Definition: servicing.h:89
static const int checkAmmo
Definition: servicing.h:139
bool putResource(int resourcetype, int amount)
Definition: servicing.cpp:100
virtual ASCString getName()=0
TransferHandler(ContainerBase *src, ContainerBase *dst, int flags=0)
Definition: servicing.cpp:806
static const int checkRepair
Definition: servicing.h:141
static const int checkResources
Definition: servicing.h:140
void check(ContainerBase *dest)
Definition: servicing.cpp:607
void repair(ContainerBase *dest)
Definition: servicing.cpp:727
virtual int getAmount(const ContainerBase *target)=0
virtual void resource(ContainerBase *dest, int type, bool active)=0
void ammo(ContainerBase *dest, int type)
Definition: servicing.cpp:796
bool getResource(int resourcetype, int amount)
Definition: servicing.cpp:114
bool commit(const Context &context)
Definition: servicing.cpp:877
int ignoreChecks
Definition: servicing.h:99
const Resources limit()
Definition: servicing.cpp:93
const Resources amount()
Definition: servicing.cpp:70
ContainerBase * source
Definition: servicing.h:98
void show(const ContainerBase *unit)
Definition: servicing.cpp:159
virtual int transfer(ContainerBase *target, int delta)=0
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void ammo(ContainerBase *dest, int type)
Definition: servicing.cpp:714
sigc::signal< void, const std::string & > sigSourceAmount
Definition: servicing.h:83
ServiceTargetSearcher(ContainerBase *src, int checkFlags)
Definition: servicing.cpp:734
ContainerBase * getContainer()
Definition: servicing.cpp:65
virtual void ammo(ContainerBase *dest, int type)=0
Coordinate on the twodimensional map.
Definition: typen.h:202
ResourceWatch & source
Definition: servicing.h:50
deallocating_vector< Transferrable * > Transfers
Definition: servicing.h:156
ServiceChecker(ContainerBase *src, int skipChecks=0)
Definition: servicing.cpp:602
virtual int getMin(ContainerBase *c, bool avail)=0
ContainerBase * getDstContainer()
Definition: servicing.cpp:176
A single weapon of a #Vehicletype.
Definition: vehicletype.h:100
const SingleWeapon * getServiceWeapon()
Definition: servicing.cpp:570
void fillDestResource()
Definition: servicing.cpp:860
void repair(ContainerBase *dest)
Definition: servicing.h:168
int setAmount(ContainerBase *target, int newamount)
Definition: servicing.cpp:192
const Resources avail()
Definition: servicing.cpp:76
ResourceWatch(ContainerBase *container)
Definition: servicing.cpp:53
sigc::signal< bool > updateRanges
Definition: servicing.h:185
void resource(ContainerBase *dest, int type, bool active)
Definition: servicing.cpp:801
vector< ContainerBase * > Targets
Definition: servicing.h:129
void resource(ContainerBase *dest, int type, bool active)
Definition: servicing.cpp:720
ContainerBase * getSrcContainer()
Definition: servicing.cpp:171
The parent class of Vehicle and Building; The name Container originates from Battle Isle...
Definition: containerbase.h:40
const Targets & getTargets() const
Definition: servicing.h:145
static const int ignoreDistance
Definition: servicing.h:111
bool getResources(Resources res)
Definition: servicing.cpp:124
Resources are basically the currency of ASC.
Definition: typen.h:97
virtual int getID()=0
the id is used to identify the transferrable when serializng to disk. In each service operation...
void showAll()
Definition: servicing.cpp:186
Transfers & getTransfers()
Definition: servicing.cpp:840
void empty(ContainerBase *target)
Definition: servicing.cpp:204
ResourceWatch & dest
Definition: servicing.h:51
virtual void repair(ContainerBase *dest)=0
ResourceWatch & getResourceWatch(const ContainerBase *unit)
Definition: servicing.cpp:136
Transferrable(ResourceWatch &s, ResourceWatch &d)
Definition: servicing.cpp:169
virtual void commit(const Context &context)=0
sigc::signal< void, const std::string & > sigDestAmount
Definition: servicing.h:84
bool setDestAmount(long amount)
Definition: servicing.cpp:181
virtual int getMax(ContainerBase *c, bool avail)=0
get maximum amount for that unit.
ResourceWatch & getOpposingResourceWatch(const ContainerBase *unit)
Definition: servicing.cpp:145
bool allowAmmoProduction(bool allow)
Definition: servicing.cpp:816
static const int ignoreHeight
Definition: servicing.h:110
ContainerBase * opposingContainer(const ContainerBase *unit)
Definition: servicing.cpp:150
virtual bool isExchangable() const =0
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182