More work on the login system, especially 'tangible.redirect'
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user