Skip to content

Commit

Permalink
DB Queue Debug Update
Browse files Browse the repository at this point in the history
Some documentation update on battlegrounds.conf
Fixed Hercules Queue Option constants, they're 1-2-3 not 0-1-2.
Some Bugfixes to the test script, special thanks to ossi0110
http://hercules.ws/board/topic/1302-bg-queue-debug

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Jul 6, 2013
1 parent a804951 commit 449a41a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 58 deletions.
12 changes: 6 additions & 6 deletions conf/battlegrounds.conf
Expand Up @@ -34,7 +34,7 @@ battlegrounds: (
minPlayers: 6 /* minimum amount of players to start */
maxPlayers: 60 /* maximum amount of players */
minTeamPlayers: 6 /* minimum amount of team members required for a team (party or guild) to join */
delay_var: "Tierra_BG_Tick" /* npc variable name that will store the delay for this match */
delay_var: "Tierra_BG_Tick" /* char variable name that will store the delay for this match */
maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */
fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */
pGameDuration: 20 /* time to wait for players to confirm their attendence after queueing process has finished */
Expand All @@ -48,10 +48,10 @@ battlegrounds: (
loss: 3
draw: 3
}
minPlayers: 3 /* minimum amount of players to start (DEBUG VALUE, CHANGE BACK) */
minPlayers: 2 /* minimum amount of players to start (DEBUG VALUE, CHANGE BACK) */
maxPlayers: 60 /* maximum amount of players */
minTeamPlayers: 6 /* minimum amount of team members required for a team (party or guild) to join */
delay_var: "Flavius_BG_Tick" /* npc variable name that will store the delay for this match */
delay_var: "Flavius_BG_Tick" /* char variable name that will store the delay for this match */
maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */
fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */
pGameDuration: 20 /* time to wait for players to confirm their attendence after queueing process has finished */
Expand All @@ -68,7 +68,7 @@ battlegrounds: (
minPlayers: 4 /* minimum amount of players to start */
maxPlayers: 60 /* maximum amount of players */
minTeamPlayers: 5 /* minimum amount of team members required for a team (party or guild) to join */
delay_var: "KVM_BG_Tick" /* npc variable name that will store the delay for this match */
delay_var: "KVM_BG_Tick" /* char variable name that will store the delay for this match */
maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */
fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */
pGameDuration: 20 /* time to wait for players to confirm their attendence after queueing process has finished */
Expand All @@ -85,7 +85,7 @@ battlegrounds: (
minPlayers: 4 /* minimum amount of players to start */
maxPlayers: 60 /* maximum amount of players */
minTeamPlayers: 5 /* minimum amount of team members required for a team (party or guild) to join */
delay_var: "KVM_BG_Tick" /* npc variable name that will store the delay for this match */
delay_var: "KVM_BG_Tick" /* char variable name that will store the delay for this match */
maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */
fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */
pGameDuration: 20 /* time to wait for players to confirm their attendence after queueing process has finished */
Expand All @@ -102,7 +102,7 @@ battlegrounds: (
minPlayers: 4 /* minimum amount of players to start */
maxPlayers: 60 /* maximum amount of players */
minTeamPlayers: 5 /* minimum amount of team members required for a team (party or guild) to join */
delay_var: "KVM_BG_Tick" /* npc variable name that will store the delay for this match */
delay_var: "KVM_BG_Tick" /* char variable name that will store the delay for this match */
maxDuration: 30 /* maximum duration in minutes, if reached game ends and highest score wins (or calls a draw if scores are equal) */
fillDuration: 20 /* time in seconds to wait for more applications when minimum has been reached */
pGameDuration: 20 /* time to wait for players to confirm their attendence after queueing process has finished */
Expand Down
6 changes: 3 additions & 3 deletions db/const.txt
Expand Up @@ -3160,6 +3160,6 @@ IT_AMMO 10
IT_DELAYCONSUME 11
IT_CASH 18

HQO_OnDeath 0
HQO_OnLogout 1
HQO_OnMapChange 2
HQO_OnDeath 1
HQO_OnLogout 2
HQO_OnMapChange 3
2 changes: 1 addition & 1 deletion doc/script_commands.txt
Expand Up @@ -8146,7 +8146,7 @@ Modifies <queue_id>'s <optionType>. When <option val> is not present
<queue_id>'s <optionType> with the new <option val> value.

Currently 3 options are available:
HQO_OnDeath (0), HQO_OnLogout (1), HQO_OnMapChange (2)
HQO_OnDeath (1), HQO_OnLogout (2), HQO_OnMapChange (3)

Note: The constant names are not final.

Expand Down
58 changes: 24 additions & 34 deletions npc/custom/bgqueue/flavius.txt
Expand Up @@ -74,8 +74,12 @@ OnPlayerListReady:
disablenpc "Vintenar#bat_b01_bover";
bg_warp $@FlaviusBG1_id1,"bat_b01",87,75;
bg_warp $@FlaviusBG1_id2,"bat_b01",311,224;

/* after warp */
queueopt($@Guill_QueueBG1,HQO_OnMapChange,"start#bat_b01::OnGuillaumeQuit");
queueopt($@Croix_QueueBG1,HQO_OnMapChange,"start#bat_b01::OnCroixQuit");

donpcevent "countdown#bat_b01::OnEnable";
initnpctimer;
end;

OnReset:
Expand All @@ -98,20 +102,31 @@ OnReset:
bg_warp $@FlaviusBG1_id2,"bat_b01",311,224;
end;

OnGuillaumeQuit:
OnCroixQuit:
bg_leave;
queueremove($@Croix_QueueBG1,getcharid(3));
callsub L_OnPlayerQuit;
end;

OnTimer10000:
stopnpctimer;
donpcevent "#bat_b01_timer::OnEnable";
OnGuillaumeQuit:
queueremove($@Guill_QueueBG1,getcharid(3));
callsub L_OnPlayerQuit;
end;

L_OnPlayerQuit:
bg_leave;
setd $@bg_delay_var$,gettimetick(2);
if( queuesize($@Guill_QueueBG1) == 0 || queuesize($@Croix_QueueBG1) == 0 ) /* todo check score and decide a winner if anyone left */
callsub OnMatchOver;
end;

OnMatchOver:
bg_match_over("Flavius");
queuedel($@Croix_QueueBG1);
queuedel($@Guill_QueueBG1);
if( $@FlaviusBG1_id1 || $@FlaviusBG1_id2 ) {
bg_match_over("Flavius");
queuedel($@Croix_QueueBG1);
queuedel($@Guill_QueueBG1);
}
if( $@FlaviusBG1_id1 ) { bg_destroy $@FlaviusBG1_id1; set $@FlaviusBG1_id1, 0; }
if( $@FlaviusBG1_id2 ) { bg_destroy $@FlaviusBG1_id2; set $@FlaviusBG1_id2, 0; }
end;
}

Expand Down Expand Up @@ -140,37 +155,12 @@ OnMyMobDead:
donpcevent "time#bat_b01::OnEnable";
donpcevent "start#bat_b01::onReset";
}
donpcevent "#bat_b01_timer::OnStop";
bg_updatescore "bat_b01",$@Guill_ScoreBG1,$@Croix_ScoreBG1;
bg_warp $@FlaviusBG1_id1,"bat_b01",10,290;
bg_warp $@FlaviusBG1_id2,"bat_b01",390,10;
donpcevent "#bat_b01_timer::OnEnable";
}
end;
}
bat_room,2,151,3 script #bat_b01_timer 844,{
end;

OnEnable:
initnpctimer;
end;

OnStop:
stopnpctimer;
end;

OnTimer1000:
stopnpctimer;
initnpctimer;
set .@chk_bat_a01,getmapusers("bat_b01");
if (.@chk_bat_a01 < 1) {
set $@FlaviusBG1, 0;
if( $@FlaviusBG1_id1 ) { bg_destroy $@FlaviusBG1_id1; set $@FlaviusBG1_id1, 0; }
if( $@FlaviusBG1_id2 ) { bg_destroy $@FlaviusBG1_id2; set $@FlaviusBG1_id2, 0; }
}
end;
}

bat_b01,1,2,3 script OBJ#bat_b01_b 844,{
OnEnable:
bg_monster $@FlaviusBG1_id2,"bat_b01",328,150,"Blue Crystal",1914,"OBJ#bat_b01_b::OnMyMobDead";
Expand Down
40 changes: 27 additions & 13 deletions src/map/battleground.c
Expand Up @@ -110,7 +110,7 @@ int bg_team_join(int bg_id, struct map_session_data *sd)
int bg_team_leave(struct map_session_data *sd, int flag)
{ // Single Player leaves team
int i, bg_id;
struct battleground_data *bg;
struct battleground_data *bg_data;
char output[128];

if( sd == NULL || !sd->bg_id )
Expand All @@ -120,24 +120,27 @@ int bg_team_leave(struct map_session_data *sd, int flag)
bg_id = sd->bg_id;
sd->bg_id = 0;

if( (bg = bg_team_search(bg_id)) == NULL )
if( (bg_data = bg_team_search(bg_id)) == NULL )
return 0;

ARR_FIND(0, MAX_BG_MEMBERS, i, bg->members[i].sd == sd);
ARR_FIND(0, MAX_BG_MEMBERS, i, bg_data->members[i].sd == sd);
if( i < MAX_BG_MEMBERS ) // Removes member from BG
memset(&bg->members[i], 0, sizeof(bg->members[0]));
bg->count--;
memset(&bg_data->members[i], 0, sizeof(bg_data->members[0]));
bg_data->count--;

if( flag )
sprintf(output, "Server : %s has quit the game...", sd->status.name);
else
sprintf(output, "Server : %s is leaving the battlefield...", sd->status.name);
clif->bg_message(bg, 0, "Server", output, strlen(output) + 1);
clif->bg_message(bg_data, 0, "Server", output, strlen(output) + 1);

if( bg->logout_event[0] && flag )
npc_event(sd, bg->logout_event, 0);
if( bg_data->logout_event[0] && flag )
npc_event(sd, bg_data->logout_event, 0);

return bg->count;
if( sd->bg_queue.arena )
bg->queue_pc_cleanup(sd);

return bg_data->count;
}

int bg_member_respawn(struct map_session_data *sd)
Expand Down Expand Up @@ -392,6 +395,7 @@ void bg_config_read(void) {
bg->arena[i]->fillup_timer = INVALID_TIMER;
bg->arena[i]->pregame_duration = pregame_duration;
bg->arena[i]->fillup_duration = fillup_duration;
bg->arena[i]->ongoing = false;

}
bg->arenas = arena_count;
Expand Down Expand Up @@ -463,18 +467,25 @@ void bg_match_over(struct bg_arena *arena, bool canceled) {
struct hQueue *queue = &script->hq[arena->queue_id];
int i;

if( !arena->ongoing )
return;

for( i = 0; i < queue->items; i++ ) {
struct map_session_data * sd = NULL;

if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
bg->queue_pc_cleanup(sd);
if( canceled )
clif->colormes(sd->fd,COLOR_RED,"BG Match Cancelled: not enough players");
else {
pc_setglobalreg(sd, arena->delay_var, time(NULL));
}
}
}

bg->arena[i]->begin_timer = INVALID_TIMER;
bg->arena[i]->fillup_timer = INVALID_TIMER;
arena->begin_timer = INVALID_TIMER;
arena->fillup_timer = INVALID_TIMER;
arena->ongoing = false;
/* reset queue */
script->queue_clear(arena->queue_id);
}
Expand All @@ -496,7 +507,9 @@ void bg_begin(struct bg_arena *arena) {
if( count < arena->min_players ) {
bg->match_over(arena,true);
} else {
arena->ongoing = true;
mapreg_setreg(add_str("$@bg_queue_id"),arena->queue_id);/* TODO: make this a arena-independant var? or just .@? */
mapreg_setregstr(add_str("$@bg_delay_var$"),bg->gdelay_var);
npc_event_do(arena->npc_event);
/* we split evenly? */
/* but if a party of say 10 joins, it cant be split evenly unless by luck there are 10 soloers in the queue besides them */
Expand All @@ -506,6 +519,7 @@ void bg_begin(struct bg_arena *arena) {
}
int bg_begin_timer(int tid, unsigned int tick, int id, intptr_t data) {
bg->begin(bg->arena[id]);
bg->arena[id]->begin_timer = INVALID_TIMER;
return 0;
}

Expand All @@ -524,12 +538,12 @@ void bg_queue_pregame(struct bg_arena *arena) {
}
int bg_fillup_timer(int tid, unsigned int tick, int id, intptr_t data) {
bg->queue_pregame(bg->arena[id]);
bg->arena[id]->fillup_timer = INVALID_TIMER;
return 0;
}

void bg_queue_check(struct bg_arena *arena) {
int count = script->hq[arena->queue_id].items;

if( count == arena->max_players ) {
if( arena->fillup_timer != INVALID_TIMER ) {
iTimer->delete_timer(arena->fillup_timer,bg_fillup_timer);
Expand Down Expand Up @@ -642,7 +656,7 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
return BGQA_FAIL_DESERTER;
}

if ( ( tick = pc_readglobalreg(sd, arena->cooldown_variable) ) && tsec < tick ) {
if ( ( tick = pc_readglobalreg(sd, arena->delay_var) ) && tsec < tick ) {
char response[100];
if( (tick-tsec) > 60 )
sprintf(response, "You can't reapply to this arena so fast. Apply to the different arena or wait %d minute(s)",(tick-tsec)/60);
Expand Down
2 changes: 1 addition & 1 deletion src/map/battleground.h
Expand Up @@ -67,7 +67,6 @@ struct bg_arena {
short min_players;
short max_players;
short min_team_players;
char cooldown_variable[NAME_LENGTH];
char delay_var[NAME_LENGTH];
unsigned short maxDuration;
int queue_id;
Expand All @@ -76,6 +75,7 @@ struct bg_arena {
int game_timer;
unsigned short fillup_duration;
unsigned short pregame_duration;
bool ongoing;
};

/* battleground.c interface (incomplete) */
Expand Down

0 comments on commit 449a41a

Please sign in to comment.