1 /*
2  * Copyright (C) 2006-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  */
19 
20 #include "map_io/tribes_legacy_lookup_table.h"
21 
22 // Whenever we break savegame compatibility, we can empty these maps
TribesLegacyLookupTable()23 TribesLegacyLookupTable::TribesLegacyLookupTable()
24    :  // Workers
25      workers_{},
26      // Wares
27      wares_{
28         {"thatch_reed", "reed"},
29      },
30      // Immovables
31      immovables_{
32         {"field_medium", "wheatfield_medium"},
33         {"field_small", "wheatfield_small"},
34         {"field_tiny", "wheatfield_tiny"},
35         {"field_ripe", "wheatfield_ripe"},
36         {"field_harvested", "wheatfield_harvested"},
37         {"reed_medium", "reedfield_medium"},
38         {"reed_small", "reedfield_small"},
39         {"reed_tiny", "reedfield_tiny"},
40         {"reed_ripe", "reedfield_ripe"},
41      },
42      // Buildings
43      buildings_{},
44      // Ships
45      ships_{},
46      // Working Programs
47      programs_{} {
48 }
49 
lookup_worker(const std::string & worker) const50 const std::string& TribesLegacyLookupTable::lookup_worker(const std::string& worker) const {
51 	return lookup_entry(worker, workers_);
52 }
53 
lookup_ware(const std::string & ware) const54 const std::string& TribesLegacyLookupTable::lookup_ware(const std::string& ware) const {
55 	return lookup_entry(ware, wares_);
56 }
57 
lookup_immovable(const std::string & immovable) const58 const std::string& TribesLegacyLookupTable::lookup_immovable(const std::string& immovable) const {
59 	return lookup_entry(immovable, immovables_);
60 }
61 
lookup_building(const std::string & building) const62 const std::string& TribesLegacyLookupTable::lookup_building(const std::string& building) const {
63 	return lookup_entry(building, buildings_);
64 }
65 
lookup_ship(const std::string & ship) const66 const std::string& TribesLegacyLookupTable::lookup_ship(const std::string& ship) const {
67 	return lookup_entry(ship, ships_);
68 }
69 
lookup_program(const std::string & program) const70 const std::string& TribesLegacyLookupTable::lookup_program(const std::string& program) const {
71 	return lookup_entry(program, programs_);
72 }
73 
74 const std::string&
lookup_entry(const std::string & entry,const std::map<std::string,std::string> & table) const75 TribesLegacyLookupTable::lookup_entry(const std::string& entry,
76                                       const std::map<std::string, std::string>& table) const {
77 	const auto& i = table.find(entry);
78 	if (i != table.end()) {
79 		return i->second;
80 	}
81 	return entry;
82 }
83