Changeset 117:8021fffe95f1
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r59
|
r117
|
|
| 3305 | 3305 | LogExit( va( "nextmap was run by %s", |
| 3306 | 3306 | ( ent ) ? ent->client->pers.netname : "console" ) ); |
| | 3307 | |
| | 3308 | G_CallGameHooks("on_exit"); |
| | 3309 | |
| 3307 | 3310 | return qtrue; |
| 3308 | 3311 | } |
-
|
r113
|
r117
|
|
| 3196 | 3196 | vec3_t normal; |
| 3197 | 3197 | |
| 3198 | | if( ! G_CallPlayerHooks("on_build", builder) ) |
| | 3198 | if( builder && ! G_CallPlayerHooks("on_build", builder) ) |
| 3199 | 3199 | return NULL; |
| 3200 | 3200 | |
-
|
r112
|
r117
|
|
| 1352 | 1352 | CalculateRanks( ); |
| 1353 | 1353 | G_admin_namelog_update( client, qfalse ); |
| | 1354 | |
| | 1355 | if( ! G_CallGameHooks("on_player_connect") ) |
| | 1356 | return "Game refused by server"; |
| | 1357 | |
| 1354 | 1358 | return NULL; |
| 1355 | 1359 | } |
| … |
… |
|
| 1419 | 1423 | // count current clients and rank for scoreboard |
| 1420 | 1424 | CalculateRanks( ); |
| | 1425 | |
| | 1426 | G_CallGameHooks("on_player_begin"); |
| 1421 | 1427 | } |
| 1422 | 1428 | |
| … |
… |
|
| 1827 | 1833 | |
| 1828 | 1834 | CalculateRanks( ); |
| 1829 | | } |
| | 1835 | |
| | 1836 | G_CallGameHooks("on_player_disconnect"); |
| | 1837 | } |
-
|
r112
|
r117
|
|
| 1330 | 1330 | // |
| 1331 | 1331 | int luaopen_game(lua_State * L); |
| | 1332 | int G_CallGameHooks(const char *event); |
| 1332 | 1333 | |
| 1333 | 1334 | // |
-
|
r112
|
r117
|
|
| 141 | 141 | // Quake lib |
| 142 | 142 | luaopen_entity(g_luaState); |
| | 143 | luaopen_player(g_luaState); |
| | 144 | luaopen_buildable(g_luaState); |
| 143 | 145 | luaopen_game(g_luaState); |
| 144 | 146 | luaopen_qmath(g_luaState); |
| 145 | 147 | luaopen_vector(g_luaState); |
| 146 | | |
| 147 | | luaopen_buildable(g_luaState); |
| 148 | 148 | |
| 149 | 149 | // load global scripts |
-
|
r112
|
r117
|
|
| 750 | 750 | |
| 751 | 751 | G_ResetPTRConnections( ); |
| | 752 | |
| | 753 | G_CallGameHooks("on_init"); |
| 752 | 754 | } |
| 753 | 755 | |
| … |
… |
|
| 780 | 782 | |
| 781 | 783 | G_Printf( "==== ShutdownGame ====\n" ); |
| | 784 | |
| | 785 | G_CallGameHooks("on_shutdown"); |
| 782 | 786 | |
| 783 | 787 | if( level.logFile ) |
| … |
… |
|
| 1173 | 1177 | localHTP = 0; |
| 1174 | 1178 | localATP = 0; |
| | 1179 | |
| | 1180 | G_CallGameHooks("on_sudden_death"); |
| 1175 | 1181 | |
| 1176 | 1182 | if( g_suddenDeathMode.integer == SDMODE_SELECTIVE ) { |
| … |
… |
|
| 1359 | 1365 | trap_Cvar_Set( "g_alienStage", va( "%d", S2 ) ); |
| 1360 | 1366 | level.alienStage2Time = level.time; |
| | 1367 | G_CallGameHooks("on_stage_up"); |
| 1361 | 1368 | } |
| 1362 | 1369 | |
| … |
… |
|
| 1368 | 1375 | trap_Cvar_Set( "g_alienStage", va( "%d", S3 ) ); |
| 1369 | 1376 | level.alienStage3Time = level.time; |
| | 1377 | G_CallGameHooks("on_stage_up"); |
| 1370 | 1378 | } |
| 1371 | 1379 | |
| … |
… |
|
| 1377 | 1385 | trap_Cvar_Set( "g_humanStage", va( "%d", S2 ) ); |
| 1378 | 1386 | level.humanStage2Time = level.time; |
| | 1387 | G_CallGameHooks("on_stage_up"); |
| 1379 | 1388 | } |
| 1380 | 1389 | |
| … |
… |
|
| 1386 | 1395 | trap_Cvar_Set( "g_humanStage", va( "%d", S3 ) ); |
| 1387 | 1396 | level.humanStage3Time = level.time; |
| | 1397 | G_CallGameHooks("on_stage_up"); |
| 1388 | 1398 | } |
| 1389 | 1399 | } |
| … |
… |
|
| 2083 | 2093 | trap_SendServerCommand( -1, "print \"Timelimit hit\n\"" ); |
| 2084 | 2094 | trap_SetConfigstring( CS_WINNER, "Stalemate" ); |
| | 2095 | |
| 2085 | 2096 | LogExit( "Timelimit hit." ); |
| | 2097 | |
| | 2098 | G_CallGameHooks("on_exit"); |
| | 2099 | |
| 2086 | 2100 | return; |
| 2087 | 2101 | } |
| … |
… |
|
| 2109 | 2123 | trap_SendServerCommand( -1, "print \"Humans win\n\""); |
| 2110 | 2124 | trap_SetConfigstring( CS_WINNER, "Humans Win" ); |
| | 2125 | |
| 2111 | 2126 | LogExit( "Humans win." ); |
| | 2127 | |
| | 2128 | G_CallGameHooks("on_exit"); |
| 2112 | 2129 | } |
| 2113 | 2130 | else if( level.uncondAlienWin || |
| … |
… |
|
| 2121 | 2138 | trap_SetConfigstring( CS_WINNER, "Aliens Win" ); |
| 2122 | 2139 | LogExit( "Aliens win." ); |
| | 2140 | |
| | 2141 | G_CallGameHooks("on_exit"); |
| 2123 | 2142 | } |
| 2124 | 2143 | } |
| … |
… |
|
| 2556 | 2575 | trap_Cvar_Set( "g_listEntity", "0" ); |
| 2557 | 2576 | } |
| | 2577 | |
| | 2578 | G_CallGameHooks("on_think"); |
| 2558 | 2579 | } |
| 2559 | 2580 | |
-
|
r111
|
r117
|
|
| 724 | 724 | trap_SetConfigstring( CS_WINNER, "Evacuation" ); |
| 725 | 725 | LogExit( "Evacuation." ); |
| | 726 | |
| | 727 | G_CallGameHooks("on_exit"); |
| | 728 | |
| 726 | 729 | return qtrue; |
| 727 | 730 | } |
-
|
r116
|
r117
|
|
| 31 | 31 | #include "g_local.h" |
| 32 | 32 | |
| | 33 | int G_CallGameHooks(const char *event) |
| | 34 | { |
| 33 | 35 | #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 |
| | 54 | static 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 | |
| | 62 | static int game_Time(lua_State * L) |
| | 63 | { |
| | 64 | lua_pushinteger(L, level.time - level.startTime); |
| | 65 | |
| | 66 | return 1; |
| | 67 | } |
| | 68 | |
| | 69 | static int game_StartTime(lua_State * L) |
| | 70 | { |
| | 71 | lua_pushinteger(L, level.startTime); |
| | 72 | |
| | 73 | return 1; |
| | 74 | } |
| | 75 | |
| 34 | 76 | static int game_Print(lua_State * L) |
| 35 | 77 | { |
| … |
… |
|
| 108 | 150 | } |
| 109 | 151 | |
| 110 | | static int game_CvarInt(lua_State *L) |
| | 152 | static int game_CvarInteger(lua_State *L) |
| 111 | 153 | { |
| 112 | 154 | const char *cvar; |
| … |
… |
|
| 194 | 236 | |
| 195 | 237 | static const luaL_reg gamelib[] = { |
| | 238 | {"AddHook", game_AddHook}, |
| 196 | 239 | {"Print", game_Print}, |
| 197 | 240 | {"Cp", game_Cp}, |
| 198 | 241 | {"Exec", game_Exec}, |
| 199 | | {"CvarInt", game_CvarInt}, |
| | 242 | {"CvarInteger", game_CvarInteger}, |
| 200 | 243 | {"CvarString", game_CvarString}, |
| 201 | 244 | {"CvarFloat", game_CvarFloat}, |
| 202 | 245 | {"CvarSet", game_CvarSet}, |
| | 246 | {"Time", game_Time}, |
| | 247 | {"StartTime", game_StartTime}, |
| 203 | 248 | {NULL, NULL} |
| 204 | 249 | }; |
| … |
… |
|
| 208 | 253 | luaL_register(L, "game", gamelib); |
| 209 | 254 | |
| | 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 | |
| 210 | 269 | lua_pushliteral(L, "_GAMEVERSION"); |
| 211 | 270 | lua_pushliteral(L, GAME_VERSION); |
| … |
… |
|
| 214 | 273 | } |
| 215 | 274 | #endif |
| | 275 | |