Changeset 117:8021fffe95f1

Show
Ignore:
Timestamp:
04/24/08 19:22:17 (2 years ago)
Author:
mdoison@…
Branch:
lua
Message:

* Fix a bug : a null entity must not be able call a build callback
* Fix a bug : player package crash game at startup
* Add game hooks
* Add a time() function in luagame api

Location:
src/game
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • src/game/g_admin.c

    r59 r117  
    33053305  LogExit( va( "nextmap was run by %s", 
    33063306    ( ent ) ? ent->client->pers.netname : "console" ) ); 
     3307 
     3308  G_CallGameHooks("on_exit"); 
     3309 
    33073310  return qtrue; 
    33083311} 
  • src/game/g_buildable.c

    r113 r117  
    31963196  vec3_t    normal; 
    31973197 
    3198   if( ! G_CallPlayerHooks("on_build", builder) ) 
     3198  if( builder && ! G_CallPlayerHooks("on_build", builder) ) 
    31993199    return NULL; 
    32003200 
  • src/game/g_client.c

    r112 r117  
    13521352  CalculateRanks( ); 
    13531353  G_admin_namelog_update( client, qfalse ); 
     1354 
     1355  if( ! G_CallGameHooks("on_player_connect") ) 
     1356    return "Game refused by server"; 
     1357 
    13541358  return NULL; 
    13551359} 
     
    14191423  // count current clients and rank for scoreboard 
    14201424  CalculateRanks( ); 
     1425 
     1426  G_CallGameHooks("on_player_begin"); 
    14211427} 
    14221428 
     
    18271833 
    18281834  CalculateRanks( ); 
    1829 } 
     1835 
     1836  G_CallGameHooks("on_player_disconnect"); 
     1837} 
  • src/game/g_local.h

    r112 r117  
    13301330// 
    13311331int             luaopen_game(lua_State * L); 
     1332int             G_CallGameHooks(const char *event); 
    13321333 
    13331334// 
  • src/game/g_lua.c

    r112 r117  
    141141        // Quake lib 
    142142        luaopen_entity(g_luaState); 
     143        luaopen_player(g_luaState); 
     144        luaopen_buildable(g_luaState); 
    143145        luaopen_game(g_luaState); 
    144146        luaopen_qmath(g_luaState); 
    145147        luaopen_vector(g_luaState); 
    146  
    147         luaopen_buildable(g_luaState); 
    148148 
    149149        // load global scripts 
  • src/game/g_main.c

    r112 r117  
    750750 
    751751  G_ResetPTRConnections( ); 
     752 
     753  G_CallGameHooks("on_init"); 
    752754} 
    753755 
     
    780782 
    781783  G_Printf( "==== ShutdownGame ====\n" ); 
     784 
     785  G_CallGameHooks("on_shutdown"); 
    782786 
    783787  if( level.logFile ) 
     
    11731177        localHTP = 0; 
    11741178        localATP = 0; 
     1179 
     1180                G_CallGameHooks("on_sudden_death"); 
    11751181 
    11761182        if( g_suddenDeathMode.integer == SDMODE_SELECTIVE ) { 
     
    13591365    trap_Cvar_Set( "g_alienStage", va( "%d", S2 ) ); 
    13601366    level.alienStage2Time = level.time; 
     1367    G_CallGameHooks("on_stage_up"); 
    13611368  } 
    13621369 
     
    13681375    trap_Cvar_Set( "g_alienStage", va( "%d", S3 ) ); 
    13691376    level.alienStage3Time = level.time; 
     1377    G_CallGameHooks("on_stage_up"); 
    13701378  } 
    13711379 
     
    13771385    trap_Cvar_Set( "g_humanStage", va( "%d", S2 ) ); 
    13781386    level.humanStage2Time = level.time; 
     1387    G_CallGameHooks("on_stage_up"); 
    13791388  } 
    13801389 
     
    13861395    trap_Cvar_Set( "g_humanStage", va( "%d", S3 ) ); 
    13871396    level.humanStage3Time = level.time; 
     1397    G_CallGameHooks("on_stage_up"); 
    13881398  } 
    13891399} 
     
    20832093      trap_SendServerCommand( -1, "print \"Timelimit hit\n\"" ); 
    20842094      trap_SetConfigstring( CS_WINNER, "Stalemate" ); 
     2095 
    20852096      LogExit( "Timelimit hit." ); 
     2097 
     2098      G_CallGameHooks("on_exit"); 
     2099 
    20862100      return; 
    20872101    } 
     
    21092123    trap_SendServerCommand( -1, "print \"Humans win\n\""); 
    21102124    trap_SetConfigstring( CS_WINNER, "Humans Win" ); 
     2125 
    21112126    LogExit( "Humans win." ); 
     2127 
     2128    G_CallGameHooks("on_exit"); 
    21122129  } 
    21132130  else if( level.uncondAlienWin || 
     
    21212138    trap_SetConfigstring( CS_WINNER, "Aliens Win" ); 
    21222139    LogExit( "Aliens win." ); 
     2140 
     2141    G_CallGameHooks("on_exit"); 
    21232142  } 
    21242143} 
     
    25562575    trap_Cvar_Set( "g_listEntity", "0" ); 
    25572576  } 
     2577 
     2578  G_CallGameHooks("on_think"); 
    25582579} 
    25592580 
  • src/game/g_svcmds.c

    r111 r117  
    724724    trap_SetConfigstring( CS_WINNER, "Evacuation" ); 
    725725    LogExit( "Evacuation." ); 
     726     
     727    G_CallGameHooks("on_exit"); 
     728 
    726729    return qtrue; 
    727730  } 
  • src/game/lua_game.c

    r116 r117  
    3131#include "g_local.h" 
    3232 
     33int G_CallGameHooks(const char *event) 
     34{ 
    3335#ifdef USE_LUA 
     36  lua_State *L = g_luaState; 
     37  int ret; 
     38 
     39  lua_getglobal(L, "game"); 
     40 
     41  lua_pushnil(L); 
     42 
     43  ret = G_CallHooks(event); 
     44 
     45  lua_pop(L, 2); 
     46 
     47  return ret; 
     48#else 
     49  return 1; 
     50#endif 
     51} 
     52 
     53#ifdef USE_LUA 
     54static int game_AddHook(lua_State *L) 
     55{ 
     56  lua_getglobal(L, "game"); 
     57  G_AddHook(L, lua_tostring(L, -3)); 
     58 
     59  return 0; 
     60} 
     61 
     62static int game_Time(lua_State * L) 
     63{ 
     64        lua_pushinteger(L, level.time - level.startTime); 
     65 
     66        return 1; 
     67} 
     68 
     69static int game_StartTime(lua_State * L) 
     70{ 
     71        lua_pushinteger(L, level.startTime); 
     72 
     73        return 1; 
     74} 
     75 
    3476static int game_Print(lua_State * L) 
    3577{ 
     
    108150} 
    109151 
    110 static int game_CvarInt(lua_State *L) 
     152static int game_CvarInteger(lua_State *L) 
    111153{ 
    112154        const char *cvar; 
     
    194236 
    195237static const luaL_reg gamelib[] = { 
     238        {"AddHook", game_AddHook}, 
    196239        {"Print", game_Print}, 
    197240        {"Cp", game_Cp}, 
    198241        {"Exec", game_Exec}, 
    199         {"CvarInt", game_CvarInt}, 
     242        {"CvarInteger", game_CvarInteger}, 
    200243        {"CvarString", game_CvarString}, 
    201244        {"CvarFloat", game_CvarFloat}, 
    202245        {"CvarSet", game_CvarSet}, 
     246        {"Time", game_Time}, 
     247        {"StartTime", game_StartTime}, 
    203248        {NULL, NULL} 
    204249}; 
     
    208253        luaL_register(L, "game", gamelib); 
    209254 
     255        lua_newtable(L); 
     256 
     257        G_CreateHooksTable(L, "on_think"); 
     258        G_CreateHooksTable(L, "on_init"); 
     259        G_CreateHooksTable(L, "on_exit"); 
     260        G_CreateHooksTable(L, "on_shutdown"); 
     261        G_CreateHooksTable(L, "on_player_connect"); 
     262        G_CreateHooksTable(L, "on_player_disconnect"); 
     263        G_CreateHooksTable(L, "on_player_begin"); 
     264        G_CreateHooksTable(L, "on_stage_up"); 
     265        G_CreateHooksTable(L, "on_sudden_death"); 
     266 
     267        lua_setfield(L, -2, "hooks"); 
     268 
    210269        lua_pushliteral(L, "_GAMEVERSION"); 
    211270        lua_pushliteral(L, GAME_VERSION); 
     
    214273} 
    215274#endif 
     275