summaryrefslogtreecommitdiff
path: root/src/map/battleground.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map/battleground.c')
-rw-r--r--src/map/battleground.c155
1 files changed, 95 insertions, 60 deletions
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 629122c87..7a9d54266 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -2,8 +2,8 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
- * Copyright (C) Athena Dev Teams
+ * Copyright (C) 2012-2020 Hercules Dev Team
+ * Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -47,16 +47,18 @@
#include <stdio.h>
#include <string.h>
-struct battleground_interface bg_s;
+static struct battleground_interface bg_s;
struct battleground_interface *bg;
/// Search a BG Team using bg_id
-struct battleground_data* bg_team_search(int bg_id) {
+static struct battleground_data* bg_team_search(int bg_id)
+{
if( !bg_id ) return NULL;
return (struct battleground_data *)idb_get(bg->team_db, bg_id);
}
-struct map_session_data* bg_getavailablesd(struct battleground_data *bgd) {
+static struct map_session_data* bg_getavailablesd(struct battleground_data *bgd)
+{
int i;
nullpo_retr(NULL, bgd);
ARR_FIND(0, MAX_BG_MEMBERS, i, bgd->members[i].sd != NULL);
@@ -64,7 +66,8 @@ struct map_session_data* bg_getavailablesd(struct battleground_data *bgd) {
}
/// Deletes BG Team from db
-bool bg_team_delete(int bg_id) {
+static bool bg_team_delete(int bg_id)
+{
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
@@ -82,7 +85,8 @@ bool bg_team_delete(int bg_id) {
}
/// Warps a Team
-bool bg_team_warp(int bg_id, unsigned short map_index, short x, short y) {
+static bool bg_team_warp(int bg_id, unsigned short map_index, short x, short y)
+{
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
if( bgd == NULL ) return false;
@@ -91,13 +95,15 @@ bool bg_team_warp(int bg_id, unsigned short map_index, short x, short y) {
return true;
}
-void bg_send_dot_remove(struct map_session_data *sd) {
+static void bg_send_dot_remove(struct map_session_data *sd)
+{
if( sd && sd->bg_id )
clif->bg_xy_remove(sd);
}
/// Player joins team
-bool bg_team_join(int bg_id, struct map_session_data *sd) {
+static bool bg_team_join(int bg_id, struct map_session_data *sd)
+{
int i;
struct battleground_data *bgd = bg->team_search(bg_id);
@@ -135,7 +141,8 @@ bool bg_team_join(int bg_id, struct map_session_data *sd) {
}
/// Single Player leaves team
-int bg_team_leave(struct map_session_data *sd, enum bg_team_leave_type flag) {
+static int bg_team_leave(struct map_session_data *sd, enum bg_team_leave_type flag)
+{
int i, bg_id;
struct battleground_data *bgd;
@@ -162,16 +169,16 @@ int bg_team_leave(struct map_session_data *sd, enum bg_team_leave_type flag) {
switch (flag) {
default:
case BGTL_QUIT:
- sprintf(output, "Server : %s has quit the game...", sd->status.name);
+ sprintf(output, msg_txt(464), sd->status.name); // Server : %s has quit the game...
break;
case BGTL_LEFT:
- sprintf(output, "Server : %s is leaving the battlefield...", sd->status.name);
+ sprintf(output, msg_txt(454), sd->status.name); // Server : %s is leaving the battlefield...
break;
case BGTL_AFK:
- sprintf(output, "Server : %s has been afk-kicked from the battlefield...", sd->status.name);
+ sprintf(output, msg_txt(455), sd->status.name); // Server : %s has been afk-kicked from the battlefield...
break;
}
- clif->bg_message(bgd, 0, "Server", output, strlen(output) + 1);
+ clif->bg_message(bgd, 0, "Server", output);
}
if( bgd->logout_event[0] && flag )
@@ -185,7 +192,8 @@ int bg_team_leave(struct map_session_data *sd, enum bg_team_leave_type flag) {
}
/// Respawn after killed
-bool bg_member_respawn(struct map_session_data *sd) {
+static bool bg_member_respawn(struct map_session_data *sd)
+{
struct battleground_data *bgd;
if( sd == NULL || !pc_isdead(sd) || !sd->bg_id || (bgd = bg->team_search(sd->bg_id)) == NULL )
return false;
@@ -197,7 +205,8 @@ bool bg_member_respawn(struct map_session_data *sd) {
return true; // Warped
}
-int bg_create(unsigned short map_index, short rx, short ry, const char *ev, const char *dev) {
+static int bg_create(unsigned short map_index, short rx, short ry, const char *ev, const char *dev)
+{
struct battleground_data *bgd;
bg->team_counter++;
@@ -216,7 +225,8 @@ int bg_create(unsigned short map_index, short rx, short ry, const char *ev, cons
return bgd->bg_id;
}
-int bg_team_get_id(struct block_list *bl) {
+static int bg_team_get_id(struct block_list *bl)
+{
nullpo_ret(bl);
switch( bl->type ) {
case BL_PC:
@@ -265,21 +275,22 @@ int bg_team_get_id(struct block_list *bl) {
return 0;
}
-bool bg_send_message(struct map_session_data *sd, const char *mes, int len) {
+static bool bg_send_message(struct map_session_data *sd, const char *mes)
+{
struct battleground_data *bgd;
nullpo_ret(sd);
nullpo_ret(mes);
if( sd->bg_id == 0 || (bgd = bg->team_search(sd->bg_id)) == NULL )
return false; // Couldn't send message
- clif->bg_message(bgd, sd->bl.id, sd->status.name, mes, len);
+ clif->bg_message(bgd, sd->bl.id, sd->status.name, mes);
return true;
}
/**
* @see DBApply
*/
-int bg_send_xy_timer_sub(union DBKey key, struct DBData *data, va_list ap)
+static int bg_send_xy_timer_sub(union DBKey key, struct DBData *data, va_list ap)
{
struct battleground_data *bgd = DB->data2ptr(data);
struct map_session_data *sd;
@@ -297,12 +308,14 @@ int bg_send_xy_timer_sub(union DBKey key, struct DBData *data, va_list ap)
return 0;
}
-int bg_send_xy_timer(int tid, int64 tick, int id, intptr_t data) {
+static int bg_send_xy_timer(int tid, int64 tick, int id, intptr_t data)
+{
bg->team_db->foreach(bg->team_db, bg->send_xy_timer_sub, tick);
return 0;
}
-enum bg_queue_types bg_str2teamtype (const char *str) {
+static enum bg_queue_types bg_str2teamtype(const char *str)
+{
char temp[200], *parse;
enum bg_queue_types type = BGQT_INVALID;
@@ -330,7 +343,8 @@ enum bg_queue_types bg_str2teamtype (const char *str) {
return type;
}
-void bg_config_read(void) {
+static void bg_config_read(void)
+{
struct config_t bg_conf;
struct config_setting_t *data = NULL;
const char *config_filename = "conf/battlegrounds.conf"; // FIXME hardcoded name
@@ -496,7 +510,8 @@ void bg_config_read(void) {
}
libconfig->destroy(&bg_conf);
}
-struct bg_arena *bg_name2arena(const char *name)
+
+static struct bg_arena *bg_name2arena(const char *name)
{
int i;
nullpo_retr(NULL, name);
@@ -516,7 +531,7 @@ struct bg_arena *bg_name2arena(const char *name)
* @return the position (starting at 1).
* @retval 0 if the queue doesn't exist or the given account ID isn't present in it.
*/
-int bg_id2pos(int queue_id, int account_id)
+static int bg_id2pos(int queue_id, int account_id)
{
struct script_queue *queue = script->queue(queue_id);
if (queue) {
@@ -529,7 +544,7 @@ int bg_id2pos(int queue_id, int account_id)
return 0;
}
-void bg_queue_ready_ack(struct bg_arena *arena, struct map_session_data *sd, bool response)
+static void bg_queue_ready_ack(struct bg_arena *arena, struct map_session_data *sd, bool response)
{
nullpo_retv(arena);
nullpo_retv(sd);
@@ -560,7 +575,8 @@ void bg_queue_ready_ack(struct bg_arena *arena, struct map_session_data *sd, boo
}
}
-void bg_queue_player_cleanup(struct map_session_data *sd) {
+static void bg_queue_player_cleanup(struct map_session_data *sd)
+{
nullpo_retv(sd);
if ( sd->bg_queue.client_has_bg_data ) {
if( sd->bg_queue.arena )
@@ -575,7 +591,9 @@ void bg_queue_player_cleanup(struct map_session_data *sd) {
sd->bg_queue.client_has_bg_data = 0;
sd->bg_queue.type = 0;
}
-void bg_match_over(struct bg_arena *arena, bool canceled) {
+
+static void bg_match_over(struct bg_arena *arena, bool canceled)
+{
struct script_queue *queue = script->queue(arena->queue_id);
int i;
@@ -597,7 +615,7 @@ void bg_match_over(struct bg_arena *arena, bool canceled) {
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));
+ pc_setglobalreg(sd, script->add_variable(arena->delay_var), (unsigned int)time(NULL));
}
arena->begin_timer = INVALID_TIMER;
@@ -605,7 +623,9 @@ void bg_match_over(struct bg_arena *arena, bool canceled) {
/* reset queue */
script->queue_clear(arena->queue_id);
}
-void bg_begin(struct bg_arena *arena) {
+
+static void bg_begin(struct bg_arena *arena)
+{
struct script_queue *queue = script->queue(arena->queue_id);
int i, count = 0;
@@ -634,8 +654,8 @@ void bg_begin(struct bg_arena *arena) {
bg->afk_timer_id = timer->add(timer->gettick()+10000,bg->afk_timer,0,0);
/* TODO: make this a arena-independent 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);
+ mapreg->setreg(script->add_variable("$@bg_queue_id"),arena->queue_id);
+ mapreg->setregstr(script->add_variable("$@bg_delay_var$"),bg->gdelay_var);
count = 0;
for (i = 0; i < VECTOR_LENGTH(queue->entries); i++) {
@@ -644,31 +664,34 @@ void bg_begin(struct bg_arena *arena) {
if (sd == NULL || sd->bg_queue.ready != 1)
continue;
- 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),
+ mapreg->setreg(reference_uid(script->add_variable("$@bg_member"), count), sd->status.account_id);
+ mapreg->setreg(reference_uid(script->add_variable("$@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),
+ mapreg->setreg(reference_uid(script->add_variable("$@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);
+ mapreg->setreg(script->add_variable("$@bg_member_size"),count);
npc->event_do(arena->npc_event);
}
}
-int bg_begin_timer(int tid, int64 tick, int id, intptr_t data) {
+
+static int bg_begin_timer(int tid, int64 tick, int id, intptr_t data)
+{
bg->begin(bg->arena[id]);
bg->arena[id]->begin_timer = INVALID_TIMER;
return 0;
}
-int bg_afk_timer(int tid, int64 tick, int id, intptr_t data) {
+static int bg_afk_timer(int tid, int64 tick, int id, intptr_t data)
+{
struct s_mapiterator* iter;
struct map_session_data* sd;
int count = 0;
@@ -690,7 +713,8 @@ int bg_afk_timer(int tid, int64 tick, int id, intptr_t data) {
return 0;
}
-void bg_queue_pregame(struct bg_arena *arena) {
+static void bg_queue_pregame(struct bg_arena *arena)
+{
struct script_queue *queue;
int i;
nullpo_retv(arena);
@@ -705,13 +729,16 @@ void bg_queue_pregame(struct bg_arena *arena) {
}
arena->begin_timer = timer->add( timer->gettick() + (arena->pregame_duration*1000), bg->begin_timer, arena->id, 0 );
}
-int bg_fillup_timer(int tid, int64 tick, int id, intptr_t data) {
+
+static int bg_fillup_timer(int tid, int64 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) {
+static void bg_queue_check(struct bg_arena *arena)
+{
int count;
struct script_queue *queue;
nullpo_retv(arena);
@@ -728,7 +755,9 @@ void bg_queue_check(struct bg_arena *arena) {
arena->fillup_timer = timer->add( timer->gettick() + (arena->fillup_duration*1000), bg->fillup_timer, arena->id, 0 );
}
}
-void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type) {
+
+static void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type)
+{
enum BATTLEGROUNDS_QUEUE_ACK result = bg->can_queue(sd,arena,type);
struct script_queue *queue = NULL;
int i, count = 0;
@@ -809,7 +838,9 @@ void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_q
clif->bgqueue_ack(sd,BGQA_SUCCESS,arena->id);
bg->queue_check(arena);
}
-enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type) {
+
+static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type)
+{
int tick;
unsigned int tsec;
@@ -821,27 +852,27 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
if ( sd->status.base_level > arena->max_level || sd->status.base_level < arena->min_level )
return BGQA_FAIL_LEVEL_INCORRECT;
- if ( !(sd->class_&JOBL_2) ) /* TODO: maybe make this a per-arena setting, so users may make custom arenas like baby-only,whatever. */
+ if ((sd->job & JOBL_2) == 0) /* TODO: maybe make this a per-arena setting, so users may make custom arenas like baby-only,whatever. */
return BGQA_FAIL_CLASS_INVALID;
tsec = (unsigned int)time(NULL);
- if ( ( tick = pc_readglobalreg(sd, script->add_str(bg->gdelay_var)) ) && tsec < tick ) {
+ if ( ( tick = pc_readglobalreg(sd, script->add_variable(bg->gdelay_var)) ) && tsec < tick ) {
char response[100];
if( (tick-tsec) > 60 )
- sprintf(response, "You are a deserter! Wait %u minute(s) before you can apply again", (tick - tsec) / 60);
+ sprintf(response, msg_sd(sd, 456), (tick - tsec) / 60); // You are a deserter! Wait %u minute(s) before you can apply again
else
- sprintf(response, "You are a deserter! Wait %u seconds before you can apply again", (tick - tsec));
+ sprintf(response, msg_sd(sd, 457), (tick - tsec)); // You are a deserter! Wait %u seconds before you can apply again
clif->messagecolor_self(sd->fd, COLOR_RED, response);
return BGQA_FAIL_DESERTER;
}
- if ( ( tick = pc_readglobalreg(sd, script->add_str(arena->delay_var)) ) && tsec < tick ) {
+ if ( ( tick = pc_readglobalreg(sd, script->add_variable(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 %u minute(s)", (tick - tsec) / 60);
+ sprintf(response, msg_sd(sd, 458), (tick - tsec) / 60); // You can't reapply to this arena so fast. Apply to the different arena or wait %u minute(s)
else
- sprintf(response, "You can't reapply to this arena so fast. Apply to the different arena or wait %u seconds", (tick - tsec));
+ sprintf(response, msg_sd(sd, 459), (tick - tsec)); // You can't reapply to this arena so fast. Apply to the different arena or wait %u seconds
clif->messagecolor_self(sd->fd, COLOR_RED, response);
return BGQA_FAIL_COOLDOWN;
}
@@ -861,11 +892,11 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
count++;
}
if ( count < arena->min_team_players ) {
- char response[117];
+ char response[121];
if( count != sd->guild->connect_member && sd->guild->connect_member >= arena->min_team_players )
- sprintf(response, "Can't apply: not enough members in your team/guild that have not entered the queue in individual mode, minimum is %d",arena->min_team_players);
+ sprintf(response, msg_sd(sd, 460), arena->min_team_players); // Can't apply: not enough members in your team/guild that have not entered the queue in individual mode, minimum is %d
else
- sprintf(response, "Can't apply: not enough members in your team/guild, minimum is %d",arena->min_team_players);
+ sprintf(response, msg_sd(sd, 461), arena->min_team_players); // Can't apply: not enough members in your team/guild, minimum is %d
clif->messagecolor_self(sd->fd, COLOR_RED, response);
return BGQA_FAIL_TEAM_COUNT;
}
@@ -893,11 +924,11 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
return BGQA_NOT_PARTY_GUILD_LEADER;
if( count < arena->min_team_players ) {
- char response[117];
+ char response[121];
if( count != p->party.count && p->party.count >= arena->min_team_players )
- sprintf(response, "Can't apply: not enough members in your team/party that have not entered the queue in individual mode, minimum is %d",arena->min_team_players);
+ sprintf(response, msg_sd(sd, 462), arena->min_team_players); // Can't apply: not enough members in your team/party that have not entered the queue in individual mode, minimum is %d
else
- sprintf(response, "Can't apply: not enough members in your team/party, minimum is %d",arena->min_team_players);
+ sprintf(response, msg_sd(sd, 463), arena->min_team_players); // Can't apply: not enough members in your team/party, minimum is %d
clif->messagecolor_self(sd->fd, COLOR_RED, response);
return BGQA_FAIL_TEAM_COUNT;
}
@@ -913,7 +944,9 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
}
return BGQA_SUCCESS;
}
-void do_init_battleground(bool minimal) {
+
+static void do_init_battleground(bool minimal)
+{
if (minimal)
return;
@@ -926,7 +959,7 @@ void do_init_battleground(bool minimal) {
/**
* @see DBApply
*/
-int bg_team_db_final(union DBKey key, struct DBData *data, va_list ap)
+static int bg_team_db_final(union DBKey key, struct DBData *data, va_list ap)
{
struct battleground_data* bgd = DB->data2ptr(data);
@@ -935,7 +968,7 @@ int bg_team_db_final(union DBKey key, struct DBData *data, va_list ap)
return 0;
}
-void do_final_battleground(void)
+static void do_final_battleground(void)
{
bg->team_db->destroy(bg->team_db,bg->team_db_final);
@@ -948,7 +981,9 @@ void do_final_battleground(void)
aFree(bg->arena);
}
}
-void battleground_defaults(void) {
+
+void battleground_defaults(void)
+{
bg = &bg_s;
bg->queue_on = false;