void bg_match_over(struct bg_arena *arena, bool canceled) {
struct hQueue *queue = &script->hq[arena->queue_id];
int i;
nullpo_retv(arena);
if( !arena->ongoing )
return;
arena->ongoing = false;
for( i = 0; i < queue->size; i++ ) {
struct map_session_data * sd = NULL;
if (queue->item[i] > 0 && (sd = map->id2sd(queue->item[i])) != NULL) {
if( sd->bg_queue.arena ) {
bg->team_leave(sd, 0);
bg->queue_pc_cleanup(sd);
}
if (canceled)
clif->messagecolor_self(sd->fd, COLOR_RED, "BG Match Canceled: not enough players");
else
pc_setglobalreg(sd, script->add_str(arena->delay_var), (unsigned int)time(NULL));
}
}
arena->begin_timer = INVALID_TIMER;
arena->fillup_timer = INVALID_TIMER;
/* reset queue */
script->queue_clear(arena->queue_id);
}
void bg_begin(struct bg_arena *arena) {
struct hQueue *queue = &script->hq[arena->queue_id];
int i, count = 0;
nullpo_retv(arena);
for( i = 0; i < queue->size; i++ ) {
struct map_session_data * sd = NULL;
if (queue->item[i] > 0 && (sd = map->id2sd(queue->item[i])) != NULL) {
if( sd->bg_queue.ready == 1 )
count++;
else
bg->queue_pc_cleanup(sd);
}
}
/* TODO/FIXME? I *think* it should check what kind of queue the player used, then check if his party/guild
* (his team) still meet the join criteria (sort of what bg->can_queue does)
*/
if( count < arena->min_players ) {
bg->match_over(arena,true);
} else {
arena->ongoing = true;
/* TODO: make this a arena-independant var? or just .@? */
mapreg->setreg(script->add_str("$@bg_queue_id"),arena->queue_id);
mapreg->setregstr(script->add_str("$@bg_delay_var$"),bg->gdelay_var);
count = 0;
for( i = 0; i < queue->size; i++ ) {
struct map_session_data * sd = NULL;
if (queue->item[i] > 0 && (sd = map->id2sd(queue->item[i])) != NULL) {
if( sd->bg_queue.ready == 1 ) {
mapreg->setreg(reference_uid(script->add_str("$@bg_member"), count), sd->status.account_id);
mapreg->setreg(reference_uid(script->add_str("$@bg_member_group"), count),
sd->bg_queue.type == BGQT_GUILD ? sd->status.guild_id :
sd->bg_queue.type == BGQT_PARTY ? sd->status.party_id :
0
);
mapreg->setreg(reference_uid(script->add_str("$@bg_member_type"), count),
sd->bg_queue.type == BGQT_GUILD ? 1 :
sd->bg_queue.type == BGQT_PARTY ? 2 :
0
);
count++;
}
}
}
mapreg->setreg(script->add_str("$@bg_member_size"),count);
npc->event_do(arena->npc_event);
}
}
//other part of battleground.c
// FIXME Maybe
//nullpo_retv(sd);
//nullpo_retv(arena);
//if( arena->begin_timer != INVALID_TIMER || arena->ongoing ) {
if( arena->begin_timer != INVALID_TIMER ) {
clif->bgqueue_ack(sd,BGQA_FAIL_QUEUING_FINISHED,arena->id);
return;
}
if( result != BGQA_SUCCESS ) {
clif->bgqueue_ack(sd,result,arena->id);
return;
}