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 ***************************************************************************/
22 #include "special/sprite_manager.h"
23 #include "resources.h"
25 #include "badguy_specs.h"
27 BadGuySpecsManager* badguyspecs_manager = 0;
29 BadGuySpecsManager::BadGuySpecsManager(const std::string& filename)
31 load_resfile(filename);
34 BadGuySpecsManager::~BadGuySpecsManager()
36 for(std::map<std::string, BadGuySpecs*>::iterator i =
37 badguys_specs.begin(); i != badguys_specs.end(); ++i)
42 BadGuySpecsManager::load_resfile(const std::string& filename)
44 lisp_object_t* root_obj = lisp_read_from_file(filename);
47 std::cout << "BadGuySpecsManager: Couldn't load: " << filename << std::endl;
51 lisp_object_t* cur = root_obj;
53 if (strcmp(lisp_symbol(lisp_car(cur)), "supertux-badguys-specifications") != 0)
59 lisp_object_t* el = lisp_car(cur);
61 if (strcmp(lisp_symbol(lisp_car(el)), "badguy") == 0)
63 LispReader reader(lisp_cdr(lisp_car(cur)));
64 BadGuySpecs* badguy_specs = new BadGuySpecs(reader);
66 BadGuysSpecs::iterator i = badguys_specs.find(badguy_specs->get_name());
67 if (i == badguys_specs.end())
69 badguys_specs[badguy_specs->get_name()] = badguy_specs;
74 i->second = badguy_specs;
75 std::cerr << "Warning: dulpicate entry: '" << badguy_specs->get_name() << "'" << std::endl;
80 std::cout << "BadGuySpecsManager: Unknown tag" << std::endl;
90 BadGuySpecsManager::load(const std::string& name)
92 BadGuysSpecs::iterator i = badguys_specs.find(name);
93 if (i == badguys_specs.end())
95 std::cerr << "Warning: BadGuy specification '" << name << "' not found" << std::endl;
101 BadGuySpecs::BadGuySpecs(LispReader& reader)
106 reader.read_string("kind", str);
110 reader.read_string("inherits", str);
113 BadGuySpecs* bgspecs = badguyspecs_manager->load(str);
116 sprite = bgspecs->sprite;
119 std::cerr << "Warning: inherited '" << str
120 << "was not found.\nProbably, it was declared after"
121 "this entry '" << kind << std::endl;
125 reader.read_string("sprite", str);
127 std::cerr << "Warning: No sprite has been set to badguy " << kind << std::endl;
129 sprite = sprite_manager->create(str);
132 std::cerr << "Warning: Sprite '" << str << "' could not be loaded.\n";
136 BadGuySpecs::BadGuySpecs(std::string& kind_)
142 BadGuySpecs::~BadGuySpecs()
154 BadGuySpecs::get_name()