Permalink
Browse files

Added player activity related Lua-callbacks

  • Loading branch information...
ZhilkinSerg committed Jan 5, 2019
1 parent 980b56d commit 662df854b83b7858d909cbd34c08d0673f9b1374
@@ -173,6 +173,13 @@ Following Lua-callbacks exist:
- `on_mission_assignment(player_id, mission_id)` runs whenever player is assigned to mission;
- `on_mission_finished(player_id, mission_id)` runs whenever player finishes the mission.
*player activity-related*:
- `on_activity_call_do_turn_started(act_id, player_id)` runs whenever player activity turn started;
- `on_activity_call_do_turn_finished(act_id, player_id)` runs whenever player activity turn ended;
- `on_activity_call_finish_started(act_id, player_id)` runs whenever player activity finish started;
- `on_activity_call_finish_finished(act_id, player_id)` runs whenever player activity finish ended.
__Note for `player_id`:__ Value of -1 (when game is not started) or 1 (when game is started) are used for player character, values bigger than 1 are used for npcs.
*mapgen-related*:
@@ -1,6 +1,6 @@
local MOD = {
id = "lua_test_callback",
version = "2018-09-11"
version = "2019-01-06"
}
mods[MOD.id] = MOD

@@ -13,7 +13,7 @@ MOD.MessageWithLog = function(s)
end
end

MOD.on_game_loaded = function()
MOD.on_game_loaded = function()
MOD.DisplayCallbackMessages("on_game_loaded")
end

@@ -101,7 +101,23 @@ MOD.on_player_mission_finished = function(player_id, mission_id)
MOD.DisplayCallbackMessages("on_player_mission_finished", player_id, mission_id)
end

MOD.on_mapgen_finished = function(mapgen_type, mapgen_id, mapgen_coord)
MOD.on_activity_call_do_turn_started = function(act_id, player_id)
MOD.DisplayCallbackMessages("on_activity_call_do_turn_started", act_id, player_id)
end

MOD.on_activity_call_do_turn_finished = function(act_id, player_id)
MOD.DisplayCallbackMessages("on_activity_call_do_turn_finished", act_id, player_id)
end

MOD.on_activity_call_finish_started = function(act_id, player_id)
MOD.DisplayCallbackMessages("on_activity_call_finish_started", act_id, player_id)
end

MOD.on_activity_call_finish_finished = function(act_id, player_id)
MOD.DisplayCallbackMessages("on_activity_call_finish_finished", act_id, player_id)
end

MOD.on_mapgen_finished = function(mapgen_type, mapgen_id, mapgen_coord)
MOD.DisplayCallbackMessages("on_mapgen_finished", mapgen_type, mapgen_id, mapgen_coord)
end

@@ -1,4 +1,4 @@
local MOD = {
id = "lua_test_callback",
version = "2018-09-10"
version = "2019-01-06"
}
@@ -5,8 +5,10 @@

#include "activity_handlers.h"
#include "assign.h"
#include "catalua.h"
#include "debug.h"
#include "json.h"
#include "player.h"
#include "translations.h"

// activity_type functions
@@ -84,15 +86,25 @@ void activity_type::call_do_turn( player_activity *act, player *p ) const
{
const auto &pair = activity_handlers::do_turn_functions.find( id_ );
if( pair != activity_handlers::do_turn_functions.end() ) {
CallbackArgumentContainer lua_callback_args_info;
lua_callback_args_info.emplace_back( act->id().str() );
lua_callback_args_info.emplace_back( p->getID() );
lua_callback( "on_activity_call_do_turn_started", lua_callback_args_info );
pair->second( act, p );
lua_callback( "on_activity_call_do_turn_finished", lua_callback_args_info );
}
}

bool activity_type::call_finish( player_activity *act, player *p ) const
{
const auto &pair = activity_handlers::finish_functions.find( id_ );
if( pair != activity_handlers::finish_functions.end() ) {
CallbackArgumentContainer lua_callback_args_info;
lua_callback_args_info.emplace_back( act->id().str() );
lua_callback_args_info.emplace_back( p->getID() );
lua_callback( "on_activity_call_finish_started", lua_callback_args_info );
pair->second( act, p );
lua_callback( "on_activity_call_finish_finished", lua_callback_args_info );
return true;
}
return false;

0 comments on commit 662df85

Please sign in to comment.