Pol  Revision:cb584c9
resource.h
Go to the documentation of this file.
1 
7 #ifndef RESOURCE_H
8 #define RESOURCE_H
9 
10 #include <iosfwd>
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <time.h>
15 
16 #include "../clib/compilerspecifics.h"
17 #include "../clib/rawtypes.h"
18 #include "poltype.h"
19 #include "region.h"
20 #include "zone.h"
21 
22 namespace Pol
23 {
24 namespace Bscript
25 {
26 class BObjectImp;
27 } // namespace Bscript
28 namespace Clib
29 {
30 class ConfigElem;
31 class StreamWriter;
32 } // namespace Clib
33 namespace Realms
34 {
35 class Realm;
36 } // namespace Realms
37 } // namespace Pol
38 
39 namespace Pol
40 {
41 namespace Items
42 {
43 void remove_resources( u32 objtype, u16 amount );
44 void return_resources( u32 objtype, u16 amount );
45 }
46 namespace Core
47 {
48 class ResourceDef;
49 
50 Bscript::BObjectImp* get_harvest_difficulty( const char* resource, xcoord x, ycoord y,
51  Realms::Realm* realm, unsigned short marker );
52 Bscript::BObjectImp* harvest_resource( const char* resource, xcoord x, ycoord y,
53  Realms::Realm* realm, int b, int n );
54 
55 Bscript::BObjectImp* get_region_string( const char* resource, xcoord x, ycoord y,
56  Realms::Realm* realm, const std::string& propname );
57 
58 ResourceDef* find_resource_def( const std::string& rname );
59 void write_resources_dat( Clib::StreamWriter& sw_resource );
60 void read_resources_dat();
61 void clean_resources();
62 
63 
64 class ResourceRegion : public Region
65 {
66 public:
67  explicit ResourceRegion( Clib::ConfigElem& elem, RegionId id );
68  virtual size_t estimateSize() const POL_OVERRIDE;
69 
70  void read_data( Clib::ConfigElem& elem );
71 
73  Bscript::BObjectImp* harvest_resource( xcoord x, ycoord y, int b, int n );
74 
75  void regenerate( time_t now );
76  void write( Clib::StreamWriter& sw, const std::string& resource_name ) const;
77 
78  unsigned int tilecount_;
79  friend class ResourceDef;
80 
81 private:
82  //
83  // These are only used for depletion levels.
84  //
85  const unsigned int units_per_area_;
86  const unsigned int seconds_per_regrow_;
87  typedef std::map<unsigned int, unsigned short> Depletions;
88  Depletions depletions_;
89  time_t last_regen_;
90 
91 
92  //
93  // the following are used if resource banks are implemented.
94  //
95  unsigned int capacity_; // config
96  unsigned int units_; // data
97 };
98 
99 
100 class ResourceDef : public RegionGroup<ResourceRegion>
101 {
102 public:
103  explicit ResourceDef( const char* name );
104  void read_config( Clib::ConfigElem& elem );
105  void read_data( Clib::ConfigElem& elem );
106  virtual size_t estimateSize() const POL_OVERRIDE;
107  // void read_region( ConfigElem& elem );
108 
109  bool findmarker( xcoord x, ycoord y, Realms::Realm* realm, unsigned int objtype );
110  void regenerate( time_t now );
111  void consume( unsigned amount );
112  void produce( unsigned amount );
113  void counttiles();
114  void write( Clib::StreamWriter& sw ) const;
115 
116 protected:
117 private:
118  unsigned int initial_units_;
120  std::set<unsigned short> landtiles_;
121  std::set<unsigned short> tiles_;
122  // std::vector<ResourceRegion*> regions_;
123 };
124 }
125 }
126 #endif // RESOURCE_H
#define POL_OVERRIDE
void return_resources(u32 objtype, u16)
Definition: itemdesc.cpp:1232
Depletions depletions_
Definition: resource.h:88
Bscript::BObjectImp * harvest_resource(const char *resource, xcoord x, ycoord y, Realms::Realm *realm, int b, int n)
Definition: resource.cpp:278
unsigned int capacity_
Definition: resource.h:95
unsigned short ycoord
Definition: poltype.h:20
std::map< unsigned int, unsigned short > Depletions
Definition: resource.h:87
const unsigned int units_per_area_
Definition: resource.h:85
unsigned int initial_units_
Definition: resource.h:118
void write_resources_dat(Clib::StreamWriter &sw_resource)
Definition: resource.cpp:480
unsigned short u16
Definition: rawtypes.h:26
unsigned int units_
Definition: resource.h:96
unsigned int u32
Definition: rawtypes.h:27
unsigned int tilecount_
Definition: resource.h:78
void read_resources_dat()
Definition: resource.cpp:408
ResourceDef * find_resource_def(const std::string &rname)
Definition: resource.cpp:315
std::set< unsigned short > landtiles_
Definition: resource.h:120
void remove_resources(u32 objtype, u16)
Definition: itemdesc.cpp:1223
std::set< unsigned short > tiles_
Definition: resource.h:121
const unsigned int seconds_per_regrow_
Definition: resource.h:86
unsigned short RegionId
Definition: zone.h:23
Bscript::BObjectImp * get_region_string(const char *resource, xcoord x, ycoord y, Realms::Realm *realm, const std::string &propname)
Definition: resource.cpp:298
std::string name
Definition: osmod.cpp:943
void clean_resources()
Definition: resource.cpp:488
Bscript::BObjectImp * get_harvest_difficulty(const char *resource, xcoord x, ycoord y, Realms::Realm *realm, unsigned short marker)
Definition: resource.cpp:260
Definition: berror.cpp:12
int read_data()
Definition: uimport.cpp:609
unsigned short xcoord
Definition: poltype.h:19