~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/logic/tribes/tribe_descr.cc

  • Committer: fios at foramnagaidhlig
  • Date: 2015-11-11 09:52:55 UTC
  • mto: This revision was merged to the branch mainline in revision 7621.
  • Revision ID: fios@foramnagaidhlig.net-20151111095255-i2zzpgjv5qw3yart
Renamed WareIndex to DescriptionIndex.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
                wares_order_coords_.resize(tribes_.nrwares());
87
87
                int columnindex = 0;
88
88
                for (const int key : items_table->keys<int>()) {
89
 
                        std::vector<WareIndex> column;
 
89
                        std::vector<DescriptionIndex> column;
90
90
                        std::vector<std::string> warenames = items_table->get_table(key)->array_entries<std::string>();
91
91
                        for (size_t rowindex = 0; rowindex < warenames.size(); ++rowindex) {
92
92
                                try {
93
 
                                        WareIndex wareindex = tribes_.safe_ware_index(warenames[rowindex]);
 
93
                                        DescriptionIndex wareindex = tribes_.safe_ware_index(warenames[rowindex]);
94
94
                                        if (has_ware(wareindex)) {
95
95
                                                throw GameDataError("Duplicate definition of ware '%s'", warenames[rowindex].c_str());
96
96
                                        }
111
111
                workers_order_coords_.resize(tribes_.nrworkers());
112
112
                columnindex = 0;
113
113
                for (const int key : items_table->keys<int>()) {
114
 
                        std::vector<WareIndex> column;
 
114
                        std::vector<DescriptionIndex> column;
115
115
                        std::vector<std::string> workernames = items_table->get_table(key)->array_entries<std::string>();
116
116
                        for (size_t rowindex = 0; rowindex < workernames.size(); ++rowindex) {
117
117
                                try {
118
 
                                        WareIndex workerindex = tribes_.safe_worker_index(workernames[rowindex]);
 
118
                                        DescriptionIndex workerindex = tribes_.safe_worker_index(workernames[rowindex]);
119
119
                                        if (has_worker(workerindex)) {
120
120
                                                throw GameDataError("Duplicate definition of worker '%s'", workernames[rowindex].c_str());
121
121
                                        }
140
140
                std::vector<std::string> immovables = table.get_table("immovables")->array_entries<std::string>();
141
141
                for (const std::string& immovablename : immovables) {
142
142
                        try {
143
 
                                WareIndex index = tribes_.safe_immovable_index(immovablename);
 
143
                                DescriptionIndex index = tribes_.safe_immovable_index(immovablename);
144
144
                                if (immovables_.count(index) == 1) {
145
145
                                        throw GameDataError("Duplicate definition of immovable '%s'", immovablename.c_str());
146
146
                                }
159
159
                                buildings_.push_back(index);
160
160
 
161
161
                                // Register construction materials
162
 
                                for (std::pair<WareIndex, uint8_t> build_cost : get_building_descr(index)->buildcost()) {
 
162
                                for (std::pair<DescriptionIndex, uint8_t> build_cost : get_building_descr(index)->buildcost()) {
163
163
                                        if (!is_construction_material(build_cost.first)) {
164
164
                                                construction_materials_.insert(build_cost.first);
165
165
                                        }
166
166
                                }
167
 
                                for (std::pair<WareIndex, uint8_t> enhancement_cost :
 
167
                                for (std::pair<DescriptionIndex, uint8_t> enhancement_cost :
168
168
                                          get_building_descr(index)->enhancement_cost()) {
169
169
                                        if (!is_construction_material(enhancement_cost.first)) {
170
170
                                                construction_materials_.insert(enhancement_cost.first);
210
210
size_t TribeDescr::get_nrworkers() const {return workers_.size();}
211
211
 
212
212
const std::vector<BuildingIndex>& TribeDescr::buildings() const {return buildings_;}
213
 
const std::set<WareIndex>& TribeDescr::wares() const {return wares_;}
214
 
const std::set<WareIndex>& TribeDescr::workers() const {return workers_;}
 
213
const std::set<DescriptionIndex>& TribeDescr::wares() const {return wares_;}
 
214
const std::set<DescriptionIndex>& TribeDescr::workers() const {return workers_;}
215
215
 
216
216
bool TribeDescr::has_building(const BuildingIndex& index) const {
217
217
        return std::find(buildings_.begin(), buildings_.end(), index) != buildings_.end();
218
218
}
219
 
bool TribeDescr::has_ware(const WareIndex& index) const {
 
219
bool TribeDescr::has_ware(const DescriptionIndex& index) const {
220
220
        return wares_.count(index) == 1;
221
221
}
222
 
bool TribeDescr::has_worker(const WareIndex& index) const {
 
222
bool TribeDescr::has_worker(const DescriptionIndex& index) const {
223
223
        return workers_.count(index) == 1;
224
224
}
225
225
bool TribeDescr::has_immovable(int index) const {
226
226
        return immovables_.count(index) == 1;
227
227
}
228
 
bool TribeDescr::is_construction_material(const WareIndex& index) const {
 
228
bool TribeDescr::is_construction_material(const DescriptionIndex& index) const {
229
229
        return construction_materials_.count(index) == 1;
230
230
}
231
231
 
233
233
        return tribes_.building_index(buildingname);
234
234
}
235
235
 
236
 
WareIndex TribeDescr::immovable_index(const std::string & immovablename) const {
 
236
DescriptionIndex TribeDescr::immovable_index(const std::string & immovablename) const {
237
237
        return tribes_.immovable_index(immovablename);
238
238
}
239
 
WareIndex TribeDescr::ware_index(const std::string & warename) const {
 
239
DescriptionIndex TribeDescr::ware_index(const std::string & warename) const {
240
240
        return tribes_.ware_index(warename);
241
241
}
242
 
WareIndex TribeDescr::worker_index(const std::string & workername) const {
 
242
DescriptionIndex TribeDescr::worker_index(const std::string & workername) const {
243
243
        return tribes_.worker_index(workername);
244
244
}
245
245
 
247
247
        return tribes_.safe_building_index(buildingname);
248
248
}
249
249
 
250
 
WareIndex TribeDescr::safe_ware_index(const std::string & warename) const {
 
250
DescriptionIndex TribeDescr::safe_ware_index(const std::string & warename) const {
251
251
        return tribes_.safe_ware_index(warename);
252
252
}
253
 
WareIndex TribeDescr::safe_worker_index(const std::string& workername) const {
 
253
DescriptionIndex TribeDescr::safe_worker_index(const std::string& workername) const {
254
254
        return tribes_.safe_worker_index(workername);
255
255
}
256
256
 
257
 
WareDescr const * TribeDescr::get_ware_descr(const WareIndex& index) const {
 
257
WareDescr const * TribeDescr::get_ware_descr(const DescriptionIndex& index) const {
258
258
        return tribes_.get_ware_descr(index);
259
259
}
260
 
WorkerDescr const* TribeDescr::get_worker_descr(const WareIndex& index) const {
 
260
WorkerDescr const* TribeDescr::get_worker_descr(const DescriptionIndex& index) const {
261
261
        return tribes_.get_worker_descr(index);
262
262
}
263
263
 
268
268
        return tribes_.get_immovable_descr(index);
269
269
}
270
270
 
271
 
WareIndex TribeDescr::builder() const {
 
271
DescriptionIndex TribeDescr::builder() const {
272
272
        assert(tribes_.worker_exists(builder_));
273
273
        return builder_;
274
274
}
275
 
WareIndex TribeDescr::carrier() const {
 
275
DescriptionIndex TribeDescr::carrier() const {
276
276
        assert(tribes_.worker_exists(carrier_));
277
277
        return carrier_;
278
278
}
279
 
WareIndex TribeDescr::carrier2() const {
 
279
DescriptionIndex TribeDescr::carrier2() const {
280
280
        assert(tribes_.worker_exists(carrier2_));
281
281
        return carrier2_;
282
282
}
283
 
WareIndex TribeDescr::geologist() const {
 
283
DescriptionIndex TribeDescr::geologist() const {
284
284
        assert(tribes_.worker_exists(geologist_));
285
285
        return geologist_;
286
286
}
287
 
WareIndex TribeDescr::soldier() const {
 
287
DescriptionIndex TribeDescr::soldier() const {
288
288
        assert(tribes_.worker_exists(soldier_));
289
289
        return soldier_;
290
290
}
291
 
WareIndex TribeDescr::ship() const {
 
291
DescriptionIndex TribeDescr::ship() const {
292
292
        assert(tribes_.ship_exists(ship_));
293
293
        return ship_;
294
294
}
300
300
        assert(tribes_.building_exists(port_));
301
301
        return port_;
302
302
}
303
 
const std::vector<WareIndex>& TribeDescr::worker_types_without_cost() const {
 
303
const std::vector<DescriptionIndex>& TribeDescr::worker_types_without_cost() const {
304
304
        return worker_types_without_cost_;
305
305
}
306
306
 
337
337
Find the best matching indicator for the given amount.
338
338
==============
339
339
*/
340
 
WareIndex TribeDescr::get_resource_indicator
 
340
DescriptionIndex TribeDescr::get_resource_indicator
341
341
        (ResourceDescription const * const res, uint32_t const amount) const {
342
342
        if (!res || !amount) {
343
 
                WareIndex idx = immovable_index("resi_none");
 
343
                DescriptionIndex idx = immovable_index("resi_none");
344
344
                if (!has_immovable(idx)) {
345
345
                        throw GameDataError("There is no resource indicator for resi_none!");
346
346
                }
398
398
        if (need_resize) {
399
399
                WaresOrder new_wares_order;
400
400
                for (WaresOrder::iterator it = wares_order_.begin(); it != wares_order_.end(); ++it) {
401
 
                        new_wares_order.push_back(std::vector<Widelands::WareIndex>());
402
 
                        for (std::vector<Widelands::WareIndex>::iterator it2 = it->begin(); it2 != it->end(); ++it2) {
 
401
                        new_wares_order.push_back(std::vector<Widelands::DescriptionIndex>());
 
402
                        for (std::vector<Widelands::DescriptionIndex>::iterator it2 = it->begin(); it2 != it->end(); ++it2) {
403
403
                                if (new_wares_order.rbegin()->size() >= maxLength) {
404
 
                                        new_wares_order.push_back(std::vector<Widelands::WareIndex>());
 
404
                                        new_wares_order.push_back(std::vector<Widelands::DescriptionIndex>());
405
405
                                }
406
406
                                new_wares_order.rbegin()->push_back(*it2);
407
407
                                wares_order_coords_[*it2].first = new_wares_order.size() - 1;
419
419
  * Helper functions
420
420
  */
421
421
 
422
 
WareIndex TribeDescr::add_special_worker(const std::string& workername) {
 
422
DescriptionIndex TribeDescr::add_special_worker(const std::string& workername) {
423
423
        try {
424
 
                WareIndex worker = tribes_.safe_worker_index(workername);
 
424
                DescriptionIndex worker = tribes_.safe_worker_index(workername);
425
425
                if (!has_worker(worker)) {
426
426
                        throw GameDataError("This tribe doesn't have the worker '%s'", workername.c_str());
427
427
                }