1
// $Id: PingusWorldMapGraph.cc,v 1.26 2002/01/16 23:51:00 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include <ClanLib/core.h>
21
#include <ClanLib/display.h>
23
#include "../my_gettext.hh"
24
#include "../globals.hh"
25
#include "../PingusError.hh"
26
#include "../PathManager.hh"
27
#include "../XMLPLF.hh"
28
#include "../Console.hh"
29
#include "../XMLhelper.hh"
30
#include "../StringConverter.hh"
31
#include "../PingusSound.hh"
32
#include "../PingusGameSession.hh"
33
#include "PingusWorldMapManager.hh"
34
#include "PingusWorldMapGraph.hh"
36
PingusWorldMapTubeNode::PingusWorldMapTubeNode ()
37
: worldmap_name ("pacman.xml"),
38
tube ("worldmap/tube", "core")
40
tube.set_align (-16, -32);
44
PingusWorldMapTubeNode::on_click ()
46
std::cout << "Not Supported" << std::endl;
47
PingusWorldMapManager::get_current ()->change_map (worldmap_name, link_node);
51
PingusWorldMapTubeNode::draw (CL_Vector offset)
53
tube.put_screen (pos + offset);
56
std::map<std::string, std::string>
57
PingusWorldMapTubeNode::get_string ()
59
std::map<std::string, std::string> str;
66
PingusWorldMapLevelNode::on_click ()
69
std::cout << "Start a level...: " << levelname << std::endl;
71
PingusSound::play_sound(path_manager.complete("sounds/letsgo.wav"));
72
PingusGameSession game (path_manager.complete(levelname));
74
// Launch the game and wait until it is finished
77
if (game.get_result ().finished ())
83
console.puts("Please try again!");
88
PingusWorldMapLevelNode::mark (bool value)
94
PingusWorldMapLevelNode::draw (CL_Vector offset)
96
if (!levelname.empty())
100
green_dot.put_screen (pos + offset);
102
green_flag.put_screen (pos + offset);
107
red_dot.put_screen (pos + offset);
112
std::map<std::string, std::string>
113
PingusWorldMapLevelNode::get_string ()
115
return get_plf ()->get_levelname ();
118
boost::shared_ptr<PLF>
119
PingusWorldMapLevelNode::get_plf ()
123
//console << "Loading " << levelname << std::endl;
125
plf = boost::shared_ptr<PLF> (new XMLPLF (path_manager.complete (levelname)));
126
} catch (PingusError e) {
127
std::cout << "PingusWorldMapGraph: Caught PingusError (" << e.get_message () << ")" << std::endl;
128
std::cout << "PingusWorldMapGraph: Failed to load '" << levelname << "', fallback to level1.xml" << std::endl;
129
plf = boost::shared_ptr<PLF> (new XMLPLF (path_manager.complete ("levels/level1.xml")));
136
PingusWorldMapGraph::PingusWorldMapGraph ()
138
music = "pingus-1.it";
142
PingusWorldMapGraph::~PingusWorldMapGraph ()
144
//llif (graph) delete graph;
148
PingusWorldMapGraph::parse_file (std::string filename)
150
doc = xmlParseFile(filename.c_str());
153
throw PingusError (_("PingusWorldMapGraph: File not found: ") + filename);
156
xmlNodePtr cur = doc->ROOT;
158
if (cur != NULL && strcmp((const char*)cur->name, "pingus-worldmap") == 0)
164
if (xmlIsBlankNode(cur))
170
if (strcmp ((char*)cur->name, "node-list") == 0)
172
parse_node_list (cur);
174
else if (strcmp ((char*)cur->name, "surface") == 0)
176
parse_background (cur);
178
else if (strcmp ((char*)cur->name, "music") == 0)
184
printf("PingusWorldMapGraph: Unhandled: %s\n", (char*)cur->name);
194
PingusWorldMapGraph::parse_node_list (xmlNodePtr cur)
199
if (xmlIsBlankNode(cur))
205
if (strcmp((char*)cur->name, "node") == 0)
209
else if (strcmp((char*)cur->name, "tube") == 0)
213
else if (strcmp((char*)cur->name, "comment") == 0)
219
printf("PingusWorldMapGraph:parse_node_list: Unhandled: %s\n", (char*)cur->name);
226
PingusWorldMapGraph::parse_tube (xmlNodePtr cur)
228
PingusWorldMapTubeNode* node = new PingusWorldMapTubeNode ();
230
char* id = (char*)xmlGetProp(cur, (xmlChar*)"id");
232
node->id = StringConverter::to_int (id);
234
std::cout << "PingusWorldMapGraph::parse_tube: no node 'id' given" << std::endl;
240
if (xmlIsBlankNode(cur))
246
if (strcmp((char*)cur->name, "position") == 0)
248
node->pos = XMLhelper::parse_vector (doc, cur);
250
else if (strcmp((char*)cur->name, "worldmap") == 0)
252
char* link_node = (char*)xmlGetProp(cur, (xmlChar*)"linknode");
254
from_string (link_node, node->link_node);
256
std::cout << "PingusWorldMapGraph::parse_tube: no node 'linknode' given" << std::endl;
258
node->worldmap_name = XMLhelper::parse_string (doc, cur);
260
else if (strcmp((char*)cur->name, "link") == 0)
262
char* id = (char*)xmlGetProp(cur, (xmlChar*)"id");
264
node->links.push_back(StringConverter::to_int (id));
266
std::cout << "PingusWorldMapGraph::parse_node: no id given" << std::endl;
272
nodes.push_back (boost::shared_ptr<class PingusWorldMapNode>(node));
276
PingusWorldMapGraph::parse_node (xmlNodePtr cur)
278
PingusWorldMapLevelNode* node = new PingusWorldMapLevelNode ();
280
char* id = (char*)xmlGetProp(cur, (xmlChar*)"id");
282
node->id = StringConverter::to_int (id);
284
std::cout << "PingusWorldMapGraph::parse_node: no node id given" << std::endl;
286
char* accessible = (char*)xmlGetProp(cur, (xmlChar*)"accessible");
288
node->accessible = StringConverter::to_int (accessible);
294
if (xmlIsBlankNode(cur))
300
if (strcmp((char*)cur->name, "level") == 0)
302
char* level = (char*)xmlGetProp(cur, (xmlChar*)"name");
304
node->levelname = std::string("levels/") + level;
306
std::cout << "PingusWorldMapGraph::parse_node: no levelname given" << std::endl;
308
else if (strcmp((char*)cur->name, "position") == 0)
310
node->pos = XMLhelper::parse_vector (doc, cur);
312
else if (strcmp((char*)cur->name, "link") == 0)
314
char* id = (char*)xmlGetProp(cur, (xmlChar*)"id");
316
node->links.push_back(StringConverter::to_int (id));
318
std::cout << "PingusWorldMapGraph::parse_node: no id given" << std::endl;
322
printf("PingusWorldMapGraph:parse_node: Unhandled: %s\n", (char*)cur->name);
328
nodes.push_back (boost::shared_ptr<class PingusWorldMapNode>(node));
329
// FIXME: Add the node to the graph
333
PingusWorldMapGraph::parse_background (xmlNodePtr cur)
335
bg_desc = XMLhelper::parse_surface(doc, cur);
339
PingusWorldMapGraph::parse_music (xmlNodePtr cur)
341
char* file = (char*)xmlGetProp(cur, (xmlChar*)"file");
347
std::cout << "PingusWorldMapGraph: No music file given" << std::endl;
352
PingusWorldMapGraph::get_background ()
358
PingusWorldMapGraph::get_music ()
363
/*Graph<PingusWorldMapNode>*
364
PingusWorldMapGraph::get_graph ()
370
PingusWorldMapGraph::draw (const CL_Vector& offset)
372
//float x_scale = CL_Display::get_width () / 800.0;
373
//float y_scale = CL_Display::get_height () / 600.0;
375
for (iterator i = nodes.begin();
379
for (iterator j = nodes.begin();
383
for (std::list<int>::iterator k = (*i)->links.begin();
384
k != (*i)->links.end();
387
CL_Display::draw_line ((int)((*j)->pos.x + offset.x), (int)((*j)->pos.y + offset.y),
388
(int)((*i)->pos.x + offset.x), (int)((*i)->pos.y + offset.y),
394
/* Fade out, fixme, doesn't work at the moment
395
CL_SurfaceProvider* provider = new TargetProvider (target);
396
CL_Surface* sur = CL_Surface::create (provider);
398
for (int y = 0; y < CL_Display::get_height();
399
y += CL_Display::get_height() / 40)
401
CL_System::keep_alive ();
402
CL_Display::clear_display ();
403
sur->put_screen (0, y);
404
Display::flip_display ();