Skip to content

Commit

Permalink
BG Queue Fixes
Browse files Browse the repository at this point in the history
Cleared 3 out of 5, #69
Support for the cancel button, for pre-game position to return afterwards and fix to the queue position problem after first game.

Signed-off-by: shennetsind <ind@henn.et>
  • Loading branch information
shennetsind committed Jul 29, 2013
1 parent 640c667 commit 7aa9e6e
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 93 deletions.
4 changes: 2 additions & 2 deletions db/const.txt
Expand Up @@ -3161,6 +3161,6 @@ IT_AMMO 10
IT_DELAYCONSUME 11
IT_CASH 18

HQO_OnDeath 1
HQO_OnLogout 2
HQO_OnLogout 1
HQO_OnDeath 2
HQO_OnMapChange 3
5 changes: 2 additions & 3 deletions npc/custom/bgqueue/flavius.txt
Expand Up @@ -26,6 +26,7 @@ OnInit:

//$@bg_queue_id is cleared after this event ends
OnPlayerListReady:

set $@FlaviusBG1_id1, bg_create_team("bat_b01",10,290);
set $@FlaviusBG1_id2, bg_create_team("bat_b01",390,10);

Expand Down Expand Up @@ -121,9 +122,9 @@ L_OnPlayerQuit:

OnMatchOver:
if( $@FlaviusBG1_id1 || $@FlaviusBG1_id2 ) {
bg_match_over("Flavius");
queuedel($@Croix_QueueBG1);
queuedel($@Guill_QueueBG1);
bg_match_over("Flavius");
}
if( $@FlaviusBG1_id1 ) { bg_destroy $@FlaviusBG1_id1; set $@FlaviusBG1_id1, 0; }
if( $@FlaviusBG1_id2 ) { bg_destroy $@FlaviusBG1_id2; set $@FlaviusBG1_id2, 0; }
Expand Down Expand Up @@ -186,11 +187,9 @@ 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;
}
Expand Down
82 changes: 53 additions & 29 deletions src/map/battleground.c
Expand Up @@ -93,6 +93,15 @@ int bg_team_join(int bg_id, struct map_session_data *sd)
bg->members[i].sd = sd;
bg->members[i].x = sd->bl.x;
bg->members[i].y = sd->bl.y;
/* populate 'where i came from' */
if(map[sd->bl.m].flag.nosave || map[sd->bl.m].instance_id >= 0){
struct map_data *m=&map[sd->bl.m];
if(m->save.map)
memcpy(&bg->members[i].source,&m->save,sizeof(struct point));
else
memcpy(&bg->members[i].source,&sd->status.save_point,sizeof(struct point));
} else
memcpy(&bg->members[i].source,&sd->status.last_point,sizeof(struct point));
bg->count++;

guild->send_dot_remove(sd);
Expand All @@ -115,7 +124,6 @@ int bg_team_leave(struct map_session_data *sd, int flag)

if( sd == NULL || !sd->bg_id )
return 0;

bg_send_dot_remove(sd);
bg_id = sd->bg_id;
sd->bg_id = 0;
Expand All @@ -124,21 +132,28 @@ int bg_team_leave(struct map_session_data *sd, int flag)
return 0;

ARR_FIND(0, MAX_BG_MEMBERS, i, bg_data->members[i].sd == sd);
if( i < MAX_BG_MEMBERS ) // Removes member from BG
if( i < MAX_BG_MEMBERS ) { // Removes member from BG
if( sd->bg_queue.arena ) {
bg->queue_pc_cleanup(sd);
pc->setpos(sd,bg_data->members[i].source.map, bg_data->members[i].source.x, bg_data->members[i].source.y, CLR_OUTSIGHT);
}
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_data, 0, "Server", output, strlen(output) + 1);
if( --bg_data->count != 0 ) {
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_data, 0, "Server", output, strlen(output) + 1);
}

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

if( sd->bg_queue.arena )
if( sd->bg_queue.arena ) {
bg->queue_pc_cleanup(sd);
}

return bg_data->count;
}
Expand Down Expand Up @@ -415,10 +430,13 @@ struct bg_arena *bg_name2arena (char *name) {
int bg_id2pos ( int queue_id, int account_id ) {
struct hQueue *queue = script->queue(queue_id);
if( queue ) {
int i;
for(i = 0; i < queue->items; i++ ) {
if( queue->item[i] == account_id ) {
return i;
int i, pos = 1;
for(i = 0; i < queue->size; i++ ) {
if( queue->item[i] > 0 ) {
if( queue->item[i] == account_id ) {
return pos;
}
pos++;
}
}
}
Expand All @@ -436,14 +454,14 @@ void bg_queue_ready_ack (struct bg_arena *arena, struct map_session_data *sd, bo
int i, count = 0;
sd->bg_queue.ready = 1;

for( i = 0; i < queue->items; i++ ) {
if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
for( i = 0; i < queue->size; i++ ) {
if( queue->item[i] > 0 && ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( sd->bg_queue.ready == 1 )
count++;
}
}
/* check if all are ready then cancell timer, and start game */
if( count == i ) {
if( count == queue->items ) {
iTimer->delete_timer(arena->begin_timer,bg->begin_timer);
arena->begin_timer = INVALID_TIMER;
bg->begin(arena);
Expand All @@ -454,7 +472,10 @@ void bg_queue_ready_ack (struct bg_arena *arena, struct map_session_data *sd, bo
}
void bg_queue_player_cleanup(struct map_session_data *sd) {
if ( sd->bg_queue.client_has_bg_data ) {
clif->bgqueue_notice_delete(sd,BGQND_CLOSEWINDOW, sd->bg_queue.arena ? sd->bg_queue.arena->id : 0);
if( sd->bg_queue.arena )
clif->bgqueue_notice_delete(sd,BGQND_CLOSEWINDOW,sd->bg_queue.arena->name);
else
clif->bgqueue_notice_delete(sd,BGQND_FAIL_NOT_QUEUING,bg->arena[0]->name);
}
if( sd->bg_queue.arena )
script->queue_remove(sd->bg_queue.arena->queue_id,sd->status.account_id);
Expand All @@ -469,12 +490,16 @@ void bg_match_over(struct bg_arena *arena, bool canceled) {

if( !arena->ongoing )
return;

for( i = 0; i < queue->items; i++ ) {
arena->ongoing = false;

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

if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
bg->queue_pc_cleanup(sd);
if( queue->item[i] > 0 && ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( sd->bg_queue.arena ) {
bg_team_leave(sd, 0);
bg->queue_pc_cleanup(sd);
}
if( canceled )
clif->colormes(sd->fd,COLOR_RED,"BG Match Cancelled: not enough players");
else {
Expand All @@ -485,18 +510,17 @@ void bg_match_over(struct bg_arena *arena, bool canceled) {

arena->begin_timer = INVALID_TIMER;
arena->fillup_timer = INVALID_TIMER;
arena->ongoing = false;
/* 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;

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

if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( queue->item[i] > 0 && ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( sd->bg_queue.ready == 1 )
count++;
else
Expand Down Expand Up @@ -527,10 +551,10 @@ void bg_queue_pregame(struct bg_arena *arena) {
struct hQueue *queue = &script->hq[arena->queue_id];
int i;

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

if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( queue->item[i] > 0 && ( sd = iMap->id2sd(queue->item[i]) ) ) {
clif->bgqueue_battlebegins(sd,arena->id,SELF);
}
}
Expand Down Expand Up @@ -594,7 +618,7 @@ void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_q
clif->bgqueue_ack(sd,BGQA_FAIL_PPL_OVERAMOUNT,arena->id);
return;
}

switch( type ) {
case BGQT_INDIVIDUAL:
sd->bg_queue.type = type;
Expand Down Expand Up @@ -630,7 +654,7 @@ void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_q
}
break;
}

clif->bgqueue_ack(sd,BGQA_SUCCESS,arena->id);

bg->queue_check(arena);
Expand Down
1 change: 1 addition & 0 deletions src/map/battleground.h
Expand Up @@ -29,6 +29,7 @@ struct battleground_member_data {
unsigned short x, y;
struct map_session_data *sd;
unsigned afk : 1;
struct point source;/* where did i come from before i join? */
};

struct battleground_data {
Expand Down
31 changes: 16 additions & 15 deletions src/map/clif.c
Expand Up @@ -558,10 +558,10 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
if( sd && sd->bg_queue.arena ) {
struct hQueue *queue = &script->hq[sd->bg_queue.arena->queue_id];

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

if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
if( queue->item[i] > 0 && ( sd = iMap->id2sd(queue->item[i]) ) ) {
WFIFOHEAD(sd->fd,len);
memcpy(WFIFOP(sd->fd,0), buf, len);
WFIFOSET(sd->fd,len);
Expand Down Expand Up @@ -15894,7 +15894,7 @@ void clif_bg_message(struct battleground_data *bg, int src_id, const char *name,
{
struct map_session_data *sd;
unsigned char *buf;
if( (sd = bg_getavailablesd(bg)) == NULL )
if( !bg->count || (sd = bg_getavailablesd(bg)) == NULL )
return;

buf = (unsigned char*)aMalloc((len + NAME_LENGTH + 8)*sizeof(unsigned char));
Expand Down Expand Up @@ -17426,12 +17426,12 @@ void clif_bgqueue_ack(struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_ACK
}


void clif_bgqueue_notice_delete(struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_NOTICE_DELETED response, unsigned char arena_id) {
void clif_bgqueue_notice_delete(struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_NOTICE_DELETED response, char *name) {
struct packet_bgqueue_notice_delete p;

p.PacketType = bgqueue_notice_deleteType;
p.type = response;
safestrncpy(p.bg_name, bg->arena[arena_id]->name, sizeof(p.bg_name));
safestrncpy(p.bg_name, name, sizeof(p.bg_name));

clif->send(&p,sizeof(p), &sd->bl, SELF);
}
Expand Down Expand Up @@ -17474,33 +17474,34 @@ void clif_bgqueue_update_info(struct map_session_data *sd, unsigned char arena_i
}

void clif_parse_bgqueue_checkstate(int fd, struct map_session_data *sd) {
//struct packet_bgqueue_checkstate *p = P2PTR(fd, bgqueue_checkstateType); /* TODO: bgqueue_notice_delete should use this p->bg_name */
if( !bg->queue_on ) return; /* temp, until feature is complete */
struct packet_bgqueue_checkstate *p = P2PTR(fd);

if ( sd->bg_queue.arena && sd->bg_queue.type ) {
clif->bgqueue_update_info(sd,sd->bg_queue.arena->id,bg->id2pos(sd->bg_queue.arena->queue_id,sd->status.account_id));
} else
clif->bgqueue_notice_delete(sd, BGQND_FAIL_NOT_QUEUING,0);/* TODO: wrong response, should respond with p->bg_name not id 0 */
clif->bgqueue_notice_delete(sd, BGQND_FAIL_NOT_QUEUING,p->bg_name);
}

void clif_parse_bgqueue_revoke_req(int fd, struct map_session_data *sd) {
//struct packet_bgqueue_revoke_req *p = P2PTR(fd, bgqueue_revokereqType);
return;
//bg->queue_leave(sd, p->bg_name);
struct packet_bgqueue_revoke_req *p = P2PTR(fd);

if( sd->bg_queue.arena )
bg->queue_pc_cleanup(sd);
else
clif->bgqueue_notice_delete(sd, BGQND_FAIL_NOT_QUEUING,p->bg_name);
}

void clif_parse_bgqueue_battlebegin_ack(int fd, struct map_session_data *sd) {
struct packet_bgqueue_battlebegin_ack *p = P2PTR(fd);
struct bg_arena *arena;

if( !bg->queue_on ) return; /* temp, until feature is complete */

if( ( arena = bg->name2arena(p->bg_name) ) ) {
bg->queue_ready_ack(arena,sd, ( p->result == 1 ) ? true : false);
} else {
clif->bgqueue_ack(sd,BGQA_FAIL_BGNAME_INVALID, 0);
}
//if ( p->result == 1 )
// bg->queue_pc_ready(sd);
//else
// bg->queue_leave(sd, p->bg_name);
}

void clif_bgqueue_joined(struct map_session_data *sd, int pos) {
Expand Down
2 changes: 1 addition & 1 deletion src/map/clif.h
Expand Up @@ -906,7 +906,7 @@ struct clif_interface {
void (*elemental_updatestatus) (struct map_session_data *sd, int type);
/* bgqueue */
void (*bgqueue_ack) (struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_ACK response, unsigned char arena_id);
void (*bgqueue_notice_delete) (struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_NOTICE_DELETED response, unsigned char arena_id);
void (*bgqueue_notice_delete) (struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_NOTICE_DELETED response, char *name);
void (*bgqueue_update_info) (struct map_session_data *sd, unsigned char arena_id, int position);
void (*bgqueue_joined) (struct map_session_data *sd, int pos);
void (*bgqueue_pcleft) (struct map_session_data *sd);
Expand Down
2 changes: 1 addition & 1 deletion src/map/map.c
Expand Up @@ -1536,7 +1536,7 @@ int map_quit(struct map_session_data *sd) {
if (sd->npc_id)
npc_event_dequeue(sd);

if( sd->bg_id )
if( sd->bg_id && !sd->bg_queue.arena ) /* TODO: dump this chunk after bg_queue is fully enabled */
bg_team_leave(sd,1);

skill->cooldown_save(sd);
Expand Down

0 comments on commit 7aa9e6e

Please sign in to comment.