diff options
author | Susu <bruant.bastien@gmail.com> | 2013-07-29 15:16:48 +0200 |
---|---|---|
committer | Susu <bruant.bastien@gmail.com> | 2013-07-29 15:16:48 +0200 |
commit | 5a22b0445416dbf7d0a0ddd95d31c1f068e704b3 (patch) | |
tree | 00ac75b9f22e4602eac87b9203b8faa141c86d65 | |
parent | 9ac2cf7bc508248450ddd9f3eaca32cb6fe715a4 (diff) | |
download | hercules-5a22b0445416dbf7d0a0ddd95d31c1f068e704b3.tar.gz hercules-5a22b0445416dbf7d0a0ddd95d31c1f068e704b3.tar.bz2 hercules-5a22b0445416dbf7d0a0ddd95d31c1f068e704b3.tar.xz hercules-5a22b0445416dbf7d0a0ddd95d31c1f068e704b3.zip |
Added iDuel interface (duel.c)
-rw-r--r-- | src/map/atcommand.c | 28 | ||||
-rw-r--r-- | src/map/duel.c | 388 | ||||
-rw-r--r-- | src/map/duel.h | 46 | ||||
-rw-r--r-- | src/map/map.c | 4 | ||||
-rw-r--r-- | src/map/pc.c | 4 | ||||
-rw-r--r-- | src/map/unit.c | 4 |
6 files changed, 255 insertions, 219 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 069856754..d11fd9a9b 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -7694,8 +7694,8 @@ ACMD(invite) return true; } - if(duel_list[did].max_players_limit > 0 && - duel_list[did].members_count >= duel_list[did].max_players_limit) { + if(iDuel->duel_list[did].max_players_limit > 0 && + iDuel->duel_list[did].members_count >= iDuel->duel_list[did].max_players_limit) { // "Duel: Limit of players is reached." clif->message(fd, msg_txt(351)); @@ -7721,7 +7721,7 @@ ACMD(invite) return true; } - duel_invite(did, sd, target_sd); + iDuel->invite(did, sd, target_sd); // "Duel: Invitation has been sent." clif->message(fd, msg_txt(354)); return true; @@ -7732,7 +7732,7 @@ ACMD(duel) unsigned int maxpl = 0; if(sd->duel_group > 0) { - duel_showinfo(sd->duel_group, sd); + iDuel->showinfo(sd->duel_group, sd); return true; } @@ -7742,7 +7742,7 @@ ACMD(duel) return true; } - if(!duel_checktime(sd)) { + if(!iDuel->checktime(sd)) { char output[CHAT_SIZE_MAX]; // "Duel: You can take part in duel only one time per %d minutes." sprintf(output, msg_txt(356), battle_config.duel_time_interval); @@ -7756,18 +7756,18 @@ ACMD(duel) clif->message(fd, msg_txt(357)); // "Duel: Invalid value." return true; } - duel_create(sd, maxpl); + iDuel->create(sd, maxpl); } else { struct map_session_data *target_sd; target_sd = iMap->nick2sd((char *)message); if(target_sd != NULL) { unsigned int newduel; - if((newduel = duel_create(sd, 2)) != -1) { + if((newduel = iDuel->create(sd, 2)) != -1) { if(target_sd->duel_group > 0 || target_sd->duel_invite > 0) { clif->message(fd, msg_txt(353)); // "Duel: Player already in duel." return true; } - duel_invite(newduel, sd, target_sd); + iDuel->invite(newduel, sd, target_sd); clif->message(fd, msg_txt(354)); // "Duel: Invitation has been sent." } } else { @@ -7777,7 +7777,7 @@ ACMD(duel) } } } else - duel_create(sd, 0); + iDuel->create(sd, 0); return true; } @@ -7791,14 +7791,14 @@ ACMD(leave) return true; } - duel_leave(sd->duel_group, sd); + iDuel->leave(sd->duel_group, sd); clif->message(fd, msg_txt(359)); // "Duel: You left the duel." return true; } ACMD(accept) { - if(!duel_checktime(sd)) { + if(!iDuel->checktime(sd)) { char output[CHAT_SIZE_MAX]; // "Duel: You can take part in duel only one time per %d minutes." sprintf(output, msg_txt(356), battle_config.duel_time_interval); @@ -7812,14 +7812,14 @@ ACMD(accept) return true; } - if( duel_list[sd->duel_invite].max_players_limit > 0 && duel_list[sd->duel_invite].members_count >= duel_list[sd->duel_invite].max_players_limit ) + if( iDuel->duel_list[sd->duel_invite].max_players_limit > 0 && iDuel->duel_list[sd->duel_invite].members_count >= iDuel->duel_list[sd->duel_invite].max_players_limit ) { // "Duel: Limit of players is reached." clif->message(fd, msg_txt(351)); return true; } - duel_accept(sd->duel_invite, sd); + iDuel->accept(sd->duel_invite, sd); // "Duel: Invitation has been accepted." clif->message(fd, msg_txt(361)); return true; @@ -7833,7 +7833,7 @@ ACMD(reject) return true; } - duel_reject(sd->duel_invite, sd); + iDuel->reject(sd->duel_invite, sd); // "Duel: Invitation has been rejected." clif->message(fd, msg_txt(363)); return true; diff --git a/src/map/duel.c b/src/map/duel.c index 9a8b6d12b..80ef1b530 100644 --- a/src/map/duel.c +++ b/src/map/duel.c @@ -1,184 +1,204 @@ -// Copyright (c) Hercules Dev Team, licensed under GNU GPL. -// See the LICENSE file -// Portions Copyright (c) Athena Dev Teams - -#include "../common/cbasetypes.h" - -#include "atcommand.h" // msg_txt -#include "clif.h" -#include "duel.h" -#include "pc.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -struct duel duel_list[MAX_DUEL]; -int duel_count = 0; - -/*========================================== - * Duel organizing functions [LuzZza] - *------------------------------------------*/ -void duel_savetime(struct map_session_data* sd) -{ - time_t timer; - struct tm *t; - - time(&timer); - t = localtime(&timer); - - pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min); -} - -int duel_checktime(struct map_session_data* sd) -{ - int diff; - time_t timer; - struct tm *t; - - time(&timer); - t = localtime(&timer); - - diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME"); - - return !(diff >= 0 && diff < battle_config.duel_time_interval); -} -static int duel_showinfo_sub(struct map_session_data* sd, va_list va) -{ - struct map_session_data *ssd = va_arg(va, struct map_session_data*); - int *p = va_arg(va, int*); - char output[256]; - - if (sd->duel_group != ssd->duel_group) return 0; - - sprintf(output, " %d. %s", ++(*p), sd->status.name); - clif->disp_onlyself(ssd, output, strlen(output)); - return 1; -} - -void duel_showinfo(const unsigned int did, struct map_session_data* sd) -{ - int p=0; - char output[256]; - - if(duel_list[did].max_players_limit > 0) - sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --" - did, duel_count, - duel_list[did].members_count, - duel_list[did].members_count + duel_list[did].invites_count, - duel_list[did].max_players_limit); - else - sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --" - did, duel_count, - duel_list[did].members_count, - duel_list[did].members_count + duel_list[did].invites_count); - - clif->disp_onlyself(sd, output, strlen(output)); - iMap->map_foreachpc(duel_showinfo_sub, sd, &p); -} - -int duel_create(struct map_session_data* sd, const unsigned int maxpl) -{ - int i=1; - char output[256]; - - while(duel_list[i].members_count > 0 && i < MAX_DUEL) i++; - if(i == MAX_DUEL) return 0; - - duel_count++; - sd->duel_group = i; - duel_list[i].members_count++; - duel_list[i].invites_count = 0; - duel_list[i].max_players_limit = maxpl; - - strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --" - clif->disp_onlyself(sd, output, strlen(output)); - - clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); - clif->maptypeproperty2(&sd->bl,SELF); - return i; -} - -void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd) -{ - char output[256]; - - // " -- Player %s invites %s to duel --" - sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - target_sd->duel_invite = did; - duel_list[did].invites_count++; - - // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --" - sprintf(output, msg_txt(374), sd->status.name); - clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, 0x10, SELF); -} - -static int duel_leave_sub(struct map_session_data* sd, va_list va) -{ - int did = va_arg(va, int); - if (sd->duel_invite == did) - sd->duel_invite = 0; - return 0; -} - -void duel_leave(const unsigned int did, struct map_session_data* sd) -{ - char output[256]; - - // " <- Player %s has left duel --" - sprintf(output, msg_txt(375), sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - duel_list[did].members_count--; - - if(duel_list[did].members_count == 0) { - iMap->map_foreachpc(duel_leave_sub, did); - duel_count--; - } - - sd->duel_group = 0; - duel_savetime(sd); - clif->map_property(sd, MAPPROPERTY_NOTHING); - clif->maptypeproperty2(&sd->bl,SELF); -} - -void duel_accept(const unsigned int did, struct map_session_data* sd) -{ - char output[256]; - - duel_list[did].members_count++; - sd->duel_group = sd->duel_invite; - duel_list[did].invites_count--; - sd->duel_invite = 0; - - // " -> Player %s has accepted duel --" - sprintf(output, msg_txt(376), sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - clif->map_property(sd, MAPPROPERTY_FREEPVPZONE); - clif->maptypeproperty2(&sd->bl,SELF); -} - -void duel_reject(const unsigned int did, struct map_session_data* sd) -{ - char output[256]; - - // " -- Player %s has rejected duel --" - sprintf(output, msg_txt(377), sd->status.name); - clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS); - - duel_list[did].invites_count--; - sd->duel_invite = 0; -} - -void do_final_duel(void) -{ -} - -void do_init_duel(void) -{ - memset(&duel_list[0], 0, sizeof(duel_list)); -} +// Copyright (c) Hercules Dev Team, licensed under GNU GPL.
+// See the LICENSE file
+// Portions Copyright (c) Athena Dev Teams
+
+#include "../common/cbasetypes.h"
+
+#include "atcommand.h" // msg_txt
+#include "clif.h"
+#include "duel.h"
+#include "pc.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/*==========================================
+ * Duel organizing functions [LuzZza]
+ *------------------------------------------*/
+void duel_savetime(struct map_session_data* sd)
+{
+ time_t timer;
+ struct tm *t;
+
+ time(&timer);
+ t = localtime(&timer);
+
+ pc_setglobalreg(sd, "PC_LAST_DUEL_TIME", t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
+}
+
+int duel_checktime(struct map_session_data* sd)
+{
+ int diff;
+ time_t timer;
+ struct tm *t;
+
+ time(&timer);
+ t = localtime(&timer);
+
+ diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, "PC_LAST_DUEL_TIME");
+
+ return !(diff >= 0 && diff < battle_config.duel_time_interval);
+}
+static int duel_showinfo_sub(struct map_session_data* sd, va_list va)
+{
+ struct map_session_data *ssd = va_arg(va, struct map_session_data*);
+ int *p = va_arg(va, int*);
+ char output[256];
+
+ if (sd->duel_group != ssd->duel_group) return 0;
+
+ sprintf(output, " %d. %s", ++(*p), sd->status.name);
+ clif->disp_onlyself(ssd, output, strlen(output));
+ return 1;
+}
+
+void duel_showinfo(const unsigned int did, struct map_session_data* sd)
+{
+ int p=0;
+ char output[256];
+
+ if(iDuel->duel_list[did].max_players_limit > 0)
+ sprintf(output, msg_txt(370), //" -- Duels: %d/%d, Members: %d/%d, Max players: %d --"
+ did, iDuel->duel_count,
+ iDuel->duel_list[did].members_count,
+ iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count,
+ iDuel->duel_list[did].max_players_limit);
+ else
+ sprintf(output, msg_txt(371), //" -- Duels: %d/%d, Members: %d/%d --"
+ did, iDuel->duel_count,
+ iDuel->duel_list[did].members_count,
+ iDuel->duel_list[did].members_count + iDuel->duel_list[did].invites_count);
+
+ clif->disp_onlyself(sd, output, strlen(output));
+ iMap->map_foreachpc(duel_showinfo_sub, sd, &p);
+}
+
+int duel_create(struct map_session_data* sd, const unsigned int maxpl)
+{
+ int i=1;
+ char output[256];
+
+ while(iDuel->duel_list[i].members_count > 0 && i < MAX_DUEL) i++;
+ if(i == MAX_DUEL) return 0;
+
+ iDuel->duel_count++;
+ sd->duel_group = i;
+ iDuel->duel_list[i].members_count++;
+ iDuel->duel_list[i].invites_count = 0;
+ iDuel->duel_list[i].max_players_limit = maxpl;
+
+ strcpy(output, msg_txt(372)); // " -- Duel has been created (@invite/@leave) --"
+ clif->disp_onlyself(sd, output, strlen(output));
+
+ clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
+ clif->maptypeproperty2(&sd->bl,SELF);
+ return i;
+}
+
+void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd)
+{
+ char output[256];
+
+ // " -- Player %s invites %s to duel --"
+ sprintf(output, msg_txt(373), sd->status.name, target_sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ target_sd->duel_invite = did;
+ iDuel->duel_list[did].invites_count++;
+
+ // "Blue -- Player %s invites you to PVP duel (@accept/@reject) --"
+ sprintf(output, msg_txt(374), sd->status.name);
+ clif->broadcast((struct block_list *)target_sd, output, strlen(output)+1, 0x10, SELF);
+}
+
+static int duel_leave_sub(struct map_session_data* sd, va_list va)
+{
+ int did = va_arg(va, int);
+ if (sd->duel_invite == did)
+ sd->duel_invite = 0;
+ return 0;
+}
+
+void duel_leave(const unsigned int did, struct map_session_data* sd)
+{
+ char output[256];
+
+ // " <- Player %s has left duel --"
+ sprintf(output, msg_txt(375), sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ iDuel->duel_list[did].members_count--;
+
+ if(iDuel->duel_list[did].members_count == 0) {
+ iMap->map_foreachpc(duel_leave_sub, did);
+ iDuel->duel_count--;
+ }
+
+ sd->duel_group = 0;
+ duel_savetime(sd);
+ clif->map_property(sd, MAPPROPERTY_NOTHING);
+ clif->maptypeproperty2(&sd->bl,SELF);
+}
+
+void duel_accept(const unsigned int did, struct map_session_data* sd)
+{
+ char output[256];
+
+ iDuel->duel_list[did].members_count++;
+ sd->duel_group = sd->duel_invite;
+ iDuel->duel_list[did].invites_count--;
+ sd->duel_invite = 0;
+
+ // " -> Player %s has accepted duel --"
+ sprintf(output, msg_txt(376), sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ clif->map_property(sd, MAPPROPERTY_FREEPVPZONE);
+ clif->maptypeproperty2(&sd->bl,SELF);
+}
+
+void duel_reject(const unsigned int did, struct map_session_data* sd)
+{
+ char output[256];
+
+ // " -- Player %s has rejected duel --"
+ sprintf(output, msg_txt(377), sd->status.name);
+ clif->disp_message(&sd->bl, output, strlen(output), DUEL_WOS);
+
+ iDuel->duel_list[did].invites_count--;
+ sd->duel_invite = 0;
+}
+
+void do_final_duel(void)
+{
+}
+
+void do_init_duel(void)
+{
+ memset(&iDuel->duel_list[0], 0, sizeof(iDuel->duel_list));
+}
+
+/*=====================================
+* Default Functions : duel.h
+* Generated by HerculesInterfaceMaker
+* created by Susu
+*-------------------------------------*/
+void duel_defaults(void) {
+ iDuel = &iDuel_s;
+
/* vars */
+ iDuel->duel_count = 0;
+
/* funcs */
+ //Duel functions // [LuzZza]
+ iDuel->create = duel_create;
+ iDuel->invite = duel_invite;
+ iDuel->accept = duel_accept;
+ iDuel->reject = duel_reject;
+ iDuel->leave = duel_leave;
+ iDuel->showinfo = duel_showinfo;
+ iDuel->checktime = duel_checktime;
+
+ iDuel->do_init_duel = do_init_duel;
+ iDuel->do_final_duel = do_final_duel;
+}
diff --git a/src/map/duel.h b/src/map/duel.h index 04d8e4e84..ec9c4bf83 100644 --- a/src/map/duel.h +++ b/src/map/duel.h @@ -1,6 +1,5 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder - #ifndef _DUEL_H_ #define _DUEL_H_ @@ -11,19 +10,36 @@ struct duel { }; #define MAX_DUEL 1024 -extern struct duel duel_list[MAX_DUEL]; -extern int duel_count; - -//Duel functions // [LuzZza] -int duel_create(struct map_session_data* sd, const unsigned int maxpl); -void duel_invite(const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd); -void duel_accept(const unsigned int did, struct map_session_data* sd); -void duel_reject(const unsigned int did, struct map_session_data* sd); -void duel_leave(const unsigned int did, struct map_session_data* sd); -void duel_showinfo(const unsigned int did, struct map_session_data* sd); -int duel_checktime(struct map_session_data* sd); - -void do_init_duel(void); -void do_final_duel(void); + + + +/*===================================== +* Interface : duel.h +* Generated by HerculesInterfaceMaker +* created by Susu +*-------------------------------------*/ +struct duel_interface { + + /* vars */ + struct duel duel_list[MAX_DUEL]; + int duel_count; + + /* funcs */ + //Duel functions // [LuzZza] + int (*create) (struct map_session_data* sd, const unsigned int maxpl); + void (*invite) (const unsigned int did, struct map_session_data* sd, struct map_session_data* target_sd); + void (*accept) (const unsigned int did, struct map_session_data* sd); + void (*reject) (const unsigned int did, struct map_session_data* sd); + void (*leave) (const unsigned int did, struct map_session_data* sd); + void (*showinfo) (const unsigned int did, struct map_session_data* sd); + int (*checktime) (struct map_session_data* sd); + + void (*do_init_duel) (void); + void (*do_final_duel) (void); +} iDuel_s; + +struct duel_interface *iDuel; + +void duel_defaults(void); #endif /* _DUEL_H_ */ diff --git a/src/map/map.c b/src/map/map.c index 589f6f76d..0fb988351 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4944,7 +4944,7 @@ void do_final(void) iStatus->do_final_status(); do_final_unit(); do_final_battleground(); - do_final_duel(); + iDuel->do_final_duel(); do_final_elemental(); do_final_maps(); vending->final(); @@ -5392,7 +5392,7 @@ int do_init(int argc, char *argv[]) do_init_npc(); do_init_unit(); do_init_battleground(); - do_init_duel(); + iDuel->do_init_duel(); vending->init(); npc_event_do_oninit(); // Init npcs (OnInit) diff --git a/src/map/pc.c b/src/map/pc.c index 11e775dea..ee2e62e92 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -6733,9 +6733,9 @@ int pc_dead(struct map_session_data *sd,struct block_list *src) { // Leave duel if you die [LuzZza] if(battle_config.duel_autoleave_when_die) { if(sd->duel_group > 0) - duel_leave(sd->duel_group, sd); + iDuel->leave(sd->duel_group, sd); if(sd->duel_invite > 0) - duel_reject(sd->duel_invite, sd); + iDuel->reject(sd->duel_invite, sd); } if (sd->npc_id && sd->st && sd->st->state != RUN) diff --git a/src/map/unit.c b/src/map/unit.c index 38606230f..7a1c15838 100644 --- a/src/map/unit.c +++ b/src/map/unit.c @@ -2167,7 +2167,7 @@ int unit_remove_map_(struct block_list *bl, clr_type clrtype, const char* file, sd->pvp_rank = 0; } if(sd->duel_group > 0) - duel_leave(sd->duel_group, sd); + iDuel->leave(sd->duel_group, sd); if(pc_issit(sd)) { pc->setstand(sd); @@ -2343,7 +2343,7 @@ int unit_free(struct block_list *bl, clr_type clrtype) pc->stop_following(sd); if( sd->duel_invite > 0 ) - duel_reject(sd->duel_invite, sd); + iDuel->reject(sd->duel_invite, sd); // Notify friends that this char logged out. [Skotlex] iMap->map_foreachpc(clif->friendslist_toggle_sub, sd->status.account_id, sd->status.char_id, 0); |