~widelands-dev/widelands/trunk

« back to all changes in this revision

Viewing changes to src/logic/buildcost.cc

  • Committer: Nicolai Hähnle
  • Date: 2010-10-31 12:50:41 UTC
  • mto: (5614.3.1 campaigns)
  • mto: This revision was merged to the branch mainline in revision 5692.
  • Revision ID: prefect_@gmx.net-20101031125041-z0qh421qs7gjix50
Initial cut of ship construction, untested, without proper savegame support

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 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 "buildcost.h"
 
21
 
 
22
#include "profile.h"
 
23
#include "tribe.h"
 
24
#include "wexception.h"
 
25
 
 
26
namespace Widelands {
 
27
 
 
28
void Buildcost::parse(const Tribe_Descr & tribe, Section & buildcost_s)
 
29
{
 
30
        while (Section::Value const * const val = buildcost_s.get_next_val())
 
31
                try {
 
32
                        if (Ware_Index const idx = tribe.ware_index(val->get_name())) {
 
33
                                if (count(idx))
 
34
                                        throw wexception
 
35
                                                ("a buildcost item of this ware type has already been "
 
36
                                                 "defined");
 
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));
 
41
                        } else
 
42
                                throw wexception
 
43
                                        ("tribe does not define a ware type with this name");
 
44
                } catch (_wexception const & e) {
 
45
                        throw wexception
 
46
                                ("[buildcost] \"%s=%s\": %s",
 
47
                                 val->get_name(), val->get_string(), e.what());
 
48
                }
 
49
}
 
50
 
 
51
} // namespace Widelands