summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-16 21:00:36 +0000
committerultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-16 21:00:36 +0000
commit1290cc541348ed0593b4924a44ad552007a8756d (patch)
tree75eaf4a28dc6d833c8b830af7c3fa8882d063339
parenta2bd3711edd890864a0fef46f3fcda4f2492b740 (diff)
downloadhercules-1290cc541348ed0593b4924a44ad552007a8756d.tar.gz
hercules-1290cc541348ed0593b4924a44ad552007a8756d.tar.bz2
hercules-1290cc541348ed0593b4924a44ad552007a8756d.tar.xz
hercules-1290cc541348ed0593b4924a44ad552007a8756d.zip
Replaced the 'map name' castle data variable with the equivalent 'map index'.
Optimized the castle lookup functions (direct dbmap enumeration, and no redundant operations inside the searching loop). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11918 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--src/common/mmo.h2
-rw-r--r--src/map/guild.c35
2 files changed, 14 insertions, 23 deletions
diff --git a/src/common/mmo.h b/src/common/mmo.h
index f87964bf4..1d063eaa8 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -377,7 +377,7 @@ struct guild {
struct guild_castle {
int castle_id;
- char map_name[MAP_NAME_LENGTH];
+ int mapindex;
char castle_name[NAME_LENGTH];
char castle_event[NAME_LENGTH];
int guild_id;
diff --git a/src/map/guild.c b/src/map/guild.c
index 78db261b5..ac5f67fa8 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -186,7 +186,7 @@ static int guild_read_castledb(void)
gc=(struct guild_castle *)aCalloc(1,sizeof(struct guild_castle));
gc->castle_id=atoi(str[0]);
- mapindex_getmapname(str[1],gc->map_name);
+ gc->mapindex = mapindex_name2id(str[1]);
safestrncpy(gc->castle_name,str[2],NAME_LENGTH);
safestrncpy(gc->castle_event,str[3],NAME_LENGTH);
@@ -232,29 +232,23 @@ struct guild_castle* guild_castle_search(int gcid)
/// lookup: map index -> castle*
struct guild_castle* guild_mapindex2gc(short mapindex)
{
- int i;
- struct guild_castle *gc=NULL;
-
- for(i=0;i<MAX_GUILDCASTLE;i++){
- gc=guild_castle_search(i);
- if(!gc) continue;
- if(strcmp(gc->map_name,mapindex_id2name(mapindex))==0) return gc;
+ struct guild_castle* gc;
+
+ DBIterator* iter = castle_db->iterator(castle_db);
+ for( gc = iter->first(iter,NULL); iter->exists(iter); gc = iter->next(iter,NULL) )
+ {
+ if( gc->mapindex == mapindex )
+ break;
}
- return NULL;
+ iter->destroy(iter);
+
+ return gc;
}
/// lookup: map name -> castle*
struct guild_castle* guild_mapname2gc(const char* mapname)
{
- int i;
- for(i = 0; i < MAX_GUILDCASTLE; i++)
- {
- struct guild_castle* gc;
- gc = guild_castle_search(i);
- if(!gc) continue;
- if(strcmp(gc->map_name,mapname)==0) return gc;
- }
- return NULL;
+ return guild_mapindex2gc(mapindex_name2id(mapname));
}
struct map_session_data* guild_getavailablesd(struct guild* g)
@@ -283,9 +277,6 @@ int guild_getindex(struct guild *g,int account_id,int char_id)
int guild_getposition(struct guild* g, struct map_session_data* sd)
{
int i;
-
- nullpo_retr(-1, sd);
-
if( g == NULL && (g=guild_search(sd->status.guild_id)) == NULL )
return -1;
@@ -1710,7 +1701,7 @@ int guild_castledatasave(int castle_id,int index,int value)
{ //The castle's owner has changed? Update Guardian ownership, too. [Skotlex]
struct guild_castle *gc = guild_castle_search(castle_id);
int m = -1;
- if (gc) m = map_mapname2mapid(gc->map_name);
+ if (gc) m = map_mapindex2mapid(gc->mapindex);
if (m != -1)
map_foreachinmap(mob_guardian_guildchange, m, BL_MOB); //FIXME: why not iterate over gc->guardian[i].id ?
}