-TileManager::TileManager()
-{
- std::string stwt_filename = datadir + "/images/worldmap/antarctica.stwt";
- lisp_object_t* root_obj = lisp_read_from_file(stwt_filename);
-
- if (!root_obj)
- Termination::abort("Couldn't load file", stwt_filename);
-
- if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap-tiles") == 0)
- {
- lisp_object_t* cur = lisp_cdr(root_obj);
-
- while(!lisp_nil_p(cur))
- {
- lisp_object_t* element = lisp_car(cur);
-
- if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
- {
- int id = 0;
-
- Tile* tile = new Tile;
- tile->north = tile->east = tile->south = tile->west = true;
- tile->stop = true;
- tile->auto_walk = false;
-
- LispReader reader(lisp_cdr(element));
- reader.read_int("id", id);
-
- std::string temp;
- reader.read_string("possible-directions", temp);
- if(!temp.empty())
- {
- tile->north = tile->east = tile->south = tile->west = false;
- if(temp.find("north") != std::string::npos)
- tile->north = true;
- if(temp.find("south") != std::string::npos)
- tile->south = true;
- if(temp.find("east") != std::string::npos)
- tile->east = true;
- if(temp.find("west") != std::string::npos)
- tile->west = true;
- }
-
- /* For backward compatibility */
- reader.read_bool("north", tile->north);
- reader.read_bool("south", tile->south);
- reader.read_bool("west", tile->west);
- reader.read_bool("east", tile->east);
-
- reader.read_bool("stop", tile->stop);
- reader.read_bool("auto-walk", tile->auto_walk);
-
- reader.read_string("one-way", temp);
- tile->one_way = BOTH_WAYS;
- if(!temp.empty())
- {
- if(temp == "north-south")
- tile->one_way = NORTH_SOUTH_WAY;
- else if(temp == "south-north")
- tile->one_way = SOUTH_NORTH_WAY;
- else if(temp == "east-west")
- tile->one_way = EAST_WEST_WAY;
- else if(temp == "west-east")
- tile->one_way = WEST_EAST_WAY;
- }
-
- std::vector<std::string> filenames;
- reader.read_string_vector("image", filenames);
-
- if(filenames.size() == 0)
- std::cerr << "Warning: no image specified for tile " << id
- << ".\nIgnoring...\n" << std::endl;
-
- for(int i = 0; static_cast<unsigned int>(i) < filenames.size(); i++)
- {
- Surface* image = new Surface(
- datadir + "/images/worldmap/" + filenames[i], true);
- tile->images.push_back(image);
- }
-
- tile->anim_speed = 25;
- reader.read_int("anim-speed", tile->anim_speed);
-
-
- if (id >= int(tiles.size()))
- tiles.resize(id+1);
-
- tiles[id] = tile;
- }
- else
- {
- puts("Unhandled symbol");
- }
-
- cur = lisp_cdr(cur);
- }
- }
- else
- {
- assert(0);
- }
-
- lisp_free(root_obj);
-}
-
-TileManager::~TileManager()
-{
- for(std::vector<Tile*>::iterator i = tiles.begin(); i != tiles.end(); ++i)
- delete *i;
-}
-
-Tile*
-TileManager::get(int i)
-{
- assert(i >=0 && i < int(tiles.size()));
- return tiles[i];
-}
-