summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6f03ad6)
- fix some instances where worldmap wasn't saved
- added a worldmapfinish() console command
- svn:ignore cmake temporary files
SVN-Revision: 4609
(invisible-tile #t)
(script "fadeout_screen( 2 );
state.world <- \"levels/world2/worldmap.stwm\";")
(invisible-tile #t)
(script "fadeout_screen( 2 );
state.world <- \"levels/world2/worldmap.stwm\";")
)
(sprite-change
(change-on-touch #t)
)
(sprite-change
(change-on-touch #t)
(worldmap "levels/world2/worldmap.stwm")
(spawnpoint "world1")
(automatic #t)
(worldmap "levels/world2/worldmap.stwm")
(spawnpoint "world1")
(automatic #t)
+function worldmapfinish()
+{
+ save_state();
+ foreach(levelname, level in state.worlds[state.world].levels) {
+ level.solved = true;
+ }
+ update_worldmap();
+}
+
function grow()
{
sector.Tux.add_bonus("grow");
function grow()
{
sector.Tux.add_bonus("grow");
if(World::current() == NULL)
throw std::runtime_error("Can't save state without active World");
if(World::current() == NULL)
throw std::runtime_error("Can't save state without active World");
- if(WorldMap::current() != NULL)
- WorldMap::current()->save_state();
+ WorldMap::current()->save_state();
World::current()->save_state();
}
World::current()->save_state();
}
+void update_worldmap()
+{
+ using namespace WorldMapNS;
+
+ if(World::current() == NULL)
+ throw std::runtime_error("Can't save state without active World");
+
+ WorldMap::current()->load_state();
+}
+
// not added to header, function to only be used by others
// in this file
bool validate_sector_player()
// not added to header, function to only be used by others
// in this file
bool validate_sector_player()
+ * Update worldmap from worldmap state (state.world variable)
+ */
+void update_worldmap();
+
+/**
* enable/disable drawing of collision rectangles
*/
void debug_collrects(bool enable);
* enable/disable drawing of collision rectangles
*/
void debug_collrects(bool enable);
+static SQInteger update_worldmap_wrapper(HSQUIRRELVM vm)
+{
+ (void) vm;
+
+ try {
+ Scripting::update_worldmap();
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'update_worldmap'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger debug_collrects_wrapper(HSQUIRRELVM vm)
{
SQBool arg0;
static SQInteger debug_collrects_wrapper(HSQUIRRELVM vm)
{
SQBool arg0;
throw SquirrelError(v, "Couldn't register function 'save_state'");
}
throw SquirrelError(v, "Couldn't register function 'save_state'");
}
+ sq_pushstring(v, "update_worldmap", -1);
+ sq_newclosure(v, &update_worldmap_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'update_worldmap'");
+ }
+
sq_pushstring(v, "debug_collrects", -1);
sq_newclosure(v, &debug_collrects_wrapper, 0);
if(SQ_FAILED(sq_createslot(v, -3))) {
sq_pushstring(v, "debug_collrects", -1);
sq_newclosure(v, &debug_collrects_wrapper, 0);
if(SQ_FAILED(sq_createslot(v, -3))) {
WORLDMAP_SOUTH = 0x0002,
WORLDMAP_EAST = 0x0004,
WORLDMAP_WEST = 0x0008,
WORLDMAP_SOUTH = 0x0002,
WORLDMAP_EAST = 0x0004,
WORLDMAP_WEST = 0x0008,
+ WORLDMAP_DIR_MASK = 0x000f,
{
LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
{
LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
- : solved(false), auto_play(false), auto_path(true), basedir(basedir), picture_cached(false),
+ : solved(false), auto_play(false), basedir(basedir), picture_cached(false),
picture(0)
{
lisp->get("name", name);
picture(0)
{
lisp->get("name", name);
/** Script that is run when the level is successfully finished */
std::string extro_script;
/** Script that is run when the level is successfully finished */
std::string extro_script;
- /** If false, disables the auto walking after finishing a level */
- bool auto_path;
-
/** return Surface of level picture or 0 if no picture is available */
const Surface* get_picture();
/** return Surface of level picture or 0 if no picture is available */
const Surface* get_picture();
{
using namespace Scripting;
{
using namespace Scripting;
for(ScriptList::iterator i = scripts.begin();
i != scripts.end(); ++i) {
HSQOBJECT& object = *i;
for(ScriptList::iterator i = scripts.begin();
i != scripts.end(); ++i) {
HSQOBJECT& object = *i;
- if (old_level_state != level->solved && level->auto_path) {
+ if (old_level_state != level->solved) {
// Try to detect the next direction to which we should walk
// FIXME: Mostly a hack
Direction dir = D_NONE;
const Tile* tile = at(tux->get_tile_pos());
// Try to detect the next direction to which we should walk
// FIXME: Mostly a hack
Direction dir = D_NONE;
const Tile* tile = at(tux->get_tile_pos());
+ int dirdata = tile->getData() & Tile::WORLDMAP_DIR_MASK;
// first, test for crossroads
// first, test for crossroads
- if (tile->getData() & Tile::WORLDMAP_CNSE || tile->getData() && Tile::WORLDMAP_CNSW
- || tile->getData() & Tile::WORLDMAP_CNEW || tile->getData() && Tile::WORLDMAP_CSEW
- || tile->getData() & Tile::WORLDMAP_CNSEW)
+ if (dirdata == Tile::WORLDMAP_CNSE ||
+ dirdata == Tile::WORLDMAP_CNSW ||
+ dirdata == Tile::WORLDMAP_CNEW ||
+ dirdata == Tile::WORLDMAP_CSEW ||
+ dirdata == Tile::WORLDMAP_CNSEW)
- else if (tile->getData() & Tile::WORLDMAP_NORTH
+ else if (dirdata & Tile::WORLDMAP_NORTH
&& tux->back_direction != D_NORTH)
dir = D_NORTH;
&& tux->back_direction != D_NORTH)
dir = D_NORTH;
- else if (tile->getData() & Tile::WORLDMAP_SOUTH
+ else if (dirdata & Tile::WORLDMAP_SOUTH
&& tux->back_direction != D_SOUTH)
dir = D_SOUTH;
&& tux->back_direction != D_SOUTH)
dir = D_SOUTH;
- else if (tile->getData() & Tile::WORLDMAP_EAST
+ else if (dirdata & Tile::WORLDMAP_EAST
&& tux->back_direction != D_EAST)
dir = D_EAST;
&& tux->back_direction != D_EAST)
dir = D_EAST;
- else if (tile->getData() & Tile::WORLDMAP_WEST
+ else if (dirdata & Tile::WORLDMAP_WEST
&& tux->back_direction != D_WEST)
dir = D_WEST;
&& tux->back_direction != D_WEST)
dir = D_WEST;
bool enter_level = false;
if(main_controller->pressed(Controller::ACTION)
|| main_controller->pressed(Controller::JUMP)
bool enter_level = false;
if(main_controller->pressed(Controller::ACTION)
|| main_controller->pressed(Controller::JUMP)
- || main_controller->pressed(Controller::MENU_SELECT))
- enter_level = true;
+ || main_controller->pressed(Controller::MENU_SELECT)) {
+ /* some people define UP and JUMP on the same key... */
+ if(!main_controller->pressed(Controller::UP))
+ enter_level = true;
+ }
if(main_controller->pressed(Controller::PAUSE_MENU))
on_escape_press();
if(main_controller->pressed(Controller::PAUSE_MENU))
on_escape_press();
LevelTile* level = at_level();
if (level && (level->auto_play) && (!level->solved) && (!tux->is_moving())) {
enter_level = true;
LevelTile* level = at_level();
if (level && (level->auto_play) && (!level->solved) && (!tux->is_moving())) {
enter_level = true;
}
if (enter_level && !tux->is_moving())
}
if (enter_level && !tux->is_moving())
for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
LevelTile* level = *i;
for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
LevelTile* level = *i;
- if (level->solved) {
- sq_pushstring(vm, level->get_name().c_str(), -1);
- sq_newtable(vm);
+ sq_pushstring(vm, level->get_name().c_str(), -1);
+ sq_newtable(vm);
- store_bool(vm, "solved", true);
- // TODO write statistics
- // i->statistics.write(writer);
+ store_bool(vm, "solved", level->solved);
+ // TODO write statistics
+ // i->statistics.write(writer);
- sq_createslot(vm, -3);
- }