1
2 /* Battle Tanks Game
3 * Copyright (C) 2006-2009 Battle Tanks team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 /*
21 * Additional rights can be granted beyond the GNU General Public License
22 * on the terms provided in the Exception. If you modify this file,
23 * you may extend this exception to your version of the file,
24 * but you are not obligated to do so. If you do not wish to provide this
25 * exception without modification, you must delete this exception statement
26 * from your version and license this file solely under the GPL without exception.
27 */
28 #include "vehicle_traits.h"
29 #include "config.h"
30 #include "mrt/exception.h"
31
getWeaponCapacity(int & max_n,int & max_v,const std::string & vehicle,const std::string & object,const std::string & type)32 void VehicleTraits::getWeaponCapacity(int &max_n, int &max_v, const std::string &vehicle, const std::string &object, const std::string &type) {
33 if (object.empty()) {
34 max_n = 0;
35 max_v = 0;
36 return;
37 }
38
39 if (vehicle.empty() || object.empty() || type.empty())
40 throw_ex(("vehicle(%s)/object(%s)/type(%s) cannot be empty", vehicle.c_str(), object.c_str(),type.c_str()));
41
42 if (object != "missiles" && object != "mines")
43 throw_ex(("`weapon` must be missiles or mines."));
44
45 const std::string key = "objects." + type + "-" + object + "-on-" + vehicle;
46
47 int def_cap = 10;
48 int def_v = 1;
49
50 if (vehicle == "launcher") {
51 def_v = (type == "nuke" || type == "mutagen")?2:3;
52 if (type == "guided")
53 def_cap = 15;
54 else if (type == "nuke")
55 def_cap = 4;
56 else if (type == "stun")
57 def_cap = 6;
58 else if (type == "mutagen")
59 def_cap = 3;
60
61 } else if (vehicle == "tank") {
62 if (type == "nuke" || type == "mutagen")
63 def_cap = 3;
64 else if (type == "boomerang")
65 def_cap = 6;
66 else if (type == "dumb")
67 def_cap = 8;
68 else if (type == "stun")
69 def_cap = 4;
70
71 } else if (vehicle == "boat") {
72 def_v = (type == "nuke")?2:3;
73 def_cap = 5;
74 }
75
76 Config->get(key + ".capacity", max_n, def_cap);
77
78 Config->get(key + ".visible-amount", max_v, def_v);
79 }
80