2
* Copyright (C) 2010 by the Widelands Development Team
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.
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.
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.
20
#include "buildcost.h"
24
#include "wexception.h"
28
void Buildcost::parse(const Tribe_Descr & tribe, Section & buildcost_s)
30
while (Section::Value const * const val = buildcost_s.get_next_val())
32
if (Ware_Index const idx = tribe.ware_index(val->get_name())) {
35
("a buildcost item of this ware type has already been "
37
int32_t const value = val->get_int();
38
if (value < 1 or 255 < value)
39
throw wexception("count is out of range 1 .. 255");
40
insert(std::pair<Ware_Index, uint8_t>(idx, value));
43
("tribe does not define a ware type with this name");
44
} catch (_wexception const & e) {
46
("[buildcost] \"%s=%s\": %s",
47
val->get_name(), val->get_string(), e.what());
51
} // namespace Widelands