| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "worldmap-script.h" |
| 10 |
|
| 11 |
#include "WorldBranch.h" |
| 12 |
#include "LevelDesc.h" |
| 13 |
#include "LevelNode.h" |
| 14 |
#include "def-script.h" |
| 15 |
|
| 16 |
//----------------------------------------------------------------- |
| 17 |
inline WorldBranch * |
| 18 |
getWorld(lua_State *L) |
| 19 |
{ |
| 20 |
return dynamic_cast<WorldBranch*>(script_getLeader(L)); |
| 21 |
} |
| 22 |
|
| 23 |
//----------------------------------------------------------------- |
| 24 |
/** |
| 25 |
* void worldmap_addDesc(codename, lang, levelname, desc) |
| 26 |
*/ |
| 27 |
int |
| 28 |
script_worldmap_addDesc(lua_State *L) throw() |
| 29 |
{ |
| 30 |
BEGIN_NOEXCEPTION; |
| 31 |
const char *codename = luaL_checkstring(L, 1); |
| 32 |
const char *lang = luaL_checkstring(L, 2); |
| 33 |
const char *levelname = luaL_checkstring(L, 3); |
| 34 |
const char *desc = luaL_checkstring(L, 4); |
| 35 |
|
| 36 |
LevelDesc *dialog = new LevelDesc(lang, levelname, desc); |
| 37 |
getWorld(L)->addDesc(codename, dialog); |
| 38 |
END_NOEXCEPTION; |
| 39 |
return 0; |
| 40 |
} |
| 41 |
//----------------------------------------------------------------- |
| 42 |
/** |
| 43 |
* void branch_addNode(parent, codename, datafile, x, y, |
| 44 |
* hidden=false, poster="") |
| 45 |
*/ |
| 46 |
int |
| 47 |
script_branch_addNode(lua_State *L) throw() |
| 48 |
{ |
| 49 |
BEGIN_NOEXCEPTION; |
| 50 |
const char *parent = luaL_checkstring(L, 1); |
| 51 |
const char *codename = luaL_checkstring(L, 2); |
| 52 |
const char *datafile = luaL_checkstring(L, 3); |
| 53 |
int nodeX = luaL_checkint(L, 4); |
| 54 |
int nodeY = luaL_checkint(L, 5); |
| 55 |
bool hidden = lua_toboolean(L, 6); |
| 56 |
const char *poster = luaL_optstring(L, 7, ""); |
| 57 |
|
| 58 |
LevelNode *node = new LevelNode(codename, |
| 59 |
Path::dataReadPath(datafile), V2(nodeX, nodeY), poster); |
| 60 |
getWorld(L)->addNode(parent, node, hidden); |
| 61 |
END_NOEXCEPTION; |
| 62 |
return 0; |
| 63 |
} |
| 64 |
//----------------------------------------------------------------- |
| 65 |
/** |
| 66 |
* void branch_setEnding(codename, datafile, poster="") |
| 67 |
*/ |
| 68 |
int |
| 69 |
script_branch_setEnding(lua_State *L) throw() |
| 70 |
{ |
| 71 |
BEGIN_NOEXCEPTION; |
| 72 |
const char *codename = luaL_checkstring(L, 1); |
| 73 |
const char *datafile = luaL_checkstring(L, 2); |
| 74 |
const char *poster = luaL_optstring(L, 3, ""); |
| 75 |
|
| 76 |
LevelNode *node = new LevelNode(codename, |
| 77 |
Path::dataReadPath(datafile), V2(-1, -1), poster); |
| 78 |
getWorld(L)->setEnding(node); |
| 79 |
END_NOEXCEPTION; |
| 80 |
return 0; |
| 81 |
} |
| 82 |
//----------------------------------------------------------------- |
| 83 |
/** |
| 84 |
* void node_bestSolution(codename, moves, author) |
| 85 |
*/ |
| 86 |
int |
| 87 |
script_node_bestSolution(lua_State *L) throw() |
| 88 |
{ |
| 89 |
BEGIN_NOEXCEPTION; |
| 90 |
const char *codename = luaL_checkstring(L, 1); |
| 91 |
int moves = luaL_checkint(L, 2); |
| 92 |
const char *author = luaL_checkstring(L, 3); |
| 93 |
|
| 94 |
getWorld(L)->bestSolution(codename, moves, author); |
| 95 |
END_NOEXCEPTION; |
| 96 |
return 0; |
| 97 |
} |
| 98 |
|
| 99 |
|