More work on the login system, especially 'tangible.redirect'
This commit is contained in:
@@ -23,7 +23,7 @@ LuaSnap::LuaSnap() {
|
||||
}
|
||||
|
||||
LuaSnap::~LuaSnap() {
|
||||
std::cerr << "LuaSnap destructor not implemented yet" << std::endl;
|
||||
lua_close(state_);
|
||||
}
|
||||
|
||||
void LuaSnap::serialize(StreamBuffer *sb) {
|
||||
|
||||
@@ -24,6 +24,10 @@ LuaFunctionReg::List LuaFunctionReg::all() {
|
||||
|
||||
LuaFunctionReg *LuaFunctionReg::LuaFunctionRegistry;
|
||||
|
||||
bool LuaStack::ckboolean(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TBOOLEAN);
|
||||
return lua_toboolean(L_, s) ? true:false;
|
||||
}
|
||||
|
||||
lua_Integer LuaStack::ckinteger(LuaSlot s) const {
|
||||
luaL_checktype(L_, s, LUA_TNUMBER);
|
||||
|
||||
@@ -380,6 +380,7 @@ public:
|
||||
void checkboolean(LuaSlot index) const { checktype(index, LUA_TBOOLEAN); }
|
||||
void checknil(LuaSlot index) const { checktype(index, LUA_TNIL); }
|
||||
|
||||
bool ckboolean(LuaSlot s) const;
|
||||
lua_Integer ckinteger(LuaSlot s) const;
|
||||
lua_Number cknumber(LuaSlot s) const;
|
||||
std::string ckstring(LuaSlot s) const;
|
||||
|
||||
@@ -149,7 +149,7 @@ void TextGame::do_quit_command(const StringVec &cmd) {
|
||||
std::cerr << "q command (quit) takes no arguments" << std::endl;
|
||||
return;
|
||||
}
|
||||
exit(0);
|
||||
actor_id_ = 0;
|
||||
}
|
||||
|
||||
void TextGame::do_command(const StringVec &words) {
|
||||
@@ -184,6 +184,7 @@ void TextGame::run()
|
||||
console_.clear();
|
||||
while (true) {
|
||||
check_redirects();
|
||||
if (actor_id_ == 0) break;
|
||||
console_.add_stdin();
|
||||
int action = console_.action();
|
||||
if (action == LuaConsole::DO_LUA) {
|
||||
|
||||
@@ -142,6 +142,9 @@ void World::tangible_delete(lua_State *L, int64_t id) {
|
||||
|
||||
std::vector<int64_t> World::get_near(int64_t player_id, float radius, bool exclude_nowhere) {
|
||||
Tangible *player = tangible_get(player_id);
|
||||
if (player == nullptr) {
|
||||
return std::vector<int64_t>();
|
||||
}
|
||||
|
||||
// Find out where's the center of the world.
|
||||
const AnimStep &aqback = player->anim_queue_.back();
|
||||
@@ -290,8 +293,14 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a
|
||||
return;
|
||||
}
|
||||
|
||||
// Get an ID batch for the thread, and take one for the thread itself.
|
||||
// Get the actor and place. Make sure both exist.
|
||||
Tangible *tactor = tangible_get(actor_id);
|
||||
Tangible *tplace = tangible_get(place_id);
|
||||
if ((tactor == nullptr) || (tplace == nullptr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get an ID batch for the thread, and take one for the thread itself.
|
||||
int64_t id_batch = tactor->id_player_pool_.get_batch();
|
||||
int64_t tid = id_batch++;
|
||||
|
||||
@@ -525,12 +534,14 @@ LuaDefine(tangible_setclass, "c") {
|
||||
}
|
||||
|
||||
LuaDefine(tangible_delete, "c") {
|
||||
// TODO: we need some sanity checks to make sure you're not deleting
|
||||
// the current player, or anything like that.
|
||||
LuaArg tanobj;
|
||||
LuaStack LS(L, tanobj);
|
||||
World *w = World::fetch_global_pointer(L);
|
||||
Tangible *tan = w->tangible_get(L, tanobj.index());
|
||||
if (tan->is_an_actor()) {
|
||||
luaL_error(L, "Cannot delete a player using tangible.delete, use tangible.redirect instead.");
|
||||
return 0;
|
||||
}
|
||||
w->tangible_delete(L, tan->id());
|
||||
return LS.result();
|
||||
}
|
||||
@@ -595,12 +606,24 @@ LuaDefine(tangible_get, "c") {
|
||||
}
|
||||
|
||||
LuaDefine(tangible_redirect, "c") {
|
||||
LuaArg actor1, actor2;
|
||||
LuaStack LS(L, actor1, actor2);
|
||||
LuaArg actor1, actor2, bldz;
|
||||
LuaStack LS(L, actor1, actor2, bldz);
|
||||
World *w = World::fetch_global_pointer(L);
|
||||
bool bulldoze = LS.ckboolean(bldz);
|
||||
Tangible *tan1 = w->tangible_get(L, actor1.index());
|
||||
Tangible *tan2 = w->tangible_get(L, actor2.index());
|
||||
w->redirects_[tan1->id()] = tan2->id();
|
||||
if (!tan1->is_an_actor()) {
|
||||
luaL_error(L, "redirect source is not an actor");
|
||||
}
|
||||
if (LS.isnil(actor2)) {
|
||||
w->redirects_[tan1->id()] = 0;
|
||||
} else {
|
||||
Tangible *tan2 = w->tangible_get(L, actor2.index());
|
||||
tan2->be_an_actor();
|
||||
w->redirects_[tan1->id()] = tan2->id();
|
||||
}
|
||||
if (bulldoze) {
|
||||
w->tangible_delete(L, tan1->id());
|
||||
}
|
||||
return LS.result();
|
||||
}
|
||||
|
||||
|
||||
@@ -68,8 +68,9 @@ public:
|
||||
//
|
||||
int64_t id() { return plane_item_.id(); }
|
||||
|
||||
// void be_a_player();
|
||||
void update_plane_item();
|
||||
bool is_an_actor() { return id_player_pool_.fifo_enabled(); }
|
||||
void be_an_actor() { id_player_pool_.enable_fifo(); }
|
||||
};
|
||||
|
||||
class World {
|
||||
|
||||
Reference in New Issue
Block a user