initial commit, lordsawar source, slightly modified
[lordsawar] / src / historymap.cpp
1 //  Copyright (C) 2007, 2008, 2009 Ben Asselstine
2 //
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.
7 //
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.
12 //
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 
16 //  02110-1301, USA.
17
18 #include <config.h>
19
20 #include <algorithm>
21 #include <assert.h>
22
23 #include "vector.h"
24 #include "gui/image-helpers.h"
25 #include <gtkmm.h>
26 #include <gdkmm.h>
27
28 #include "historymap.h"
29 #include "city.h"
30 #include "ruin.h"
31 #include "GameMap.h"
32 #include "GraphicsCache.h"
33
34 HistoryMap::HistoryMap(LocationList<City*> *clist, LocationList<Ruin*> *rlist)
35 {
36   d_clist = clist;
37   d_rlist = rlist;
38 }
39
40 void HistoryMap::after_draw()
41 {
42     OverviewMap::after_draw();
43     drawCities();
44     drawRuins();
45     map_changed.emit(surface);
46 }
47
48 void HistoryMap::drawRuins()
49 {
50   GraphicsCache *gc = GraphicsCache::getInstance();
51
52   // Draw all cities as shields over the city location, in the colors of
53   // the players.
54   LocationList<Ruin*>::iterator it = d_rlist->begin();
55   for (; it != d_rlist->end(); it++)
56   {
57       Ruin *ruin = *it;
58       PixMask *tmp;
59       if (ruin->isVisible(Playerlist::getViewingplayer()) == false)
60         continue;
61       if (ruin->isSearched() == false)
62         continue;
63       if (ruin->isHidden() == true && ruin->getOwner() != 
64           Playerlist::getInstance()->getActiveplayer())
65         continue;
66
67       tmp = gc->getShieldPic(1, ruin->getOwner());
68       tmp = tmp->copy();
69       PixMask::scale(tmp, tmp->get_width()/2, tmp->get_height()/2);
70   
71       Vector<int> pos = (*it)->getPos();
72       pos = mapToSurface(pos);
73       tmp->blit_centered(surface, pos);
74       delete tmp;
75   }
76 }
77
78 void HistoryMap::drawCities()
79 {
80   GraphicsCache *gc = GraphicsCache::getInstance();
81
82   // Draw all cities as shields over the city location, in the colors of
83   // the players.
84   LocationList<City*>::iterator it = d_clist->begin();
85   for (; it != d_clist->end(); it++)
86   {
87       PixMask *tmp;
88       if ((*it)->isVisible(Playerlist::getViewingplayer()) == false)
89         continue;
90       if ((*it)->isBurnt() == true)
91         tmp = gc->getSmallRuinedCityPic();
92       else
93         tmp = gc->getShieldPic(0, (*it)->getOwner());
94   
95       Vector<int> pos = (*it)->getPos();
96       pos = mapToSurface(pos);
97       tmp->blit_centered(surface, pos);
98   }
99 }
100
101 void HistoryMap::updateCities (LocationList<City*> *clist, LocationList<Ruin*> *rlist)
102 {
103   d_clist = clist;
104   d_rlist = rlist;
105   draw(Playerlist::getViewingplayer());
106   after_draw();
107 }