25
25
#include "editorbigmap.h"
28
#include "../stacklist.h"
30
#include "../citylist.h"
31
#include "../ruinlist.h"
32
#include "../signpostlist.h"
33
#include "../templelist.h"
34
#include "../bridgelist.h"
35
#include "../portlist.h"
36
#include "../roadlist.h"
38
#include "../signpost.h"
39
#include "../temple.h"
41
#include "../playerlist.h"
44
#include "../GameMap.h"
45
#include "../Configuration.h"
46
#include "../rewardlist.h"
47
#include "../GraphicsCache.h"
48
#include "../armysetlist.h"
49
#include "../sdl-draw.h"
50
#include "../MapRenderer.h"
28
#include "stacklist.h"
32
#include "signpostlist.h"
33
#include "templelist.h"
34
#include "bridgelist.h"
41
#include "playerlist.h"
45
#include "Configuration.h"
46
#include "rewardlist.h"
47
#include "GraphicsCache.h"
48
#include "armysetlist.h"
50
#include "MapRenderer.h"
51
#include "CreateScenario.h"
53
54
EditorBigMap::EditorBigMap()
194
std::vector<Vector<int> > EditorBigMap::get_screen_tiles()
196
// find out which tiles are within bounds
197
std::vector<Vector<int> > tiles;
199
for (int y = buffer_view.y; y < buffer_view.y + buffer_view.h; y++)
200
for (int x = buffer_view.x; x < buffer_view.x + buffer_view.w; x++)
202
Vector<int> tile(x, y);
203
if (tile.x >= 0 && tile.x < GameMap::getWidth() &&
204
tile.y >= 0 && tile.y < GameMap::getHeight())
205
tiles.push_back(tile);
192
211
std::vector<Vector<int> > EditorBigMap::get_cursor_tiles()
194
213
// find out which cursor tiles are within bounds
215
234
void EditorBigMap::after_draw()
217
if (pointer == POINTER)
236
int tilesize = GameMap::getInstance()->getTileset()->getTileSize();
237
std::vector<Vector<int> > tiles;
239
if (show_tile_types_instead_of_tile_styles)
241
tiles = get_screen_tiles();
242
for (std::vector<Vector<int> >::iterator i = tiles.begin(),
243
end = tiles.end(); i != end; ++i)
245
Vector<int> pos = tile_to_buffer_pos(*i);
246
SDL_Color tc = GameMap::getInstance()->getTile(*i)->getColor();
247
const Uint32 color = SDL_MapRGB(buffer->format, tc.r, tc.g, tc.b);
248
draw_filled_rect(buffer, pos.x, pos.y,
249
pos.x + tilesize, pos.y + tilesize, color);
220
253
// we need to draw a drawing cursor on the map
222
std::vector<Vector<int> > tiles = get_cursor_tiles();
254
tiles = get_cursor_tiles();
224
255
// draw each tile
225
int tilesize = GameMap::getInstance()->getTileset()->getTileSize();
226
256
for (std::vector<Vector<int> >::iterator i = tiles.begin(),
227
257
end = tiles.end(); i != end; ++i)
287
pic = GraphicsCache::getInstance()->getRoadPic(calculateRoadType(*i));
317
pic = GraphicsCache::getInstance()->getRoadPic(CreateScenario::calculateRoadType(*i));
288
318
SDL_BlitSurface(pic, 0, buffer, &r);
352
382
void remove_from_map(T *l, Vector<int> tile)
354
384
for (typename T::iterator i = l->begin(), end = l->end(); i != end; ++i)
355
if (i->contains(tile))
385
if ((*i)->contains(tile))
357
387
// erase from map
358
388
GameMap *gamemap = GameMap::getInstance();
359
Rectangle r = i->get_area();
389
Rectangle r = (*i)->get_area();
360
390
for (int x = r.x; x < r.x + r.w; ++x)
361
391
for (int y = r.y; y < r.y + r.h; ++y)
362
392
gamemap->getTile(Vector<int>(x, y))->setBuilding(Maptile::NONE);
409
439
maptile->setType(ts->getIndex(pointer_terrain));
410
440
if (pointer_tile_style_id == -1)
412
GameMap::getInstance()->applyTileStyles(tile.y-1, tile.x-1,
442
if (pointer_terrain == Tile::MOUNTAIN)
444
GameMap *gm = GameMap::getInstance();
445
gm->surroundMountains (tile.y-1, tile.x-1,
447
gm->applyTileStyles(tile.y-2, tile.x-2,
452
GameMap::getInstance()->applyTileStyles(tile.y-1, tile.x-1,
421
461
maptile->setTileStyle (tile_style);
423
463
changed_tiles.dim = Vector<int>(1, 1);
464
//change the boatedness of stacks that might be here.
465
if (Stacklist::getObjectAt(tile))
467
Stack* s = Stacklist::getObjectAt(tile);
468
Port *port = Portlist::getInstance()->getObjectAt(tile);
469
Bridge *bridge = Bridgelist::getInstance()->getObjectAt(tile);
470
if (pointer_terrain == Tile::WATER && s->hasShip() == false &&
473
for (Stack::iterator it = s->begin(); it != s->end(); it++)
474
(*it)->setInShip(true);
476
else if (pointer_terrain != Tile::WATER && s->hasShip() == true)
478
for (Stack::iterator it = s->begin(); it != s->end(); it++)
479
(*it)->setInShip(false);
479
537
Stack* s = new Stack(p, tile);
480
538
const Armysetlist* al = Armysetlist::getInstance();
481
539
Army* a = new Army(*al->getArmy(p->getArmyset(), 0), p);
540
GameMap *gm = GameMap::getInstance();
541
if (gm->getTile(s->getPos())->getBuilding() == Maptile::PORT ||
542
gm->getTile(s->getPos())->getBuilding() == Maptile::BRIDGE)
544
else if (gm->getTile(s->getPos())->getMaptileType() ==
484
552
//if we're on a city, change the allegiance of the stack
485
553
//and it's armies to that of the city
486
GameMap *gm = GameMap::getInstance();
487
554
if (gm->getTile(s->getPos())->getBuilding() == Maptile::CITY)
489
556
Citylist *clist = Citylist::getInstance();
529
596
// create the city
531
c.setOwner(Playerlist::getInstance()->getNeutral());
597
City *c = new City(tile);
598
c->setOwner(Playerlist::getInstance()->getNeutral());
532
599
Citylist::getInstance()->push_back(c);
534
601
bool replaced_grass = false;
535
602
// notify the maptiles that a city has been placed here
536
Rectangle r = c.get_area();
603
Rectangle r = c->get_area();
537
604
for (int x = r.x; x < r.x + r.w; ++x)
538
605
for (int y = r.y; y < r.y + r.h; ++y)
547
614
//change allegiance of stacks under this city
548
for (unsigned int x = 0; x < c.getSize(); x++)
615
for (unsigned int x = 0; x < c->getSize(); x++)
550
for (unsigned int y = 0; y < c.getSize(); y++)
617
for (unsigned int y = 0; y < c->getSize(); y++)
552
Stack *s = Stacklist::getObjectAt(c.getPos().x + x,
619
Stack *s = Stacklist::getObjectAt(c->getPos().x + x,
556
if (s->getOwner() != c.getOwner())
623
if (s->getOwner() != c->getOwner())
558
625
//remove it from the old player's list of stacks
559
626
s->getOwner()->getStacklist()->remove(s);
560
627
//and give it to the new player list of stacks
561
c.getOwner()->getStacklist()->push_back(s);
628
c->getOwner()->getStacklist()->push_back(s);
562
629
//change the ownership of the stack
563
s->setOwner(c.getOwner());
630
s->setOwner(c->getOwner());
564
631
//and all of it's armies
565
632
for (Stack::iterator it = s->begin();
566
633
it != s->end(); it++)
567
(*it)->setOwner(c.getOwner());
634
(*it)->setOwner(c->getOwner());
588
655
replaced_grass = true;
589
656
maptile->setType(grass_index);
590
657
Ruin *ruin = new Ruin(tile);
591
Ruinlist::getInstance()->push_back(*ruin);
658
Ruinlist::getInstance()->push_back(ruin);
592
659
if (replaced_grass)
593
660
GameMap::getInstance()->applyTileStyles
594
661
(0, 0, GameMap::getHeight(), GameMap::getWidth(), true);
604
671
if (maptile->getMaptileType() != Tile::GRASS)
605
672
replaced_grass = true;
606
673
maptile->setType(grass_index);
607
Templelist::getInstance()->push_back(Temple(tile));
674
Templelist::getInstance()->push_back(new Temple(tile));
608
675
if (replaced_grass)
609
676
GameMap::getInstance()->applyTileStyles
610
677
(0, 0, GameMap::getHeight(), GameMap::getWidth(), true);
626
693
maptile->getTileStyle()->getType() != TileStyle::INNERMIDDLECENTER)
628
695
maptile->setBuilding(Maptile::PORT);
629
Portlist::getInstance()->push_back(Port(tile));
696
Portlist::getInstance()->push_back(new Port(tile));
697
if (Stacklist::getObjectAt(tile))
699
Stack* s = Stacklist::getObjectAt(tile);
700
if (s->hasShip() == true)
702
for (Stack::iterator it = s->begin(); it != s->end();
704
(*it)->setInShip(false);
643
720
maptile->setBuilding(Maptile::BRIDGE);
644
Bridgelist::getInstance()->push_back(Bridge(tile, type));
721
Bridgelist::getInstance()->push_back(new Bridge(tile, type));
722
if (Stacklist::getObjectAt(tile))
724
Stack* s = Stacklist::getObjectAt(tile);
725
if (s->hasShip() == true)
727
for (Stack::iterator it = s->begin(); it != s->end();
729
(*it)->setInShip(false);
646
733
changed_tiles.dim = Vector<int>(1, 1);
652
739
|| maptile->getBuilding() == Maptile::ROAD)
653
740
&& maptile->getMaptileType() != Tile::WATER)
655
int type = calculateRoadType(tile);
742
int type = CreateScenario::calculateRoadType(tile);
656
743
if (maptile->getBuilding() == Maptile::NONE)
658
745
maptile->setBuilding(Maptile::ROAD);
659
Roadlist::getInstance()->push_back(Road(tile, type));
746
Roadlist::getInstance()->push_back(new Road(tile, type));
662
749
// now reconfigure all roads in the surroundings
663
750
for (int x = tile.x - 1; x <= tile.x + 1; ++x)
664
751
for (int y = tile.y - 1; y <= tile.y + 1; ++y)
666
if (x < 0 || x >= GameMap::getWidth() &&
667
y < 0 || y >= GameMap::getHeight())
753
if ((x < 0 || x >= GameMap::getWidth()) &&
754
(y < 0 || y >= GameMap::getHeight()))
670
757
Vector<int> pos(x, y);
671
758
if (Road *r = Roadlist::getInstance()->getObjectAt(pos))
673
int newtype = calculateRoadType(pos);
760
int newtype = CreateScenario::calculateRoadType(pos);
674
761
r->setType(newtype);
694
781
view.x+view.w, true);
698
int EditorBigMap::calculateRoadType (Vector<int> t)
700
Roadlist *rl = Roadlist::getInstance();
701
Bridgelist *bl = Bridgelist::getInstance();
703
// examine neighbour tiles to discover whether there's a road or
706
bool b = false; //bottom
707
bool l = false; //left
708
bool r = false; //right
711
u = rl->getObjectAt(t + Vector<int>(0, -1));
712
if (t.y < GameMap::getHeight() - 1)
713
b = rl->getObjectAt(t + Vector<int>(0, 1));
715
l = rl->getObjectAt(t + Vector<int>(-1, 0));
716
if (t.x < GameMap::getWidth() - 1)
717
r = rl->getObjectAt(t + Vector<int>(1, 0));
720
u = bl->getObjectAt(t + Vector<int>(0, -1));
721
if (!b && t.y < GameMap::getHeight() - 1)
722
b = bl->getObjectAt(t + Vector<int>(0, 1));
724
l = bl->getObjectAt(t + Vector<int>(-1, 0));
725
if (!r && t.x < GameMap::getWidth() - 1)
726
r = bl->getObjectAt(t + Vector<int>(1, 0));
728
// then translate this to the type
730
//show road type 2 when no other road tiles are around
731
if (!u && !b && !l && !r)
733
else if (u && b && l && r)
735
else if (!u && b && l && r)
737
else if (u && !b && l && r)
739
else if (u && b && !l && r)
741
else if (u && b && l && !r)
743
else if (u && b && !l && !r)
745
else if (!u && !b && l && r)
747
else if (u && !b && l && !r)
749
else if (u && !b && !l && r)
751
else if (!u && b && l && !r)
753
else if (!u && b && !l && r)
755
else if (u && !b && !l && !r)
757
else if (!u && b && !l && !r)
759
else if (!u && !b && l && !r)
761
else if (!u && !b && !l && r)