Changed SetRoomIndex() to SetRoom()

This commit is contained in:
Kayne Ruse
2015-03-13 21:05:24 +11:00
parent d82e3a8b79
commit 4ae58550b5
2 changed files with 34 additions and 16 deletions
+8 -8
View File
@@ -54,13 +54,13 @@ function createTrigger(handle, room, x, y, script)
) )
end end
function createDoorPair(handle, roomOne, roomOneUID, Xone, Yone, roomTwo, roomTwoUID, Xtwo, Ytwo) function createDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo, Ytwo)
--create the scripts --create the scripts
local function scriptOne(entity) local function scriptOne(entity)
if entityAPI.GetType(entity) ~= "character" then return end if entityAPI.GetType(entity) ~= "character" then return end
--move the character --move the character
characterAPI.SetRoomIndex(entity, roomTwoUID) characterAPI.SetRoom(entity, roomTwo)
characterAPI.SetOrigin(entity, Xtwo, Ytwo-16) characterAPI.SetOrigin(entity, Xtwo, Ytwo-16)
networkAPI.PumpCharacterUpdate(entity) networkAPI.PumpCharacterUpdate(entity)
@@ -73,7 +73,7 @@ function createDoorPair(handle, roomOne, roomOneUID, Xone, Yone, roomTwo, roomTw
if entityAPI.GetType(entity) ~= "character" then return end if entityAPI.GetType(entity) ~= "character" then return end
--move the character --move the character
characterAPI.SetRoomIndex(entity, roomOneUID) characterAPI.SetRoom(entity, roomOne)
characterAPI.SetOrigin(entity, Xone, Yone-16) --NOTE: the 16 pixel margin for presentation characterAPI.SetOrigin(entity, Xone, Yone-16) --NOTE: the 16 pixel margin for presentation
networkAPI.PumpCharacterUpdate(entity) networkAPI.PumpCharacterUpdate(entity)
@@ -88,9 +88,9 @@ function createDoorPair(handle, roomOne, roomOneUID, Xone, Yone, roomTwo, roomTw
end end
--call the monstrosity --call the monstrosity
createDoorPair("pair 1", overworld, uidOne, 0, -64, underworld, uidTwo, 0, 0) createDoorPair("pair 1", overworld, 0, -64, underworld, 0, 0)
createDoorPair("pair 2", overworld, uidOne, 64, -64, underworld, uidTwo, 64, 0) createDoorPair("pair 2", overworld, 64, -64, underworld, 64, 0)
createDoorPair("pair 3", overworld, uidOne, 128, -64, underworld, uidTwo, 128, 0) createDoorPair("pair 3", overworld, 128, -64, underworld, 128, 0)
--[[ --[[
--simple door pair --simple door pair
@@ -100,7 +100,7 @@ createTrigger("door 1", overworld, 128, -128, function(entity)
end end
--move the character --move the character
characterAPI.SetRoomIndex(entity, uidTwo) characterAPI.SetRoom(entity, uidTwo)
characterAPI.SetOrigin(entity, 0, 0) characterAPI.SetOrigin(entity, 0, 0)
networkAPI.PumpCharacterUpdate(entity) networkAPI.PumpCharacterUpdate(entity)
end) end)
@@ -111,7 +111,7 @@ createTrigger("door 1", underworld, 128, -128, function(entity)
end end
--move the character --move the character
characterAPI.SetRoomIndex(entity, uidOne) characterAPI.SetRoom(entity, uidOne)
characterAPI.SetOrigin(entity, 0, 0) characterAPI.SetOrigin(entity, 0, 0)
networkAPI.PumpCharacterUpdate(entity) networkAPI.PumpCharacterUpdate(entity)
end) end)
+26 -8
View File
@@ -29,15 +29,10 @@
#include <stdexcept> #include <stdexcept>
static int setRoomIndex(lua_State* L) { //TODO: (0) take the room userdata as a parameter static int setRoom(lua_State* L) {
//NOTE: type-dependant calls to various API functions, see bug #43
//reverse engineer the character index //reverse engineer the character index
int characterIndex = -1; int characterIndex = -1;
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1)); CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
int roomIndex = lua_tointeger(L, 2);
RoomData* roomData = RoomManager::GetSingleton().Get(roomIndex);
CharacterManager& characterMgr = CharacterManager::GetSingleton(); CharacterManager& characterMgr = CharacterManager::GetSingleton();
for (auto& it : *characterMgr.GetContainer()) { for (auto& it : *characterMgr.GetContainer()) {
@@ -52,8 +47,31 @@ static int setRoomIndex(lua_State* L) { //TODO: (0) take the room userdata as a
throw(std::runtime_error("Lua Error: Failed to find character index by reference")); throw(std::runtime_error("Lua Error: Failed to find character index by reference"));
} }
//get the room index, depending on the parameter type
int roomIndex = -1;
RoomManager& roomMgr = RoomManager::GetSingleton();
switch(lua_type(L, 2)) {
case LUA_TNUMBER:
roomIndex = lua_tointeger(L, 2);
break;
case LUA_TLIGHTUSERDATA:
//reverse engineer the room index
for (auto& it : *roomMgr.GetContainer()) {
if (lua_touserdata(L, 2) == &it.second) {
roomIndex = it.first;
break;
}
}
break;
}
//error checking
if (roomIndex == -1) {
throw(std::runtime_error("Lua Error: Failed to find room index by reference"));
}
//send the delete & create messages //send the delete & create messages
pumpAndChangeRooms(character, lua_tointeger(L, 2), characterIndex); pumpAndChangeRooms(character, roomIndex, characterIndex);
return 0; return 0;
} }
@@ -76,7 +94,7 @@ static int getAvatar(lua_State* L) {
} }
static const luaL_Reg characterLib[] = { static const luaL_Reg characterLib[] = {
{"SetRoomIndex", setRoomIndex}, {"SetRoom", setRoom},
// {"GetOwner", getOwner}, //unusable without account API // {"GetOwner", getOwner}, //unusable without account API
{"GetHandle", getHandle}, {"GetHandle", getHandle},
{"GetAvatar", getAvatar}, {"GetAvatar", getAvatar},