initial commit, lordsawar source, slightly modified
[lordsawar] / src / CreateScenario.cpp
1 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
2 // Copyright (C) 2003 Michael Bartl
3 // Copyright (C) 2004 John Farrell
4 // Copyright (C) 2004, 2005, 2006 Andrea Paternesi
5 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
6 // Copyright (C) 2007 Ole Laursen
7 //
8 //  This program is free software; you can redistribute it and/or modify
9 //  it under the terms of the GNU General Public License as published by
10 //  the Free Software Foundation; either version 3 of the License, or
11 //  (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU Library General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
21 //  02110-1301, USA.
22
23 #include <sstream>
24 #include <sigc++/functors/mem_fun.h>
25
26 #include "CreateScenario.h"
27 #include "GameScenario.h"
28 #include "army.h"
29 #include "GameMap.h"
30 #include "counter.h"
31 #include "player.h"
32 #include "playerlist.h"
33 #include "stacklist.h"
34 #include "citylist.h"
35 #include "city.h"
36 #include "ruinlist.h"
37 #include "ruin.h"
38 #include "rewardlist.h"
39 #include "Itemlist.h"
40 #include "templelist.h"
41 #include "temple.h"
42 #include "signpostlist.h"
43 #include "signpost.h"
44 #include "portlist.h"
45 #include "port.h"
46 #include "bridgelist.h"
47 #include "bridge.h"
48 #include "roadlist.h"
49 #include "road.h"
50 #include "armysetlist.h"
51 #include "citysetlist.h"
52 #include "real_player.h"
53 #include "ai_fast.h"
54 #include "ai_smart.h"
55 #include "ai_dummy.h"
56 #include "File.h"
57 #include "MapGenerator.h"
58 #include "QuestsManager.h"
59 #include "Configuration.h"
60 #include "FogMap.h"
61 #include "history.h"
62
63 using namespace std;
64
65 #define debug(x) {cerr<<__FILE__<<": "<<__LINE__<<": "<<x<<endl<<flush;}
66 //#define debug(x)
67
68 CreateScenario::CreateScenario(int width, int height)
69     :d_scenario(0), d_generator(0)
70 {
71     debug("CreateScenario::CreateScenario")
72    
73     //make sure that objects are deleted
74     GameMap::deleteInstance();
75     Playerlist::deleteInstance();
76     Templelist::deleteInstance();
77     Ruinlist::deleteInstance();
78     Rewardlist::deleteInstance();
79     Portlist::deleteInstance();
80     Bridgelist::deleteInstance();
81     Citylist::deleteInstance();
82     Itemlist::deleteInstance();
83
84     QuestsManager::deleteInstance();
85
86     fl_counter = new FL_Counter();
87
88     setWidth(width);
89     setHeight(height);
90
91     d_generator = new MapGenerator();
92     d_generator->progress.connect (sigc::mem_fun(*this, &CreateScenario::on_progress));
93 }
94
95 CreateScenario::~CreateScenario()
96 {
97     debug("CreateScenario::~CreateScenario")
98
99     if (d_generator)
100         delete d_generator;
101
102     if (d_scenario)
103         delete d_scenario;
104 }
105
106 void CreateScenario::on_progress(double percent, std::string description)
107 {
108   progress.emit();
109 }
110
111 void CreateScenario::setPercentages(int pgrass, int pwater, int pforest,
112                                     int pswamp, int phills, int pmountains)
113 {
114     debug("CreateScenario::setPercentages")
115
116     //handle input with !=100% sum
117     int sum = pgrass + pwater + pforest + pswamp +phills + pmountains;
118
119     if (sum != 100)
120     {
121         double factor = 100 / static_cast<double>(sum);  
122
123         pwater = static_cast<int>(pwater * factor);
124         pforest = static_cast<int>(pforest * factor);
125         pswamp = static_cast<int>(pswamp * factor);
126         phills = static_cast<int>(phills * factor);
127         pmountains = static_cast<int>(pmountains * factor);
128     }
129
130     //the multiplication doesn't round up, so the figures should be OK now, the
131     //missing percentage is implicitely added to the grass part.
132     d_generator->setPercentages(pwater, pforest, pswamp, phills, pmountains);
133 }
134
135 void CreateScenario::setMapTiles(std::string tilesname)
136 {
137     debug("CreateScenario::setMapTiles")
138     d_tilesname = tilesname;
139 }
140
141 void CreateScenario::setShieldset(std::string shieldset)
142 {
143     debug("CreateScenario::setShieldset")
144     d_shieldsname = shieldset;
145 }
146
147 void CreateScenario::setCityset(std::string citysetname)
148 {
149     debug("CreateScenario::setCityset")
150     d_citysetname = citysetname;
151     d_generator->setCityset(Citysetlist::getInstance()->getCityset(citysetname));
152 }
153
154 void CreateScenario::setNoCities(int nocities)
155 {
156     debug("CreateScenario::setNoCities")
157
158     d_generator->setNoCities(nocities);
159 }
160
161 void CreateScenario::setNoRuins(int noruins)
162 {
163     debug("CreateScenario::setNoRuins")
164
165     d_generator->setNoRuins(noruins);
166 }
167
168 void CreateScenario::setNoSignposts (int nosignposts)
169 {
170     debug("CreateScenario::setNoSignposts")
171
172     d_generator->setNoSignposts(nosignposts);
173 }
174
175 void CreateScenario::setNoTemples(int notemples)
176 {
177     debug("CreateScenario::setNoTemples")
178
179     d_generator->setNoTemples(notemples);
180 }
181
182 void CreateScenario::setWidth(int width)
183 {
184     debug("CreateScenario::setWidth")
185
186     if (width < 0)
187     {
188         std::cerr << "CreateScenario:: wrong width given\n";
189         return;
190     }
191
192     d_width = width;
193
194     //IMPORTANT!!
195     GameMap::setWidth(width);
196 }
197 void CreateScenario::setHeight(int height)
198 {
199     debug("CreateScenario::setHeight")
200
201     if (height < 0)
202     {
203         std::cerr << "CreateScenario:: wrong height given\n";
204         return;
205     }
206
207     d_height = height;
208
209     //IMPORTANT!!
210     GameMap::setHeight(height);
211 }
212
213 Player* CreateScenario::addPlayer(std::string name, guint32 armyset,
214                                 Gdk::Color color, int type)
215 {
216     debug("CreateScenario::addPlayer")
217
218     Player* p = Player::create(name, armyset, color, d_width, d_height,
219                                Player::Type(type));
220     Playerlist::getInstance()->add(p);
221
222     return p;
223 }
224
225 bool CreateScenario::addNeutral(std::string name, guint32 armyset,
226                                 Gdk::Color color, int type)
227 {
228     // for consistency, we only allow exactly one neutral player
229     if (Playerlist::getInstance()->getNeutral() != 0)
230         return false;
231
232     Player* p = addPlayer(name, armyset, color, Player::Type(type));
233     Playerlist::getInstance()->setNeutral(p);
234     return true;
235 }
236
237 int CreateScenario::getNoPlayers() const
238 {
239     return Playerlist::getInstance()->size();
240 }
241
242 Player* CreateScenario::getPlayer(int number) const
243 {
244     debug("CreateScenario::getPlayer")
245
246     if (number >= static_cast<int>(Playerlist::getInstance()->size()))
247         return 0;
248
249     Playerlist::iterator it;
250     for (it = Playerlist::getInstance()->begin(); number > 0; number--)
251         it++;
252
253     return (*it);
254 }
255
256 int CreateScenario::getNoCities() const
257 {
258     if (!d_generator)
259         return -1;
260
261     return d_generator->getNoCities();
262 }
263
264 int CreateScenario::getNoRuins() const
265 {
266     if (!d_generator)
267         return -1;
268
269     return d_generator->getNoRuins();
270 }
271
272 int CreateScenario::getNoTemples() const
273 {
274     if (!d_generator)
275         return -1;
276
277     return d_generator->getNoTemples();
278 }
279
280 bool CreateScenario::create(const GameParameters &g)
281 {
282     debug("CreateScenario::create")
283
284     d_scenario = new GameScenario("AutoGenerated", "AutoGenerated", d_turnmode);
285
286     GameScenario::s_see_opponents_stacks = g.see_opponents_stacks;
287     GameScenario::s_see_opponents_production = g.see_opponents_production;
288     GameScenario::s_play_with_quests = g.play_with_quests;
289     GameScenario::s_hidden_map = g.hidden_map;
290     GameScenario::s_diplomacy = g.diplomacy;
291     GameScenario::s_cusp_of_war = g.cusp_of_war;
292     GameScenario::s_neutral_cities = g.neutral_cities;
293     GameScenario::s_razing_cities = g.razing_cities;
294     GameScenario::s_military_advisor= g.military_advisor;
295     GameScenario::s_random_turns = g.random_turns;
296     GameScenario::s_intense_combat = g.intense_combat;
297
298     if (!createMap())
299         return false;
300
301     // fog it up
302     if (GameScenario::s_hidden_map)
303       {
304         Playerlist::iterator pit = Playerlist::getInstance()->begin();
305         for (; pit != Playerlist::getInstance()->end(); pit++)
306           (*pit)->getFogMap()->fill(FogMap::CLOSED);
307       }
308
309     if (!setupTemples())
310         return false;
311     
312     int sage_factor;
313     int no_guardian_factor;
314     int stronghold_factor;
315
316     getRuinDifficulty (g.difficulty, &sage_factor, &no_guardian_factor,
317                        &stronghold_factor);
318     if (!setupRuins(GameScenario::s_play_with_quests != GameParameters::NO_QUESTING, 20, 10, 6))
319         return false;
320
321     int base_gold;
322     getBaseGold (g.difficulty, &base_gold);
323     if (!setupPlayers(g.random_turns, base_gold))
324         return false;
325
326     if (!setupItems())
327         return false;
328
329     if (!setupRoads())
330         return false;
331     
332     if (!setupBridges())
333         return false;
334     
335     if (!distributePlayers())
336         return false;
337
338     int number_of_armies_factor;
339     getCityDifficulty(g.difficulty, &number_of_armies_factor);
340     if (!setupCities(g.cities_can_produce_allies, number_of_armies_factor))
341         return false;
342
343     int signpost_ratio;
344     getSignpostDifficulty (g.difficulty, g.hidden_map, &signpost_ratio);
345     if (!setupSignposts(signpost_ratio))
346         return false;
347
348     return true;
349 }
350
351 bool CreateScenario::dump(std::string filename) const
352 {
353     debug("CreateScenario::dump")
354
355     if (d_scenario)
356         return d_scenario->saveGame(filename, "map");
357
358     return false;
359 }
360
361 bool CreateScenario::createMap()
362 {
363     debug("CreateScenario::createMap")
364
365     const Maptile::Building* map;
366     
367     Rewardlist::getInstance();
368
369     //have the generator make the map...
370     d_generator->makeMap(d_width, d_height, true);
371     
372     //...fill the terrain...
373     GameMap::getInstance(d_tilesname, d_shieldsname,
374                          d_citysetname)->fill(d_generator);
375
376     //...and create cities, temples, ruins ,signposts
377     map = d_generator->getBuildings(d_width, d_height);
378     Cityset *cityset = Citysetlist::getInstance()->getCityset(d_citysetname);
379     
380     for (int y = 0; y < d_height; y++)
381         for (int x = 0; x < d_width; x++)
382         {
383             switch (map[y*d_width + x])
384             {
385                 case Maptile::SIGNPOST:
386                     Signpostlist::getInstance()->add(new Signpost(Vector<int>(x,y)));
387                     break;
388                 case Maptile::TEMPLE:
389                     Templelist::getInstance()->add
390                       (new Temple(Vector<int>(x,y), 
391                                   cityset->getTempleTileWidth(),
392                                   popRandomTempleName()));
393                     break;
394                 case Maptile::RUIN:
395                     Ruinlist::getInstance()->add
396                       (new Ruin(Vector<int>(x,y), 
397                                 cityset->getRuinTileWidth(),
398                                 popRandomRuinName()));
399                     break;
400                 case Maptile::CITY:
401                     Citylist::getInstance()->add
402                       (new City(Vector<int>(x,y), cityset->getCityTileWidth()));
403                     break;
404                 case Maptile::ROAD:
405                     Roadlist::getInstance()->add(new Road(Vector<int>(x,y)));
406                     break;
407                 case Maptile::PORT:
408                     Portlist::getInstance()->add(new Port(Vector<int>(x,y)));
409                     break;
410                 case Maptile::BRIDGE:
411                     Bridgelist::getInstance()->add(new Bridge(Vector<int>(x,y)));
412                     break;
413                 case Maptile::NONE:
414                     break;
415             }
416         }
417     //the other details such as giving names are done later
418     
419     return true;
420 }
421
422 void CreateScenario::createCapitalCity(Player *player, City *city)
423 {
424   // distribute capitals for the players
425   city->conquer(player);
426   city->setCapitalOwner(player);
427   city->setCapital(true);
428
429   History_CityWon *item = new History_CityWon();
430   item->fillData(city);
431   player->addHistory(item);
432 }
433
434 bool CreateScenario::tooNearToOtherCapitalCities(City *c, std::list<City*> capitals, guint32 distance)
435 {
436   for (std::list<City*>::iterator it = capitals.begin(); it != capitals.end(); 
437        it++)
438     {
439       int d = dist(c->getPos(), (*it)->getPos());
440       if ((guint32) d < distance)
441         return true;
442     }
443   return false;
444 }
445
446 bool CreateScenario::distributePlayers()
447 {
448     debug("CreateScenario::distributePlayers")
449
450     Citylist* cl = Citylist::getInstance();
451     const Playerlist* pl = Playerlist::getInstance();
452
453     //okay, everyone starts out as neutral.
454     for (Citylist::iterator cit = cl->begin(); cit != cl->end(); cit++)
455       {
456         City *c = *cit;
457         if (c->isBurnt() == false)
458           c->setOwner(pl->getNeutral());
459       }
460
461     std::list<City*> capitals;
462     //now pick some equidistant cities for capitals, that aren't too close.
463     for (Playerlist::const_iterator pit = pl->begin(); pit != pl->end(); pit++)
464       {
465         int tries = 0;
466         if (*pit == pl->getNeutral())
467           continue;
468         while (1)
469           {
470             Vector<int> pos = Vector<int>(rand() % d_width, rand() % d_height);
471             City *city = Citylist::getInstance()->getNearestCity(pos);
472             if (city->isBurnt() == false && city->isCapital() == false)
473               {
474                 if (tooNearToOtherCapitalCities(city, capitals, 30) == false || 
475                     tries > 50)
476                   {
477                     createCapitalCity(*pit, city);
478                     capitals.push_back(city);
479                     break;
480                   }
481                 else
482                   tries++;
483               }
484             else
485               tries++;
486             if (tries > 100)
487               break;
488           }
489       }
490
491     return true;
492 }
493
494 bool CreateScenario::setupCities(bool cities_can_produce_allies,
495                                  int number_of_armies_factor)
496 {
497     debug("CreateScenario::setupCities")
498
499     for (Citylist::iterator it = Citylist::getInstance()->begin();
500         it != Citylist::getInstance()->end(); it++)
501     {
502         City *c = *it;
503         //1. set a reasonable cityname
504         c->setName(popRandomCityName());
505
506         //2. distribute the income a bit (TBD)
507
508         //3. set the city production
509         c->setRandomArmytypes(cities_can_produce_allies, 
510                               number_of_armies_factor);
511
512         c->setGold(getRandomCityIncome(c->isCapital()));
513     }
514
515     return true;
516 }
517
518
519 bool CreateScenario::setupRoads()
520 {
521   Roadlist* rl = Roadlist::getInstance();
522   for (Roadlist::iterator it = rl->begin(); it != rl->end(); it++)
523     (*it)->setType(calculateRoadType((*it)->getPos()));
524   return true;
525 }
526
527 bool CreateScenario::setupBridges()
528 {
529   Bridgelist* bl = Bridgelist::getInstance();
530   for (Bridgelist::iterator it = bl->begin(); it != bl->end(); it++)
531     (*it)->setType(Bridgelist::getInstance()->calculateType((*it)->getPos()));
532   return true;
533 }
534
535 bool CreateScenario::setupTemples()
536 {
537     Templelist* tl = Templelist::getInstance();
538     for (Templelist::iterator it = tl->begin(); it != tl->end(); it++)
539     {
540         // set a random temple type
541         int type= (int) ((TEMPLE_TYPES*1.0) * (rand() / (RAND_MAX + 1.0)));
542         (*it)->setType(type);
543
544     }
545
546     return true;
547 }
548 bool CreateScenario::setupRuins(bool strongholds_invisible, int sage_factor,
549                                 int no_guardian_factor, int stronghold_factor)
550 {
551     debug("CreateScenario::setupRuins")
552
553     //The aim of this function is to put a strong stack as sentinel in all
554     //ruins.
555
556     for (Ruinlist::iterator it = Ruinlist::getInstance()->begin();
557         it != Ruinlist::getInstance()->end(); it++)
558     {
559         // set a random ruin type
560         if (rand() % stronghold_factor == 0) //one in six ruins is a stronghold
561           {
562             (*it)->setType(Ruin::STRONGHOLD);
563             if (strongholds_invisible == true)
564               {
565                 (*it)->setHidden(true);
566                 (*it)->setOwner(NULL);
567               }
568           }
569         else
570           (*it)->setType(Ruin::RUIN);
571
572         //one in twenty ruins is a sage
573         if (rand() % sage_factor == 0 && (*it)->getType() == Ruin::RUIN) 
574           {
575             (*it)->setSage (true);
576             continue;
577           }
578
579
580         //one in ten ruins doesn't have a guardian
581         if (rand() % no_guardian_factor == 0 && (*it)->getType() == Ruin::RUIN) 
582           continue;
583
584         // and set a guardian
585         Stack* s;
586         Army* a = 0;
587         Vector<int> pos = (*it)->getPos();
588         
589         a = getRandomRuinKeeper(Playerlist::getInstance()->getNeutral());
590         if (a)
591           {
592             //create a stack:
593             s = new Stack(0, pos);
594             
595             s->push_back(a);
596             a = 0;
597
598             //now mark this stack as guard
599             (*it)->setOccupant(s);
600           }
601     }
602
603     return true;
604 }
605
606 bool CreateScenario::setupSignposts(int ratio)
607 {
608     int randno;
609     int dynamicPercent = static_cast<int>(1.0 / ratio * 100);
610     debug("CreateScenario::setupSignposts")
611     Signpostlist *sl = Signpostlist::getInstance();
612
613     for (Signpostlist::iterator it = sl->begin(); it != sl->end(); it++)
614     {
615         if (randomSignpostsEmpty())
616             randno = dynamicPercent;
617         else
618             randno = rand() % 100;
619         if (randno < dynamicPercent)
620         {
621             // set up a signpost from the list of signposts
622             (*it)->setName(popRandomSignpost());
623         }
624         else
625         {
626             (*it)->setName(getDynamicSignpost(*it));
627         }
628     }
629
630     return true;
631 }
632
633 bool CreateScenario::setupPlayers(bool random_turns, 
634                                   int base_gold)
635 {
636     debug("CreateScenario::setupPlayers")
637
638     Playerlist *pl = Playerlist::getInstance();
639
640     // Give players some gold to start with
641     for (Playerlist::iterator pit = pl->begin(); pit != pl->end(); pit++)
642       (*pit)->setGold(adjustBaseGold(base_gold));
643
644
645     if (random_turns)
646       pl->randomizeOrder();
647     return true;
648 }
649
650 bool CreateScenario::setupItems()
651 {
652   Itemlist::createStandardInstance();
653   return true;
654 }
655
656 void CreateScenario::getRuinDifficulty (int difficulty, int *sage_factor, 
657                                         int *no_guardian_factor, 
658                                         int *stronghold_factor)
659 {
660   if (difficulty < 50)
661     {
662       *sage_factor = 3;
663       *no_guardian_factor = 5;
664       *stronghold_factor = 12;
665     }
666   else if (difficulty < 60)
667     {
668       *sage_factor = 9;
669       *no_guardian_factor = 6;
670       *stronghold_factor = 10;
671     }
672   else if (difficulty < 70)
673     {
674       *sage_factor = 14;
675       *no_guardian_factor = 8;
676       *stronghold_factor = 9;
677     }
678   else if (difficulty < 80)
679     {
680       *sage_factor = 20;
681       *no_guardian_factor = 10;
682       *stronghold_factor = 6;
683     }
684   else if (difficulty < 90)
685     {
686       *sage_factor = 22;
687       *no_guardian_factor = 12;
688       *stronghold_factor = 4;
689     }
690   else 
691     {
692       *sage_factor = 24;
693       *no_guardian_factor = 15;
694       *stronghold_factor = 3;
695     }
696 }
697     
698 void CreateScenario::getSignpostDifficulty (int difficulty, bool hidden_map, 
699                                             int *signpost_ratio)
700 {
701   //the idea here is that we're on a hidden map, and if it's harder
702   //difficulty, then we don't get as many signs directing us to cities.
703   if (hidden_map)
704     {
705       if (difficulty < 60)
706         *signpost_ratio = 2; //50% of signs point to cities
707       else if (difficulty < 70)
708         *signpost_ratio = 3; //33% of signs point to cities
709       else if (difficulty < 80)
710         *signpost_ratio = 6; //16% of signs point to cities
711       else if (difficulty < 90)
712         *signpost_ratio = 9; //11% of signs point to cities
713       else
714         *signpost_ratio = 15; //6% of signs point to cities
715     }
716   else
717     *signpost_ratio = 6;
718 }
719
720     
721 void CreateScenario::getCityDifficulty(int difficulty, 
722                                        int *number_of_armies_factor)
723 {
724   if (difficulty < 50)
725     *number_of_armies_factor = 3;
726   else if (difficulty < 60)
727     *number_of_armies_factor = 2;
728   else if (difficulty < 70)
729     *number_of_armies_factor = 1;
730   else 
731     *number_of_armies_factor = 0;
732 }
733     
734 int CreateScenario::calculateRoadType (Vector<int> t)
735 {
736     Roadlist *rl = Roadlist::getInstance();
737     Bridgelist *bl = Bridgelist::getInstance();
738
739     // examine neighbour tiles to discover whether there's a road or
740     // bridge on them
741     bool u = false; //up
742     bool b = false; //bottom
743     bool l = false; //left
744     bool r = false; //right
745
746     if (t.y > 0)
747       u = rl->getObjectAt(t + Vector<int>(0, -1));
748     if (t.y < GameMap::getHeight() - 1)
749       b = rl->getObjectAt(t + Vector<int>(0, 1));
750     if (t.x > 0)
751       l = rl->getObjectAt(t + Vector<int>(-1, 0));
752     if (t.x < GameMap::getWidth() - 1)
753       r = rl->getObjectAt(t + Vector<int>(1, 0));
754
755     if (!u && t.y > 0)
756       u = bl->getObjectAt(t + Vector<int>(0, -1));
757     if (!b && t.y < GameMap::getHeight() - 1)
758       b = bl->getObjectAt(t + Vector<int>(0, 1));
759     if (!l && t.x > 0)
760       l = bl->getObjectAt(t + Vector<int>(-1, 0));
761     if (!r && t.x < GameMap::getWidth() - 1)
762       r = bl->getObjectAt(t + Vector<int>(1, 0));
763
764     // then translate this to the type
765     int type = 2; 
766     //show road type 2 when no other road tiles are around
767     if (!u && !b && !l && !r)
768         type = 2;
769     else if (u && b && l && r)
770         type = 2;
771     else if (!u && b && l && r)
772         type = 9;
773     else if (u && !b && l && r)
774         type = 8;
775     else if (u && b && !l && r)
776         type = 7;
777     else if (u && b && l && !r)
778         type = 10;
779     else if (u && b && !l && !r)
780         type = 1;
781     else if (!u && !b && l && r)
782         type = 0;
783     else if (u && !b && l && !r)
784         type = 3;
785     else if (u && !b && !l && r)
786         type = 4;
787     else if (!u && b && l && !r)
788         type = 6;
789     else if (!u && b && !l && r)
790         type = 5;
791     else if (u && !b && !l && !r)
792         type = Road::CONNECTS_NORTH;
793     else if (!u && b && !l && !r)
794         type = Road::CONNECTS_SOUTH;
795     else if (!u && !b && l && !r)
796         type = Road::CONNECTS_WEST;
797     else if (!u && !b && !l && r)
798         type = Road::CONNECTS_EAST;
799     return type;
800 }
801
802 int CreateScenario::calculateNumberOfSignposts(int width, int height, int grass)
803 {
804   int area = width * height;
805   return int(area * (grass / 100.0) * SIGNPOST_FREQUENCY);
806 }