Skip to content

Commit

Permalink
Entity API
Browse files Browse the repository at this point in the history
  • Loading branch information
Exmirai committed May 10, 2015
1 parent 89c71e6 commit ac33e28
Show file tree
Hide file tree
Showing 26 changed files with 1,109 additions and 57 deletions.
1 change: 1 addition & 0 deletions cgame/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ files = [
'game/bg_g2_utils.cpp',
'game/bg_lua.cpp',
'game/bg_luacvar.cpp',
'game/bg_luaentity.cpp',
'game/bg_luaevent.cpp',
'game/bg_luafs.cpp',
'game/bg_lualogger.cpp',
Expand Down
8 changes: 4 additions & 4 deletions cgame/cg_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ void UI_CleanupGhoul2( void );

#define MAX_MISC_ENTS 4000

static refEntity_t MiscEnts[MAX_MISC_ENTS]; //statically allocated for now.
static float Radius[MAX_MISC_ENTS];
static float zOffset[MAX_MISC_ENTS]; //some models need a z offset for culling, because of stupid wrong model origins
refEntity_t MiscEnts[MAX_MISC_ENTS]; //statically allocated for now.
float Radius[MAX_MISC_ENTS];
float zOffset[MAX_MISC_ENTS]; //some models need a z offset for culling, because of stupid wrong model origins

static int NumMiscEnts = 0;
int NumMiscEnts = 0;

void CG_MiscEnt( void );
void CG_DoCameraShake( vector3 *origin, float intensity, int radius, int time );
Expand Down
1 change: 1 addition & 0 deletions cgame/tr_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ typedef struct refEntity_s {
/*
Ghoul2 Insert End
*/
int id;
} refEntity_t;


Expand Down
2 changes: 2 additions & 0 deletions game/NPC_AI_Mark1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "b_local.h"
#include "g_nav.h"
#include "bg_lua.h"

#define MIN_MELEE_RANGE 320
#define MIN_MELEE_RANGE_SQR ( MIN_MELEE_RANGE * MIN_MELEE_RANGE )
Expand Down Expand Up @@ -557,6 +558,7 @@ void Mark1_AttackDecision( void ) {
if ( NPC->die ) {
NPC->die( NPC, NPC, NPC, 100, MOD_UNKNOWN );
}
JPLua_Entity_CallFunction(NPC, JPLUA_ENTITY_DIE, NPC, NPC, (void *)100, (void *)MOD_UNKNOWN);
}

// We can see enemy so shoot him if timers let you.
Expand Down
19 changes: 11 additions & 8 deletions game/NPC_AI_Rancor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "b_local.h"
#include "bg_lua.h"

void G_GetBoltPosition( gentity_t *self, int boltIndex, vector3 *pos, int modelIndex );

Expand Down Expand Up @@ -165,7 +166,7 @@ void Rancor_Swing( qboolean tryGrab ) {
}

if ( DistanceSquared( &radiusEnt->r.currentOrigin, &boltOrg ) <= radiusSquared ) {
if ( tryGrab
if (tryGrab
&& NPC->count != 1 //don't have one in hand or in mouth already - FIXME: allow one in hand and any number in mouth!
&& radiusEnt->client->NPC_class != CLASS_RANCOR
&& radiusEnt->client->NPC_class != CLASS_GALAKMECH
Expand All @@ -181,10 +182,10 @@ void Rancor_Swing( qboolean tryGrab ) {
&& radiusEnt->client->NPC_class != CLASS_REMOTE
&& radiusEnt->client->NPC_class != CLASS_SENTRY
&& radiusEnt->client->NPC_class != CLASS_INTERROGATOR
&& radiusEnt->client->NPC_class != CLASS_VEHICLE ) {//grab
if ( NPC->count == 2 ) {//have one in my mouth, remove him
TIMER_Remove( NPC, "clearGrabbed" );
Rancor_DropVictim( NPC );
&& radiusEnt->client->NPC_class != CLASS_VEHICLE) {//grab
if (NPC->count == 2) {//have one in my mouth, remove him
TIMER_Remove(NPC, "clearGrabbed");
Rancor_DropVictim(NPC);
}
NPC->enemy = radiusEnt;//make him my new best friend
radiusEnt->client->ps.eFlags2 |= EF2_HELD_BY_MONSTER;
Expand All @@ -194,9 +195,11 @@ void Rancor_Swing( qboolean tryGrab ) {
NPC->activator = radiusEnt;//remember him
NPC->count = 1;//in my hand
//wait to attack
TIMER_Set( NPC, "attacking", NPC->client->ps.legsTimer + Q_irand( 500, 2500 ) );
if ( radiusEnt->health > 0 && radiusEnt->pain ) {//do pain on enemy
radiusEnt->pain( radiusEnt, NPC, 100 );
TIMER_Set(NPC, "attacking", NPC->client->ps.legsTimer + Q_irand(500, 2500));
if (radiusEnt->health > 0){//do pain on enemy
if(radiusEnt->pain)
radiusEnt->pain( radiusEnt, NPC, 100 );
JPLua_Entity_CallFunction(radiusEnt, JPLUA_ENTITY_PAIN, NPC, (void *)100);
//GEntity_PainFunc( radiusEnt, NPC, NPC, radiusEnt->r.currentOrigin, 0, MOD_CRUSH );
}
else if ( radiusEnt->client ) {
Expand Down
9 changes: 7 additions & 2 deletions game/NPC_spawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bg_saga.h"
#include "bg_vehicles.h"
#include "g_nav.h"
#include "bg_lua.h"

void G_DebugPrint( int level, const char *format, ... );

Expand Down Expand Up @@ -3466,8 +3467,10 @@ void NPC_Kill_f( void ) {
Com_Printf( S_COLOR_GREEN"Killing NPC %s named %s\n", player->NPC_type, player->targetname );
player->health = 0;

if ( player->die && player->client ) {
player->die( player, player, player, player->client->pers.maxHealth, MOD_UNKNOWN );
if (player->client){
if (player->die)
player->die(player, player, player, player->client->pers.maxHealth, MOD_UNKNOWN);
JPLua_Entity_CallFunction(player, JPLUA_ENTITY_DIE, player, player, (void *)player->client->pers.maxHealth, (void *)MOD_UNKNOWN);
}
}
}
Expand All @@ -3486,6 +3489,7 @@ void NPC_Kill_f( void ) {
if ( player->die ) {
player->die( player, player, player, player->client->pers.maxHealth, MOD_UNKNOWN );
}
JPLua_Entity_CallFunction(player, JPLUA_ENTITY_DIE, player, player, (void *)player->client->pers.maxHealth, (void *)MOD_UNKNOWN);
}
}
else if ( (player->targetname && Q_stricmp( name, player->targetname ) == 0)
Expand All @@ -3496,6 +3500,7 @@ void NPC_Kill_f( void ) {
if ( player->die ) {
player->die( player, player, player, 100, MOD_UNKNOWN );
}
JPLua_Entity_CallFunction(player, JPLUA_ENTITY_DIE, player, player, (void *)player->client->pers.maxHealth, (void *)MOD_UNKNOWN);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions game/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ files = [
'game/bg_g2_utils.cpp',
'game/bg_lua.cpp',
'game/bg_luacvar.cpp',
'game/bg_luaentity.cpp',
'game/bg_luaevent.cpp',
'game/bg_luafs.cpp',
'game/bg_lualogger.cpp',
Expand Down
13 changes: 13 additions & 0 deletions game/bg_lua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ void JPLua_Util_ArgAsString( lua_State *L, char *out, int bufsize ) {
return;
}

int propertycmp(const void *a, const void *b) {
return strcmp((const char *)a, ((luaProperty_t *)b)->name);
}

extern int lastluaid;
static int JPLua_Export_Print( lua_State *L ) {
char buf[16384] = { 0 };
Expand Down Expand Up @@ -980,6 +984,7 @@ static int JPLua_GetGLConfig(lua_State *L){

return 1;
}

#endif


Expand All @@ -993,6 +998,12 @@ static const jplua_cimport_table_t JPLua_CImports[] = {
{ "AddListener", JPLua_Event_AddListener }, // AddListener( string name, function listener )
{ "AddServerCommand", JPLua_Export_AddServerCommand }, // AddServerCommand( string cmd )
{ "CreateCvar", JPLua_CreateCvar }, // Cvar CreateCvar( string name [, string value [, integer flags] ] )
#ifdef PROJECT_GAME
{ "CreateEntity", JPLua_Entity_Create },
#endif
#ifdef PROJECT_CGAME
{ "CreateRefEntity", JPLua_Entity_CreateRefEntity },
#endif
#ifdef PROJECT_GAME
{ "ConnectToDB", JPLua_ConnectToDB}, // ConnectToDB ( int type(1 - MySQL , 2 - SQLite), ...) // SQLite (type, string path) || MySQL ( type, string host, string user, string db, string password, int port )
#endif
Expand All @@ -1006,6 +1017,7 @@ static const jplua_cimport_table_t JPLua_CImports[] = {
#endif
{ "GetConfigString", JPLua_GetConfigString }, // table GetConfigString()
{ "GetCvar", JPLua_GetCvar }, // Cvar GetCvar( string name )
{ "GetEntity", JPLua_Entity_Get }, // GetEntity(num) or GetEntity() for full list
{ "GetFileList", JPLua_File_GetFileList}, // table GetFileList(string path, string extension)
#ifdef PROJECT_CGAME
{ "GetFPS", JPLua_Export_GetFPS }, // integer GetFPS()
Expand Down Expand Up @@ -1124,6 +1136,7 @@ void JPLua_Init( void ) {

// Register our classes
JPLua_Register_Player( JPLua.state );
JPLua_Register_Entity(JPLua.state);
#ifdef PROJECT_CGAME
JPLua_Register_Server( JPLua.state );
#endif
Expand Down
11 changes: 11 additions & 0 deletions game/bg_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ extern "C" {
#include "bg_luacvar.h"
#include "bg_luaevent.h"
#include "bg_luaplayer.h"
#include "bg_luaentity.h"
#ifdef PROJECT_CGAME
#include "cg_luaserver.h"
#endif
Expand Down Expand Up @@ -64,6 +65,16 @@ typedef struct jplua_s {
} jplua_t;
extern jplua_t JPLua;

typedef int(*getFunc_t)(lua_State *L, jpluaEntity_t *ent);
typedef void(*setFunc_t)(lua_State *L, jpluaEntity_t *ent);

struct luaProperty_t {
const char *name;
getFunc_t Get;
setFunc_t Set;
};

extern const uint32_t JPLUA_VERSION;
int propertycmp(const void *a, const void *b);

#endif // JPLUA

0 comments on commit ac33e28

Please sign in to comment.