summaryrefslogtreecommitdiff
path: root/src/map/guild.c
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-12 09:55:13 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-12 09:55:13 +0000
commited87621c65d7c13ddd4993101a5b7c2287b6609e (patch)
treea035e4d010d2b9a690c82114dff33dfa36d9f889 /src/map/guild.c
parent1c5fab35e935b870939bcae24ea95e957ed76d5a (diff)
downloadhercules-ed87621c65d7c13ddd4993101a5b7c2287b6609e.tar.gz
hercules-ed87621c65d7c13ddd4993101a5b7c2287b6609e.tar.bz2
hercules-ed87621c65d7c13ddd4993101a5b7c2287b6609e.tar.xz
hercules-ed87621c65d7c13ddd4993101a5b7c2287b6609e.zip
* Some preparations for the guild script update
- cleaned up npc event execution code - cleaned up guild data loading/saving code; to be improved later - removed dummy 'account name' expulsion list management code - removed columns 'rsv1' and 'rsv2' from guild member data - removed columns 'rsv1' 'rsv2' 'rsv3' and 'acc' from guild expulsion data - added upgrade_svn11895.sql for SQL git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11895 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map/guild.c')
-rw-r--r--src/map/guild.c133
1 files changed, 40 insertions, 93 deletions
diff --git a/src/map/guild.c b/src/map/guild.c
index 889338a9c..ca571b3ce 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -655,9 +655,7 @@ int guild_invite(struct map_session_data *sd,struct map_session_data *tsd)
}
// ’θˆυŠm”F
- for(i=0;i<g->max_member;i++)
- if(g->member[i].account_id==0)
- break;
+ ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 );
if(i==g->max_member){
clif_guild_inviteack(sd,3);
return 0;
@@ -669,60 +667,52 @@ int guild_invite(struct map_session_data *sd,struct map_session_data *tsd)
clif_guild_invite(tsd,g);
return 0;
}
-// ƒMƒ‹ƒhŠ©—U‚Φ‚Μ•Τ“š
-int guild_reply_invite(struct map_session_data *sd,int guild_id,int flag)
+
+/// Guild invitation reply.
+/// flag: 0:rejected, 1:accepted
+int guild_reply_invite(struct map_session_data* sd, int guild_id, int flag)
{
- struct map_session_data *tsd;
+ struct map_session_data* tsd;
nullpo_retr(0, sd);
-
- //nullpo_retr(0, tsd= map_id2sd( sd->guild_invite_account ));
- //I checked the code, and there's no "check" for the case where the guy
- //that invites another to a guild quits the map-server before being replied.
- //Hence that's a valid null pointer scenario. :) [Skotlex]
- if ((tsd= map_id2sd( sd->guild_invite_account )) == NULL)
- { //Do we send a "invitation failed" msg or something to the player?
- //Or should we accept the invitation and add it to the guild anyway?
- //afterall, guild_invite holds the guild id that the player was invited to.
- sd->guild_invite=0;
- sd->guild_invite_account=0;
- return 0;
- }
- if(sd->guild_invite!=guild_id) // Š©—U‚ΖƒMƒ‹ƒhID‚ͺˆα‚€
- return 0;
+ // subsequent requests may override the value
+ if( sd->guild_invite != guild_id )
+ return 0; // mismatch
- if(flag==1){ // ³‘ψ
+ // look up the person who sent the invite
+ //NOTE: this can be NULL because the person might have logged off in the meantime
+ tsd = map_id2sd(sd->guild_invite_account);
+
+ // zero out the status data
+ sd->guild_invite = 0;
+ sd->guild_invite_account = 0;
+
+ if( flag == 0 )
+ {// rejected
+ if( tsd ) clif_guild_inviteack(tsd,1);
+ }
+ else
+ {// accepted
struct guild_member m;
- struct guild *g;
+ struct guild* g;
int i;
- // ’θˆυŠm”F
- if( (g=guild_search(tsd->status.guild_id))==NULL ){
- sd->guild_invite=0;
- sd->guild_invite_account=0;
+ if( (g=guild_search(guild_id)) == NULL )
return 0;
- }
- for(i=0;i<g->max_member;i++)
- if(g->member[i].account_id==0)
- break;
- if(i==g->max_member){
- sd->guild_invite=0;
- sd->guild_invite_account=0;
- clif_guild_inviteack(tsd,3);
+
+ ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 );
+ if( i == g->max_member )
+ {
+ if( tsd ) clif_guild_inviteack(tsd,3);
return 0;
}
- //interŽI‚Φ’Η‰Α—v‹
guild_makemember(&m,sd);
- intif_guild_addmember( sd->guild_invite, &m );
+ intif_guild_addmember(guild_id, &m);
//TODO: send a minimap update to this player
- return 0;
- }else{ // ‹‘”Ϋ
- sd->guild_invite=0;
- sd->guild_invite_account=0;
- clif_guild_inviteack(tsd,1);
}
+
return 0;
}
// ƒMƒ‹ƒhƒƒ“ƒo‚ͺ’Η‰Α‚³‚κ‚½
@@ -1821,7 +1811,9 @@ int guild_castlealldataload(int len,struct guild_castle *gc)
for( i = n-1; i >= 0 && !(gc[i].guild_id); --i );
ev = i; // offset of castle or -1
- // load received castles into memory, one by one
+ if( ev < 0 ) //No castles owned, invoke OnAgitInit as it is.
+ npc_event_doall("OnAgitInit");
+ else // load received castles into memory, one by one
for( i = 0; i < n; i++, gc++ )
{
struct guild_castle *c = guild_castle_search(gc->castle_id);
@@ -1842,9 +1834,6 @@ int guild_castlealldataload(int len,struct guild_castle *gc)
}
}
- if( ev < 0 ) //No castles owned, invoke OnAgitInit as it is.
- npc_event_doall("OnAgitInit");
-
return 0;
}
@@ -1906,57 +1895,15 @@ int guild_checkcastles(struct guild *g)
return nb_cas;
}
-// [MouseJstr]
-// is this guild allied with this castle?
-int guild_isallied(struct guild *g, struct guild_castle *gc)
-{
- int i;
-
- nullpo_retr(0, g);
-
- if(g->guild_id == gc->guild_id)
- return 1;
-
- if (gc->guild_id == 0)
- return 0;
-
-
- for(i=0;i<MAX_GUILDALLIANCE;i++)
- if(g->alliance[i].guild_id == gc->guild_id) {
- if(g->alliance[i].opposition == 0)
- return 1;
- else
- return 0;
- }
-
- return 0;
-}
-
-int guild_idisallied(int guild_id, int guild_id2)
+// Are these two guilds allied?
+bool guild_isallied(int guild_id, int guild_id2)
{
int i;
- struct guild *g;
-
- if (guild_id <= 0 || guild_id2 <= 0)
- return 0;
-
- if(guild_id == guild_id2)
- return 1;
-
- g = guild_search(guild_id);
-
+ struct guild* g = guild_search(guild_id);
nullpo_retr(0, g);
-
- for(i=0;i<MAX_GUILDALLIANCE;i++)
- if(g->alliance[i].guild_id == guild_id2) {
- if(g->alliance[i].opposition == 0)
- return 1;
- else
- return 0;
- }
-
- return 0;
+ ARR_FIND( 0, MAX_GUILDALLIANCE, i, g->alliance[i].guild_id == guild_id2 );
+ return( i < MAX_GUILDALLIANCE && g->alliance[i].opposition == 0 );
}
static int guild_infoevent_db_final(DBKey key,void *data,va_list ap)