1 /***************************************************************************
2 badguy_specs.cpp - badguys properties table
5 copyright : (C) 2004 by Ricardo Cruz
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
20 #include "special/sprite_manager.h"
21 #include "resources.h"
23 #include "badguy_specs.h"
25 BadGuySpecsManager* badguyspecs_manager = 0;
27 BadGuySpecsManager::BadGuySpecsManager(const std::string& filename)
29 load_resfile(filename);
32 BadGuySpecsManager::~BadGuySpecsManager()
34 for(std::map<std::string, BadGuySpecs*>::iterator i =
35 badguys_specs.begin(); i != badguys_specs.end(); ++i)
40 BadGuySpecsManager::load_resfile(const std::string& filename)
42 lisp_object_t* root_obj = lisp_read_from_file(filename);
45 std::cout << "BadGuySpecsManager: Couldn't load: " << filename << std::endl;
49 lisp_object_t* cur = root_obj;
51 if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-badguys-specifications") != 0)
57 lisp_object_t* el = lisp_car(cur);
59 if (strcmp(lisp_symbol(lisp_car(el)), "badguy") == 0)
61 LispReader reader(lisp_cdr(lisp_car(cur)));
62 BadGuySpecs* badguy_specs = new BadGuySpecs(reader);
64 BadGuysSpecs::iterator i = badguys_specs.find(badguy_specs->get_name());
65 if (i == badguys_specs.end())
67 badguys_specs[badguy_specs->get_name()] = badguy_specs;
72 i->second = badguy_specs;
73 std::cerr << "Warning: dulpicate entry: '" << badguy_specs->get_name() << "'" << std::endl;
78 std::cout << "BadGuySpecsManager: Unknown tag" << std::endl;
88 BadGuySpecsManager::load(const std::string& name)
90 BadGuysSpecs::iterator i = badguys_specs.find(name);
91 if (i == badguys_specs.end())
93 std::cerr << "Warning: BadGuy specification '" << name << "' not found" << std::endl;
99 BadGuySpecs::BadGuySpecs(LispReader& reader)
104 reader.read_string("kind", str);
108 reader.read_string("inherits", str);
111 BadGuySpecs* bgspecs = badguyspecs_manager->load(str);
114 sprite = bgspecs->sprite;
117 std::cerr << "Warning: inherited '" << str
118 << "was not found.\nProbably, it was declared after"
119 "this entry '" << kind << std::endl;
123 reader.read_string("sprite", str);
125 std::cerr << "Warning: No sprite has been set to badguy " << kind << std::endl;
127 sprite = sprite_manager->load(str);
131 std::cerr << "Warning: Sprite '" << str << "' could not be loaded.\n";
135 BadGuySpecs::BadGuySpecs(std::string& kind_)
141 BadGuySpecs::~BadGuySpecs()
152 BadGuySpecs::get_name()