summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
Diffstat (limited to 'src/map')
-rw-r--r--src/map/chrif.c1
-rw-r--r--src/map/clif.c10
-rw-r--r--src/map/guild.c140
-rw-r--r--src/map/guild.h5
-rw-r--r--src/map/intif.c33
-rw-r--r--src/map/intif.h2
-rw-r--r--src/map/script.c138
7 files changed, 139 insertions, 190 deletions
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 4c70aff90..a75c48ecb 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -458,6 +458,7 @@ int chrif_connectack(int fd)
if( !char_init_done ) {
char_init_done = true;
ShowStatus("Event '"CL_WHITE"OnInterIfInitOnce"CL_RESET"' executed with '"CL_WHITE"%d"CL_RESET"' NPCs.\n", npc_event_doall("OnInterIfInitOnce"));
+ guild_castle_map_init();
}
return 0;
diff --git a/src/map/clif.c b/src/map/clif.c
index 51d5b802d..c50dd9ee2 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -7054,7 +7054,7 @@ void clif_guild_masterormember(struct map_session_data *sd)
/// 01b6 <guild id>.L <level>.L <member num>.L <member max>.L <exp>.L <max exp>.L <points>.L <honor>.L <virtue>.L <emblem id>.L <name>.24B <master name>.24B <manage land>.16B <zeny>.L (ZC_GUILD_INFO2)
void clif_guild_basicinfo(struct map_session_data *sd)
{
- int fd,i,t;
+ int fd;
struct guild *g;
struct guild_castle *gc = NULL;
@@ -7080,13 +7080,7 @@ void clif_guild_basicinfo(struct map_session_data *sd)
memcpy(WFIFOP(fd,46),g->name, NAME_LENGTH);
memcpy(WFIFOP(fd,70),g->master, NAME_LENGTH);
- for(i = 0, t = 0; i < MAX_GUILDCASTLE; i++)
- {
- gc = guild_castle_search(i);
- if(gc && g->guild_id == gc->guild_id)
- t++;
- }
- safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+t),16); // "'N' castles"
+ safestrncpy((char*)WFIFOP(fd,94),msg_txt(300+guild_checkcastles(g)),16); // "'N' castles"
WFIFOL(fd,110) = 0; // zeny
WFIFOSET(fd,packet_len(0x1b6));
diff --git a/src/map/guild.c b/src/map/guild.c
index ef19e2f8a..75f63b2ae 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -33,7 +33,6 @@ static DBMap* guild_db; // int guild_id -> struct guild*
static DBMap* castle_db; // int castle_id -> struct guild_castle*
static DBMap* guild_expcache_db; // int char_id -> struct guild_expcache*
static DBMap* guild_infoevent_db; // int guild_id -> struct eventlist*
-static DBMap* guild_castleinfoevent_db; // int castle_id_index -> struct eventlist*
struct eventlist {
char name[EVENT_NAME_LENGTH];
@@ -160,10 +159,14 @@ int guild_check_skill_require(struct guild *g,int id)
static bool guild_read_castledb(char* str[], int columns, int current)
{// <castle id>,<map name>,<castle name>,<castle event>[,<reserved/unused switch flag>]
struct guild_castle *gc;
+ int mapindex = mapindex_name2id(str[1]);
+
+ if (map_mapindex2mapid(mapindex) < 0) // Map not found or on another map-server
+ return false;
CREATE(gc, struct guild_castle, 1);
gc->castle_id = atoi(str[0]);
- gc->mapindex = mapindex_name2id(str[1]);
+ gc->mapindex = mapindex;
safestrncpy(gc->castle_name, str[2], sizeof(gc->castle_name));
safestrncpy(gc->castle_event, str[3], sizeof(gc->castle_event));
@@ -1542,28 +1545,29 @@ int castle_guild_broken_sub(DBKey key,void *data,va_list ap)
return 0;
}
-//Innvoked on /breakguild "Guild name"
+//Invoked on /breakguild "Guild name"
int guild_broken(int guild_id,int flag)
{
- struct guild *g=guild_search(guild_id);
- struct guild_castle *gc=NULL;
- struct map_session_data *sd;
+ struct guild *g = guild_search(guild_id);
+ struct guild_castle *gc = NULL;
+ DBIterator *iter = NULL;
+ struct map_session_data *sd = NULL;
int i;
char name[EVENT_NAME_LENGTH];
if(flag!=0 || g==NULL)
return 0;
- //we call castle_event::OnGuildBreak of all castlesof the guild
+ //we call castle_event::OnGuildBreak of all castles of the guild
//you can set all castle_events in the castle_db.txt
- for(i=0;i<MAX_GUILDCASTLE;i++){
- if( (gc=guild_castle_search(i)) != NULL ){
- if(gc->guild_id == guild_id){
- safestrncpy(name, gc->castle_event, 50);
- npc_event_do(strcat(name,"::OnGuildBreak"));
- }
+ iter = db_iterator(castle_db);
+ for (gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter)) {
+ if (gc->guild_id == guild_id) {
+ safestrncpy(name, gc->castle_event, sizeof(name));
+ npc_event_do(strcat(name, "::OnGuildBreak"));
}
}
+ dbi_destroy(iter);
for(i=0;i<g->max_member;i++){ // ギルド解散を通知
if((sd=g->member[i].sd)!=NULL){
@@ -1686,71 +1690,32 @@ int guild_break(struct map_session_data *sd,char *name)
return 0;
}
-// ギルド城データ要求
-int guild_castledataload(int castle_id,int index)
+/**
+ * Creates a list of guild castle IDs to be requested
+ * from char-server.
+ */
+void guild_castle_map_init(void)
{
- return intif_guild_castle_dataload(castle_id,index);
-}
-// ギルド城情報所得時イベント追加
-int guild_addcastleinfoevent(int castle_id,int index,const char *name)
-{
- struct eventlist *ev;
- int code=castle_id|(index<<16);
-
- if( name==NULL || *name==0 )
- return 0;
+ DBIterator* iter = NULL;
+ int num = db_size(castle_db);
- ev = (struct eventlist *)aMalloc(sizeof(struct eventlist));
- strncpy(ev->name,name,ARRAYLENGTH(ev->name));
- //The next event becomes whatever was currently stored.
- ev->next = (struct eventlist *)idb_put(guild_castleinfoevent_db,code,ev);
- return 0;
-}
+ if (num > 0) {
+ struct guild_castle* gc = NULL;
+ int *castle_ids, *cursor;
-// ギルド城データ要求返信
-int guild_castledataloadack(int castle_id,int index,int value)
-{
- struct guild_castle *gc=guild_castle_search(castle_id);
- int code=castle_id|(index<<16);
- struct eventlist *ev,*ev2;
-
- if(gc==NULL){
- return 0;
- }
- switch(index){
- case 1:
- gc->guild_id = value;
- if (gc->guild_id && guild_search(gc->guild_id)==NULL) //Request guild data which will be required for spawned guardians. [Skotlex]
- guild_request_info(gc->guild_id);
- break;
- case 2: gc->economy = value; break;
- case 3: gc->defense = value; break;
- case 4: gc->triggerE = value; break;
- case 5: gc->triggerD = value; break;
- case 6: gc->nextTime = value; break;
- case 7: gc->payTime = value; break;
- case 8: gc->createTime = value; break;
- case 9: gc->visibleC = value; break;
- default:
- if (index > 9 && index <= 9+MAX_GUARDIANS) {
- gc->guardian[index-10].visible = value;
- break;
- }
- ShowError("guild_castledataloadack ERROR!! (Not found castle_id=%d index=%d)\n", castle_id, index);
- return 0;
- }
-
- if( (ev = (struct eventlist *)idb_remove(guild_castleinfoevent_db,code))!=NULL )
- {
- while(ev){
- npc_event_do(ev->name);
- ev2=ev->next;
- aFree(ev);
- ev=ev2;
+ CREATE(castle_ids, int, num);
+ cursor = castle_ids;
+ iter = db_iterator(castle_db);
+ for (gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter)) {
+ *(cursor++) = gc->castle_id;
}
+ dbi_destroy(iter);
+ if (intif_guild_castle_dataload(num, castle_ids))
+ ShowStatus("Requested '"CL_WHITE"%d"CL_RESET"' guild castles from char-server...\n", num);
+ aFree(castle_ids);
}
- return 1;
}
+
// ギルド城データ変更要求
int guild_castledatasave(int castle_id,int index,int value)
{
@@ -1776,7 +1741,7 @@ int guild_castledatasave(int castle_id,int index,int value)
}
}
- return intif_guild_castle_datasave(castle_id,index,value);
+ return intif_guild_castle_datasave(castle_id, index, value); // FIXME: it may fail if char-server is disconnected
}
// ギルド城データ変更通知
@@ -1801,14 +1766,14 @@ int guild_castledatasaveack(int castle_id,int index,int value)
gc->guardian[index-10].visible = value;
break;
}
- ShowError("guild_castledatasaveack ERROR!! (Not found index=%d)\n", index);
+ ShowError("guild_castledatasaveack: not found index=%d\n", index);
return 0;
}
return 1;
}
// ギルドデータ一括受信(初期化時)
-int guild_castlealldataload(int len,struct guild_castle *gc)
+int guild_castledataloadack(int len, struct guild_castle *gc)
{
int i;
int n = (len-4) / sizeof(struct guild_castle);
@@ -1816,7 +1781,7 @@ int guild_castlealldataload(int len,struct guild_castle *gc)
nullpo_ret(gc);
- //Last owned castle in the list invokes ::OnAgitinit
+ //Last owned castle in the list invokes ::OnAgitInit
for( i = n-1; i >= 0 && !(gc[i].guild_id); --i );
ev = i; // offset of castle or -1
@@ -1829,12 +1794,12 @@ int guild_castlealldataload(int len,struct guild_castle *gc)
{
struct guild_castle *c = guild_castle_search(gc->castle_id);
if (!c) {
- ShowError("guild_castlealldataload Castle id=%d not found.\n", gc->castle_id);
+ ShowError("guild_castledataloadack: castle id=%d not found.\n", gc->castle_id);
continue;
}
- // update mapserver castle data with new info
- memcpy(&c->guild_id, &gc->guild_id, sizeof(struct guild_castle) - ((uintptr_t)&c->guild_id - (uintptr_t)c));
+ // update map-server castle data with new info
+ memcpy(&c->guild_id, &gc->guild_id, sizeof(struct guild_castle) - offsetof(struct guild_castle, guild_id));
if( c->guild_id )
{
@@ -1846,7 +1811,7 @@ int guild_castlealldataload(int len,struct guild_castle *gc)
}
}
}
-
+ ShowStatus("Received '"CL_WHITE"%d"CL_RESET"' guild castles from char-server.\n", n);
return 0;
}
@@ -1881,15 +1846,16 @@ int guild_agit2_end(void)
// How many castles does this guild have?
int guild_checkcastles(struct guild *g)
{
- int i, nb_cas = 0;
- struct guild_castle* gc;
+ int nb_cas = 0;
+ struct guild_castle* gc = NULL;
+ DBIterator *iter = db_iterator(castle_db);
- for(i = 0; i < MAX_GUILDCASTLE; i++) {
- gc = guild_castle_search(i);
- if(gc && gc->guild_id == g->guild_id)
+ for (gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter)) {
+ if (gc->guild_id == g->guild_id) {
nb_cas++;
+ }
}
-
+ dbi_destroy(iter);
return nb_cas;
}
@@ -1938,7 +1904,6 @@ void do_init_guild(void)
guild_expcache_db=idb_alloc(DB_OPT_BASE);
guild_infoevent_db=idb_alloc(DB_OPT_BASE);
expcache_ers = ers_new(sizeof(struct guild_expcache));
- guild_castleinfoevent_db=idb_alloc(DB_OPT_BASE);
sv_readdb(db_path, "castle_db.txt", ',', 4, 5, -1, &guild_read_castledb);
@@ -1957,6 +1922,5 @@ void do_final_guild(void)
castle_db->destroy(castle_db,guild_castle_db_final);
guild_expcache_db->destroy(guild_expcache_db,guild_expcache_db_final);
guild_infoevent_db->destroy(guild_infoevent_db,eventlist_db_final);
- guild_castleinfoevent_db->destroy(guild_castleinfoevent_db,eventlist_db_final);
ers_destroy(expcache_ers);
}
diff --git a/src/map/guild.h b/src/map/guild.h
index c6b380647..3af5be6c4 100644
--- a/src/map/guild.h
+++ b/src/map/guild.h
@@ -90,12 +90,11 @@ int guild_broken(int guild_id,int flag);
int guild_gm_change(int guild_id, struct map_session_data *sd);
int guild_gm_changed(int guild_id, int account_id, int char_id);
-int guild_addcastleinfoevent(int castle_id,int index,const char *name);
+void guild_castle_map_init(void);
int guild_castledataload(int castle_id,int index);
-int guild_castledataloadack(int castle_id,int index,int value);
int guild_castledatasave(int castle_id,int index,int value);
int guild_castledatasaveack(int castle_id,int index,int value);
-int guild_castlealldataload(int len,struct guild_castle *gc);
+int guild_castledataloadack(int len, struct guild_castle *gc);
int guild_agit_start(void);
int guild_agit_end(void);
diff --git a/src/map/intif.c b/src/map/intif.c
index 54d039347..20d686c11 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -36,7 +36,7 @@ static const int packet_len_table[]={
0, 0, 0, 0, 0, 0, 0, 0, -1,11, 0, 0, 0, 0, 0, 0, //0x3810
39,-1,15,15, 14,19, 7,-1, 0, 0, 0, 0, 0, 0, 0, 0, //0x3820
10,-1,15, 0, 79,19, 7,-1, 0,-1,-1,-1, 14,67,186,-1, //0x3830
- 9, 9,-1,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
+ -1, 9, 0,14, 0, 0, 0, 0, -1,74,-1,11, 11,-1, 0, 0, //0x3840
-1,-1, 7, 7, 7,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3850 Auctions [Zephyrus]
-1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3860 Quests [Kevin] [Inkfish]
-1, 3, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0x3870 Mercenaries [Zephyrus]
@@ -720,17 +720,22 @@ int intif_guild_emblem(int guild_id,int len,const char *data)
WFIFOSET(inter_fd,len+12);
return 0;
}
-//現在のギルド城占領ギルドを調べる
-int intif_guild_castle_dataload(int castle_id,int index)
+
+/**
+ * Requests guild castles data from char-server.
+ * @param num Number of castles, size of castle_ids array.
+ * @param castle_ids Pointer to array of castle IDs.
+ */
+int intif_guild_castle_dataload(int num, int *castle_ids)
{
if (CheckForCharServer())
return 0;
- WFIFOHEAD(inter_fd,5);
- WFIFOW(inter_fd,0)=0x3040;
- WFIFOW(inter_fd,2)=castle_id;
- WFIFOB(inter_fd,4)=index;
- WFIFOSET(inter_fd,5);
- return 0;
+ WFIFOHEAD(inter_fd, 4 + num * sizeof(int));
+ WFIFOW(inter_fd, 0) = 0x3040;
+ WFIFOW(inter_fd, 2) = 4 + num * sizeof(int);
+ memcpy(WFIFOP(inter_fd, 4), castle_ids, num * sizeof(int));
+ WFIFOSET(inter_fd, WFIFOW(inter_fd, 2));
+ return 1;
}
//ギルド城占領ギルド変更要求
@@ -1072,7 +1077,6 @@ int intif_parse_GuildInfo(int fd)
guild_recv_noinfo(RFIFOL(fd,4));
return 0;
}
-
if( RFIFOW(fd,2)!=sizeof(struct guild)+4 )
ShowError("intif: guild info : data size error Gid: %d recv size: %d Expected size: %d\n",RFIFOL(fd,4),RFIFOW(fd,2),sizeof(struct guild)+4);
guild_recv_info((struct guild *)RFIFOP(fd,4));
@@ -1203,7 +1207,7 @@ int intif_parse_GuildMessage(int fd)
// ギルド城データ要求返信
int intif_parse_GuildCastleDataLoad(int fd)
{
- return guild_castledataloadack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
+ return guild_castledataloadack(RFIFOW(fd,2), (struct guild_castle *)RFIFOP(fd,4));
}
// ギルド城データ変更通知
int intif_parse_GuildCastleDataSave(int fd)
@@ -1211,12 +1215,6 @@ int intif_parse_GuildCastleDataSave(int fd)
return guild_castledatasaveack(RFIFOW(fd,2),RFIFOB(fd,4),RFIFOL(fd,5));
}
-// ギルド城データ一括受信(初期化時)
-int intif_parse_GuildCastleAllDataLoad(int fd)
-{
- return guild_castlealldataload(RFIFOW(fd,2),(struct guild_castle *)RFIFOP(fd,4));
-}
-
int intif_parse_GuildMasterChanged(int fd)
{
return guild_gm_changed(RFIFOL(fd,2),RFIFOL(fd,6),RFIFOL(fd,10));
@@ -2040,7 +2038,6 @@ int intif_parse(int fd)
case 0x383f: intif_parse_GuildEmblem(fd); break;
case 0x3840: intif_parse_GuildCastleDataLoad(fd); break;
case 0x3841: intif_parse_GuildCastleDataSave(fd); break;
- case 0x3842: intif_parse_GuildCastleAllDataLoad(fd); break;
case 0x3843: intif_parse_GuildMasterChanged(fd); break;
//Quest system
diff --git a/src/map/intif.h b/src/map/intif.h
index b1315f40c..c7dc25db4 100644
--- a/src/map/intif.h
+++ b/src/map/intif.h
@@ -56,7 +56,7 @@ int intif_guild_skillup(int guild_id, int skill_num, int account_id, int max);
int intif_guild_alliance(int guild_id1, int guild_id2, int account_id1, int account_id2, int flag);
int intif_guild_notice(int guild_id, const char *mes1, const char *mes2);
int intif_guild_emblem(int guild_id, int len, const char *data);
-int intif_guild_castle_dataload(int castle_id, int index);
+int intif_guild_castle_dataload(int num, int *castle_ids);
int intif_guild_castle_datasave(int castle_id, int index, int value);
int intif_create_pet(int account_id, int char_id, short pet_type, short pet_lv, short pet_egg_id,
diff --git a/src/map/script.c b/src/map/script.c
index 29387fe4e..67e9e722e 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -10139,52 +10139,44 @@ BUILDIN_FUNC(getcastlename)
BUILDIN_FUNC(getcastledata)
{
- const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
+ const char *mapname = mapindex_getmapname(script_getstr(st,2),NULL);
int index = script_getnum(st,3);
+ struct guild_castle *gc = guild_mapname2gc(mapname);
- struct guild_castle* gc = guild_mapname2gc(mapname);
+ if (gc == NULL) {
+ script_pushint(st,0);
+ ShowWarning("builtin_setcastledata: guild castle for map '%s' not found\n", mapname);
+ return 1;
+ }
- if(script_hasdata(st,4) && index==0 && gc) {
- const char* event = script_getstr(st,4);
- check_event(st, event);
- guild_addcastleinfoevent(gc->castle_id, 9+MAX_GUARDIANS, event);
- }
-
- if(gc){
- switch(index){
- case 0: {
- int i;
- for (i = 1; i <= 9+MAX_GUARDIANS; i++) // Initialize[AgitInit]
- guild_castledataload(gc->castle_id,i);
- } break;
- case 1:
- script_pushint(st,gc->guild_id); break;
- case 2:
- script_pushint(st,gc->economy); break;
- case 3:
- script_pushint(st,gc->defense); break;
- case 4:
- script_pushint(st,gc->triggerE); break;
- case 5:
- script_pushint(st,gc->triggerD); break;
- case 6:
- script_pushint(st,gc->nextTime); break;
- case 7:
- script_pushint(st,gc->payTime); break;
- case 8:
- script_pushint(st,gc->createTime); break;
- case 9:
- script_pushint(st,gc->visibleC); break;
- default:
- if (index > 9 && index <= 9+MAX_GUARDIANS)
- script_pushint(st,gc->guardian[index-10].visible);
- else
- script_pushint(st,0);
+ switch (index) {
+ case 1:
+ script_pushint(st,gc->guild_id); break;
+ case 2:
+ script_pushint(st,gc->economy); break;
+ case 3:
+ script_pushint(st,gc->defense); break;
+ case 4:
+ script_pushint(st,gc->triggerE); break;
+ case 5:
+ script_pushint(st,gc->triggerD); break;
+ case 6:
+ script_pushint(st,gc->nextTime); break;
+ case 7:
+ script_pushint(st,gc->payTime); break;
+ case 8:
+ script_pushint(st,gc->createTime); break;
+ case 9:
+ script_pushint(st,gc->visibleC); break;
+ default:
+ if (index > 9 && index <= 9+MAX_GUARDIANS) {
+ script_pushint(st,gc->guardian[index-10].visible);
break;
- }
- return 0;
+ }
+ script_pushint(st,0);
+ ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
+ return 1;
}
- script_pushint(st,0);
return 0;
}
@@ -10193,39 +10185,41 @@ BUILDIN_FUNC(setcastledata)
const char* mapname = mapindex_getmapname(script_getstr(st,2),NULL);
int index = script_getnum(st,3);
int value = script_getnum(st,4);
-
struct guild_castle* gc = guild_mapname2gc(mapname);
- if(gc) {
- // Save Data byself First
- switch(index){
- case 1:
- gc->guild_id = value; break;
- case 2:
- gc->economy = value; break;
- case 3:
- gc->defense = value; break;
- case 4:
- gc->triggerE = value; break;
- case 5:
- gc->triggerD = value; break;
- case 6:
- gc->nextTime = value; break;
- case 7:
- gc->payTime = value; break;
- case 8:
- gc->createTime = value; break;
- case 9:
- gc->visibleC = value; break;
- default:
- if (index > 9 && index <= 9+MAX_GUARDIANS) {
- gc->guardian[index-10].visible = value;
- break;
- }
- return 0;
- }
- guild_castledatasave(gc->castle_id,index,value);
+ if (gc == NULL) {
+ ShowWarning("builtin_setcastledata: guild castle for map '%s' not found\n", mapname);
+ return 1;
+ }
+
+ switch (index) {
+ case 1:
+ gc->guild_id = value; break;
+ case 2:
+ gc->economy = value; break;
+ case 3:
+ gc->defense = value; break;
+ case 4:
+ gc->triggerE = value; break;
+ case 5:
+ gc->triggerD = value; break;
+ case 6:
+ gc->nextTime = value; break;
+ case 7:
+ gc->payTime = value; break;
+ case 8:
+ gc->createTime = value; break;
+ case 9:
+ gc->visibleC = value; break;
+ default:
+ if (index > 9 && index <= 9+MAX_GUARDIANS) {
+ gc->guardian[index-10].visible = value;
+ break;
+ }
+ ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
+ return 1;
}
+ guild_castledatasave(gc->castle_id, index, value);
return 0;
}
@@ -16065,7 +16059,7 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(agitcheck,""), // <Agitcheck>
BUILDIN_DEF(flagemblem,"i"), // Flag Emblem
BUILDIN_DEF(getcastlename,"s"),
- BUILDIN_DEF(getcastledata,"si?"),
+ BUILDIN_DEF(getcastledata,"si"),
BUILDIN_DEF(setcastledata,"sii"),
BUILDIN_DEF(requestguildinfo,"i?"),
BUILDIN_DEF(getequipcardcnt,"i"),