1 // Copyright (C) 2008, 2009 Ben Asselstine
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "ucompose.hpp"
23 #include "CreateScenarioRandomize.h"
31 #include "armysetlist.h"
32 #include "playerlist.h"
37 #define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
40 CreateScenarioRandomize::CreateScenarioRandomize()
45 d_citynames = new NameList("citynames.xml", "city");
46 d_templenames = new NameList("templenames.xml", "temple");
47 d_ruinnames = new NameList("ruinnames.xml", "ruin");
48 d_signposts = new NameList("signposts.xml", "signpost");
52 std::cerr <<"CreateScenarioRandomize: Didn't succeed in reading object names. Aborting!\n";
57 CreateScenarioRandomize::~CreateScenarioRandomize()
59 debug("CreateScenarioRandomize::~CreateScenarioRandomize")
62 std::string CreateScenarioRandomize::popRandomCityName()
64 std::string name = d_citynames->popRandomName().c_str();
66 return City::getDefaultName();
70 void CreateScenarioRandomize::pushRandomCityName(std::string name)
72 d_citynames->push_back(name);
75 std::string CreateScenarioRandomize::popRandomRuinName()
77 std::string name = d_ruinnames->popRandomName().c_str();
79 return Ruin::getDefaultName();
83 void CreateScenarioRandomize::pushRandomRuinName(std::string name)
85 d_ruinnames->push_back(name);
88 std::string CreateScenarioRandomize::popRandomTempleName()
90 std::string name = d_templenames->popRandomName().c_str();
92 return Temple::getDefaultName();
96 void CreateScenarioRandomize::pushRandomTempleName(std::string name)
98 d_templenames->push_back(name);
101 std::string CreateScenarioRandomize::popRandomSignpost()
103 return d_signposts->popRandomName().c_str();
106 void CreateScenarioRandomize::pushRandomSignpost(std::string name)
108 d_signposts->push_back(name);
111 guint32 CreateScenarioRandomize::getRandomCityIncome(bool capital)
114 return 33 + (rand() % 8);
116 return 15 + (rand() % 12);
119 Army * CreateScenarioRandomize::getRandomRuinKeeper(Player *p)
121 Armysetlist *al = Armysetlist::getInstance();
122 const ArmyProto *a= al->getArmyset(p->getArmyset())->getRandomRuinKeeper();
124 return (new Army(*a, p));
129 std::string CreateScenarioRandomize::getDynamicSignpost(Signpost *signpost)
133 Vector<int> signpostPos = signpost->getPos();
134 City *nearCity = Citylist::getInstance()->getNearestCity(signpostPos);
135 if (nearCity == NULL)
138 Vector<int> cityPos = nearCity->getPos();
139 xdir = cityPos.x - signpostPos.x;
140 ydir = cityPos.y - signpostPos.y;
141 if (xdir >= 1 && ydir >= 1)
142 dir = _("southeast");
143 else if (xdir >= 1 && ydir == 0)
145 else if (xdir >= 1 && ydir <= -1)
146 dir = _("northeast");
147 else if (xdir == 0 && ydir >= 1)
149 else if (xdir == 0 && ydir <= -1)
151 else if (xdir <= -1 && ydir >= 1)
152 dir = _("southwest");
153 else if (xdir <= -1 && ydir == 0)
155 else if (xdir <= -1 && ydir <= -1)
156 dir = _("northwest");
157 return String::ucompose("%1 lies to the %2", nearCity->getName(), dir);
160 Reward *CreateScenarioRandomize::getNewRandomReward(bool hidden_ruins)
162 int max_reward_types = 5;
165 int num = rand() % max_reward_types;
171 reward = new Reward_Gold(Reward_Gold::getRandomGoldPieces());
174 reward = new Reward_Item(Reward_Item::getRandomItem());
178 const ArmyProto *a = Reward_Allies::randomArmyAlly();
180 reward = new Reward_Allies
181 (a, Reward_Allies::getRandomAmountOfAllies());
183 reward = new Reward_Gold(Reward_Gold::getRandomGoldPieces());
188 int x, y, width, height;
189 Reward_Map::getRandomMap(&x, &y, &width, &height);
190 reward = new Reward_Map (Vector<int>(x, y), "", height, width);
191 reward->setName(reward->getDescription());
194 case 4: //Hidden Ruin
196 Ruin *r = Reward_Ruin::getRandomHiddenRuin();
197 reward = new Reward_Ruin (r);
198 reward->setName(reward->getDescription());
204 reward->setName(reward->getDescription());
208 int CreateScenarioRandomize::adjustBaseGold (int base_gold)
210 int gold = base_gold + ((rand() % 7) - 4);
216 void CreateScenarioRandomize::getBaseGold (int difficulty, int *base_gold)
220 else if (difficulty < 60)
222 else if (difficulty < 70)
224 else if (difficulty < 80)
226 else if (difficulty < 90)
232 std::string CreateScenarioRandomize::getPlayerName(Shield::Colour id)
234 std::string name = "";
238 name = _("The Sirians");
241 name = _("Elvallie");
244 name = _("Storm Giants");
246 case Shield::LIGHT_BLUE:
247 name = _("The Selentines");
250 name = _("Grey Dwarves");
252 case Shield::DARK_BLUE:
253 name = _("Horse Lords");
256 name = _("Orcs of Kor");
259 name = _("Lord Bane");
261 case Shield::NEUTRAL:
262 name = _("Neutrals");