File: resourcenet.h

package info (click to toggle)
asc 2.6.1.0-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 81,740 kB
  • sloc: cpp: 158,704; sh: 11,544; ansic: 6,736; makefile: 604; perl: 138
file content (178 lines) | stat: -rw-r--r-- 7,382 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/***************************************************************************
                          resourcenet.cpp  -  description
                             -------------------
    begin                : Tue Jan 28 2001
    copyright            : (C) 2001 by Martin Bickel
    email                : bickel@asc-hq.org
 ***************************************************************************/

/*! \file resourcenet.h
    \brief Handling the connection of buildings by pipelines, powerlines etc.
*/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef resourcenetH
 #define resourcenetH

#include "gamemap.h"

//! Base class for the management of resource networks and globally stored resources
class MapNetwork {
                static int instancesrunning;
             protected:
                GameMap* actmap;
                int pass;

                MapCoordinate startposition;

                virtual int fieldavail ( int x, int y ) = 0;
                virtual int searchfinished ( void ) = 0;
                virtual void checkvehicle ( Vehicle* v ) = 0;
                virtual void checkbuilding ( Building* b ) = 0;
                virtual int globalsearch ( void ) = 0;

                virtual void searchbuilding ( int x, int y );
                virtual void searchvehicle  ( int x, int y );
                virtual void searchfield ( int x, int y, int dir );
                void searchAllVehiclesNextToBuildings ( int player );
             public:
                enum Scope { singleField, net, wholeMap, globalPool };
                virtual void start ( int x, int y );
                MapNetwork ( GameMap* gamemap, int checkInstances = 1 );
                virtual ~MapNetwork();
           };

class ResourceNet : public MapNetwork {
               public:
                  ResourceNet ( GameMap* gamemap, int _scope = -1 ) : MapNetwork ( gamemap, _scope != 0 ), resourcetype(-1), scope(_scope) {};
               protected:
                  int resourcetype;
                  int scope;

                  virtual int fieldavail ( int x, int y );
                  virtual int globalsearch ( void ) { return scope; };
             };

class GetConnectedBuildings : public ResourceNet {
                protected:
                   void checkvehicle ( Vehicle* v ) {};
                   void checkbuilding ( Building* b ) { buildingContainer.push_back ( b ); };
                   int searchfinished ( void ) { return false; };

                public:
                   typedef vector<Building*> BuildingContainer;
                   BuildingContainer& buildingContainer;
                   GetConnectedBuildings ( BuildingContainer& buildingContainer_, GameMap* gamemap, int resourceType ) : ResourceNet ( gamemap, gamemap->isResourceGlobal(resourceType)?2:1), buildingContainer ( buildingContainer_) { resourcetype = 0; };
};

class StaticResourceNet : public ResourceNet {
               protected:
                  int need;
                  int got;
                  int queryonly;
                  int player;

                  virtual int searchfinished ( void );

              public:
                  StaticResourceNet ( GameMap* gamemap, int scope = -1 ) : ResourceNet ( gamemap, scope ) {};
                  int getresource ( int x, int y, int resource, int _need, int _queryonly, int _player, int _scope );
                       /* _scope:  0 : only this field
                                   1 : net
                                   2 : global
                       */
       };

class GetResource : public StaticResourceNet {
              protected:
                  int tributegot[3][8];
                  virtual void checkvehicle ( Vehicle* v );
                  virtual void checkbuilding ( Building* b );
                  virtual void start ( int x, int y );
              public:
                  GetResource ( GameMap* gamemap, int scope = -1 );
   };

class PutResource : public StaticResourceNet {
              protected:
                  virtual void checkbuilding ( Building* b );
                  virtual void checkvehicle ( Vehicle* v ) {};
                  virtual void start ( int x, int y );
               public:
                   PutResource ( GameMap* gamemap, int scope = -1 ) : StaticResourceNet ( gamemap, scope ) {};
   };

class PutTribute : public StaticResourceNet {
              protected:
                  int targplayer;
                  Building* startbuilding;
                  virtual void checkbuilding ( Building* b );
                  virtual void checkvehicle ( Vehicle* v ) {};
                  virtual void start ( int x, int y );
              public:
                  PutTribute ( GameMap* gamemap ) : StaticResourceNet( gamemap ) {};
                  int puttribute ( Building* start, int resource, int _queryonly, int _forplayer, int _fromplayer, int _scope );
   };


class GetResourceCapacity : public StaticResourceNet {
              protected:
                  virtual void checkbuilding ( Building* b );
                  virtual void checkvehicle ( Vehicle* v ) {};
                  virtual void start ( int x, int y );
                  virtual int searchfinished ( void ) { return 0; };
              public:
                  GetResourceCapacity( GameMap* gamemap ) : StaticResourceNet ( gamemap ) {};
   };

class ResourceChangeNet : public ResourceNet {
               protected:
                  int got;
                  int player;

                  virtual int searchfinished ( void ) { return 0; };

              public:
                  int getresource ( int x, int y, int resource, int _player, int _scope );
                       /* _scope:  0 : only this field
                                   1 : net
                                   2 : global
                       */
                  ResourceChangeNet ( GameMap* gamemap ) : ResourceNet ( gamemap ) {};

       };


class GetResourcePlus : public ResourceChangeNet {
              protected:
                  virtual void checkbuilding ( Building* b );
                  virtual void checkvehicle ( Vehicle* v );
              public:
                  GetResourcePlus ( GameMap* gamemap ) : ResourceChangeNet ( gamemap ) {};
   };

class GetResourceUsage : public ResourceChangeNet {
              protected:
                  virtual void checkbuilding ( Building* b );
                  virtual void checkvehicle ( Vehicle* v ) {};
              public:
                  GetResourceUsage ( GameMap* gamemap ) : ResourceChangeNet ( gamemap ) {};
   };

extern void transfer_all_outstanding_tribute( Player& player );

extern sigc::signal<void> tributeTransferred;

extern bool compareMapResources( GameMap* currentMap, GameMap* replaymap, int player, ASCString* log );


#endif