Skip to content

Commit

Permalink
Add prestige system
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoru committed Sep 19, 2024
1 parent c11b32d commit 12a9c83
Show file tree
Hide file tree
Showing 28 changed files with 893 additions and 366 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ option(VRX_Q2PRO "Use map/gamemap differentiation (for q2pro)." TRUE)
option(VRX_OLD_NOLAG "Use old NOLAG style. Not recommended." FALSE)
option(VRX_OLD_VOTE "Use old vote system." FALSE)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED TRUE)

# Source files
Expand Down
95 changes: 53 additions & 42 deletions sql/vrx-5.7.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,83 @@ create table if not exists abilities
(
char_idx int not null,
aindex int not null,
level int null,
max_level int null,
hard_max int null,
modifier int null,
disable int null,
general_skill int null,
level int not null,
max_level int not null,
hard_max int not null,
modifier int not null,
disable int not null,
general_skill int not null,
primary key (char_idx, aindex)
);

create table if not exists prestige
(
char_idx int not null,
pindex int not null,
param int not null,
level int not null,
primary key (char_idx, pindex, param)
);

create table if not exists character_data
(
char_idx int not null,
respawns int null,
health int null,
maxhealth int null,
armour int null,
maxarmour int null,
nerfme int null,
adminlevel int null,
bosslevel int null,
respawns int not null default 0,
health int not null default 100,
maxhealth int not null default 100,
armour int not null default 0,
maxarmour int not null default 0,
nerfme int not null default 0,
adminlevel int not null default 0,
bosslevel int not null default 0,
prestigelevel int not null default 0,
prestigepoints int not null default 0,
primary key (char_idx)
);

create table if not exists ctf_stats
(
char_idx int not null,
flag_pickups int null,
flag_captures int null,
flag_returns int null,
flag_kills int null,
offense_kills int null,
defense_kills int null,
assists int null,
flag_pickups int not null default 0,
flag_captures int not null default 0,
flag_returns int not null default 0,
flag_kills int not null default 0,
offense_kills int not null default 0,
defense_kills int not null default 0,
assists int not null default 0,
primary key (char_idx)
);

create table if not exists game_stats
(
char_idx int not null,
shots int null,
shots_hit int null,
frags int null,
fragged int null,
num_sprees int null,
max_streak int null,
spree_wars int null,
broken_sprees int null,
broken_spreewars int null,
suicides int null,
teleports int null,
num_2fers int null,
shots int not null default 0,
shots_hit int not null default 0,
frags int not null default 0,
fragged int not null default 0,
num_sprees int not null default 0,
max_streak int not null default 0,
spree_wars int not null default 0,
broken_sprees int not null default 0,
broken_spreewars int not null default 0,
suicides int not null default 0,
teleports int not null default 0,
num_2fers int not null default 0,
primary key (char_idx)
);

create table if not exists point_data
(
char_idx int not null,
exp int null,
exptnl int null,
level int null,
classnum int null,
skillpoints int null,
credits int null,
weap_points int null,
resp_weapon int null,
tpoints int null,
exp int not null,
exptnl int not null,
level int not null default 0,
classnum int not null default 0,
skillpoints int not null default 0,
credits int not null default 0,
weap_points int not null default 0,
resp_weapon int not null default 0,
tpoints int not null default 0,
primary key (char_idx)
);

Expand Down
6 changes: 4 additions & 2 deletions src/characters/io/v_characterio.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ void vrx_setup_sqlite_io() {
.handle_status = NULL,
.character_exists = &vrx_sqlite_character_exists,
.is_loading = &vrx_sqlite_isloading,
.set_owner = &cdb_set_owner
.set_owner = &cdb_set_owner,
.type = SAVEMETHOD_SQLITE
};

cdb_start_connection();
Expand Down Expand Up @@ -170,7 +171,8 @@ void vrx_setup_mysql_io() {
.load_player = &vrx_mysql_load_character,
.is_loading = &vrx_mysql_isloading,
.handle_status = &gds_handle_status,
.set_owner = &gds_queue_add_setowner
.set_owner = &gds_queue_add_setowner,
.type = SAVEMETHOD_MYSQL
};

gds_connect();
Expand Down
1 change: 1 addition & 0 deletions src/characters/io/v_characterio.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ typedef struct {
qboolean (*is_loading) (edict_t* ent); // if it's already loading... don't bother calling load_player again.
void (*handle_status)(edict_t* ent); // if not null, this is a multithreaded io system.
void (*set_owner)(edict_t* ent, char* charname, char* mpw);
int type;
} char_io_t;

extern char_io_t vrx_char_io;
Expand Down
87 changes: 79 additions & 8 deletions src/characters/io/v_sqlite_unidb.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// *********************************
// Definitions
// *********************************
#define TOTAL_TABLES 14
#define TOTAL_TABLES 15
#define TOTAL_INSERTONCE 5
#define TOTAL_RESETTABLES 6
#define TOTAL_RESETTABLES 7

void cdb_start_connection();

Expand All @@ -34,15 +34,16 @@ const char* VSFU_CREATEDBQUERY[TOTAL_TABLES] =
"CREATE TABLE [userdata] ( [char_idx] INTEGER,[title] CHAR(24), [playername] CHAR(64), [password] CHAR(24), [email] CHAR(64), [owner] CHAR(24), [member_since] CHAR(30), [last_played] CHAR(30), [playtime_total] INTEGER,[playingtime] INTEGER)",
"CREATE TABLE [weapon_meta] ([char_idx] INTEGER,[index] INTEGER, [disable] INTEGER)",
"CREATE TABLE [weapon_mods] ([char_idx] INTEGER,[weapon_index] INTEGER, [modindex] INTEGER, [level] INTEGER, [soft_max] INTEGER, [hard_max] INTEGER)",
"CREATE TABLE [character_data] ([char_idx] INTEGER, [respawns] INTEGER, [health] INTEGER, [maxhealth] INTEGER, [armour] INTEGER, [maxarmour] INTEGER, [nerfme] INTEGER, [adminlevel] INTEGER, [bosslevel] INTEGER)",
"CREATE TABLE [character_data] ([char_idx] INTEGER, [respawns] INTEGER, [health] INTEGER, [maxhealth] INTEGER, [armour] INTEGER, [maxarmour] INTEGER, [nerfme] INTEGER, [adminlevel] INTEGER, [bosslevel] INTEGER, [prestigelevel] INTEGER, [prestigepoints] INTEGER)",
"create table [prestige](char_idx int not null, pindex int not null, param int not null, level int not null, primary key (char_idx, pindex, param))"
"create table stash( char_idx int not null, lock_char_id int null, primary key (char_idx));",
"create table stash_runes_meta( char_idx int not null, stash_index int not null, itemtype int null, itemlevel int null, quantity int null, untradeable int null, id char(16) null, name char(24) null, nummods int null, setcode int null, classnum int null, primary key (char_idx, stash_index));",
"create table stash_runes_mods( char_idx int not null, stash_index int not null, rune_mod_index int not null, type int null, mod_index int null, value int null, [set] int null, primary key (char_idx, stash_index, rune_mod_index));"
};

// SAVING

const char* CreateCharacterData = "INSERT INTO character_data VALUES (%d,0,0,0,0,0,0,0,0)";
const char* CreateCharacterData = "INSERT INTO character_data VALUES (%d,0,0,0,0,0,0,0,0,0,0)";
const char* CreateCtfStats = "INSERT INTO ctf_stats VALUES (%d,0,0,0,0,0,0,0)";
const char* CreateGameStats = "INSERT INTO game_stats VALUES (%d,0,0,0,0,0,0,0,0,0,0,0,0)";
const char* CreatePointData = "INSERT INTO point_data VALUES (%d,0,0,0,0,0,0,0,0,0)";
Expand All @@ -53,6 +54,7 @@ const char* VSFU_RESETTABLES[TOTAL_RESETTABLES] =
{
"DELETE FROM abilities WHERE char_idx=%d;",
"DELETE FROM talents WHERE char_idx=%d;",
"DELETE FROM prestige WHERE char_idx=%d;",
"DELETE FROM runes_meta WHERE char_idx=%d;",
"DELETE FROM runes_mods WHERE char_idx=%d;",
"DELETE FROM weapon_meta WHERE char_idx=%d;",
Expand Down Expand Up @@ -80,7 +82,9 @@ const char* VSFU_INSERTRMOD = "INSERT INTO runes_mods VALUES (%d,%d,%d,%d,%d,%d)
const char* VSFU_INSERTRMODEX = "INSERT INTO runes_mods VALUES (%d,%d,0,%d,%d,%d,%d);";


const char* VSFU_UPDATECDATA = "UPDATE character_data SET respawns=%d, health=%d, maxhealth=%d, armour=%d, maxarmour=%d, nerfme=%d, adminlevel=%d, bosslevel=%d WHERE char_idx=%d;";
const char* VSFU_UPDATECDATA = "UPDATE character_data SET respawns=%d, health=%d, maxhealth=%d, armour=%d, "
"maxarmour=%d, nerfme=%d, adminlevel=%d, bosslevel=%d, prestigelevel=%d, prestigepoints=%d"
" WHERE char_idx=%d;";

const char* VSFU_UPDATESTATS = "UPDATE game_stats SET shots=%d, shots_hit=%d, frags=%d, fragged=%d, num_sprees=%d, max_streak=%d, spree_wars=%d, broken_sprees=%d, broken_spreewars=%d, suicides=%d, teleports=%d, num_2fers=%d WHERE char_idx=%d;";

Expand Down Expand Up @@ -326,7 +330,10 @@ qboolean cdb_save_player(edict_t* player)
MAX_ARMOR(player),
player->myskills.nerfme,
player->myskills.administrator, // flags
player->myskills.boss, id));
player->myskills.boss,
player->myskills.prestige.total,
player->myskills.prestige.points,
id));


//*****************************
Expand Down Expand Up @@ -437,6 +444,34 @@ qboolean cdb_save_player(edict_t* player)
player->myskills.defense_kills,
player->myskills.assists, id));

// prestige
QUERY(va("INSERT INTO prestige(char_idx, pindex, param, level) VALUES (%d, %d, %d, %d);",
id, PRESTIGE_CREDITS, 0, player->myskills.prestige.creditLevel));

QUERY(va("INSERT INTO prestige(char_idx, pindex, param, level) VALUES (%d, %d, %d, %d);",
id, PRESTIGE_ABILITY_POINTS, 0, player->myskills.prestige.abilityPoints));

QUERY(va("INSERT INTO prestige(char_idx, pindex, param, level) VALUES (%d, %d, %d, %d);",
id, PRESTIGE_WEAPON_POINTS, 0, player->myskills.prestige.weaponPoints));

// softmax bump points - param is the ab index, level is the bump
for (i = 0; i < MAX_ABILITIES; i++)
{
if (player->myskills.prestige.softmaxBump[i] > 0) {
QUERY(va("INSERT INTO prestige(char_idx, pindex, param, level) VALUES (%d, %d, %d, %d);",
id, PRESTIGE_SOFTMAX_BUMP, i, player->myskills.prestige.softmaxBump[i]));
}
}

// class skills - param is the ab index, level is always 0
for (i = 0; i < MAX_ABILITIES; i++)
{
if (player->myskills.prestige.classSkill[i / 32] & (1 << (i % 32)))
{
QUERY(va("INSERT INTO prestige(char_idx, pindex, param, level) VALUES (%d, %d, %d, %d);",
id, PRESTIGE_CLASS_SKILL, i, 0));
}
}

} // end saving

Expand Down Expand Up @@ -749,6 +784,10 @@ qboolean cdb_load_player(edict_t* player)
//boss flag
player->myskills.boss = sqlite3_column_int(statement, 8);

// prestige
player->myskills.prestige.total = sqlite3_column_int(statement, 9);
player->myskills.prestige.points = sqlite3_column_int(statement, 10);

//*****************************
//stats
//*****************************
Expand Down Expand Up @@ -804,10 +843,42 @@ qboolean cdb_load_player(edict_t* player)

sqlite3_finalize(statement);

// prestige
format = va("SELECT * FROM prestige WHERE char_idx=%d", id);

r = sqlite3_prepare_v2(db, format, strlen(format), &statement, NULL);
while(sqlite3_step(statement) == SQLITE_ROW) {
int pindex = sqlite3_column_int(statement, 1);
int param = sqlite3_column_int(statement, 2);
int level = sqlite3_column_int(statement, 3);

switch (pindex)
{
case PRESTIGE_CREDITS:
player->myskills.prestige.creditLevel = level;
break;
case PRESTIGE_ABILITY_POINTS:
player->myskills.prestige.abilityPoints = level;
break;
case PRESTIGE_WEAPON_POINTS:
player->myskills.prestige.weaponPoints = level;
break;
case PRESTIGE_SOFTMAX_BUMP:
player->myskills.prestige.softmaxBump[param] = level;
break;
case PRESTIGE_CLASS_SKILL:
player->myskills.prestige.classSkill[param / 32] |= (1 << (param % 32));
break;
default: break;
}
}



//Apply runes
V_ResetAllStats(player);
vrx_runes_unapply(player);
for (i = 0; i < 4; ++i)
V_ApplyRune(player, &player->myskills.items[i]);
vrx_runes_apply(player, &player->myskills.items[i]);

//Apply health
if (player->myskills.current_health > MAX_HEALTH(player))
Expand Down
7 changes: 3 additions & 4 deletions src/characters/player_points.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,14 @@ int vrx_get_credits(const edict_t *ent, float level_diff, int bonus, qboolean cl
else
add_credits = level_diff * (vrx_creditmult->value * vrx_pvmcreditmult->value * (CREDITS_OTHER_BASE));

// vrxchile v1.5 no credit cap
//if (add_credits > 250)
// add_credits = 250;

add_credits += bonus;
add_credits = (int) (add_credits * PRESTIGE_CREDIT_BUFF_MULTIPLIER);
return add_credits;
}

void vrx_add_credits(edict_t *ent, int add_credits) {
if (add_credits < 0)
return;

//FIXME: remove this after allocating more space
if (ent->myskills.credits + add_credits > MAX_CREDITS)
Expand Down
Loading

0 comments on commit 12a9c83

Please sign in to comment.