diff options
author | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-10-18 08:04:53 +0000 |
---|---|---|
committer | ultramage <ultramage@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2007-10-18 08:04:53 +0000 |
commit | e8d7a95f9416c67242db5e06fd1743c8f28b3b08 (patch) | |
tree | a31a379d1f2e3af7eede623407b4cc0a25b43383 /src/map | |
parent | 5f6a6a2557a90573a504b541a3234f0dc566bf6a (diff) | |
download | hercules-e8d7a95f9416c67242db5e06fd1743c8f28b3b08.tar.gz hercules-e8d7a95f9416c67242db5e06fd1743c8f28b3b08.tar.bz2 hercules-e8d7a95f9416c67242db5e06fd1743c8f28b3b08.tar.xz hercules-e8d7a95f9416c67242db5e06fd1743c8f28b3b08.zip |
Some code cleaning...
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11505 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/atcommand.c | 14 | ||||
-rw-r--r-- | src/map/charcommand.c | 6 | ||||
-rw-r--r-- | src/map/clif.c | 6 | ||||
-rw-r--r-- | src/map/map.c | 97 | ||||
-rw-r--r-- | src/map/map.h | 10 | ||||
-rw-r--r-- | src/map/mercenary.c | 2 | ||||
-rw-r--r-- | src/map/npc.c | 27 | ||||
-rw-r--r-- | src/map/pc.c | 14 | ||||
-rw-r--r-- | src/map/script.c | 2 | ||||
-rw-r--r-- | src/map/skill.c | 8 |
10 files changed, 70 insertions, 116 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c index d5a51e933..e6b1fd6e0 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -2143,7 +2143,7 @@ int atcommand_jobchange(const int fd, struct map_session_data* sd, const char* c { "soul linker", 4049 }, }; - for (i=0; i < (int)(sizeof(jobs) / sizeof(jobs[0])); i++) { + for (i=0; i < ARRAYLENGTH(jobs); i++) { if (strncmpi(message, jobs[i].name, 16) == 0) { job = jobs[i].id; upper = 0; @@ -3053,7 +3053,7 @@ int atcommand_go(const int fd, struct map_session_data* sd, const char* command, town = atoi(message); // if no value, display all value - if (!message || !*message || sscanf(message, "%15s", map_name) < 1 || town < -3 || town >= (int)(sizeof(data) / sizeof(data[0]))) { + if (!message || !*message || sscanf(message, "%15s", map_name) < 1 || town < -3 || town >= ARRAYLENGTH(data)) { clif_displaymessage(fd, msg_txt(38)); // Invalid location number or name. clif_displaymessage(fd, msg_txt(82)); // Please, use one of this number/name: clif_displaymessage(fd, " 0=Prontera 1=Morroc 2=Geffen"); @@ -3161,7 +3161,7 @@ int atcommand_go(const int fd, struct map_session_data* sd, const char* command, clif_displaymessage(fd, atcmd_output); return -1; } - } else if (town >= 0 && town < (int)(sizeof(data) / sizeof(data[0]))) { + } else if (town >= 0 && town < ARRAYLENGTH(data)) { m = map_mapname2mapid((char *)data[town].map); if (m >= 0 && map[m].flag.nowarpto && battle_config.any_warp_GM_min_level > pc_isGM(sd)) { clif_displaymessage(fd, msg_txt(247)); @@ -3917,7 +3917,7 @@ int atcommand_stat_all(const int fd, struct map_session_data* sd, const char* co } count = 0; - for (index = 0; index < (int)(sizeof(status) / sizeof(status[0])); index++) { + for (index = 0; index < ARRAYLENGTH(status); index++) { if (value > 0 && *status[index] > max - value) new_value = max; @@ -6302,10 +6302,8 @@ int atcommand_npcmove(const int fd, struct map_session_data* sd, const char* com return -1; //Not on a map. } - if (x < 0) x = 0; - else if (x >= map[m].xs) x = map[m].xs-1; - if (y < 0) y = 0; - else if (y >= map[m].ys) y = map[m].ys-1; + x = cap_value(x, 0, map[m].xs-1); + y = cap_value(y, 0, map[m].ys-1); map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl); map_moveblock(&nd->bl, x, y, gettick()); map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl); diff --git a/src/map/charcommand.c b/src/map/charcommand.c index 88c32b307..dc16f399b 100644 --- a/src/map/charcommand.c +++ b/src/map/charcommand.c @@ -2578,11 +2578,11 @@ int charcommand_param(const int fd, struct map_session_data* sd, const char* com status[5] = &pl_sd->status.luk; index = -1; - for (index = 0; index < sizeof(param)/sizeof(param[0]); index++) { + for (index = 0; index < ARRAYLENGTH(param); index++) { if (strcmpi(command, param[index]) == 0) break; } - if (index == sizeof(param)/sizeof(param[0]) || index > MAX_STATUS_TYPE) { + if (index == ARRAYLENGTH(param) || index > MAX_STATUS_TYPE) { // normaly impossible... sprintf(output, "Please, enter a valid value (usage: #str,#agi,#vit,#int,#dex,#luk <+/-adjustment> <player>)."); clif_displaymessage(fd, output); @@ -2964,7 +2964,7 @@ int charcommand_allstats(const int fd, struct map_session_data* sd, const char* count = 0; max = pc_maxparameter(pl_sd); - for (index = 0; index < (int)(sizeof(status) / sizeof(status[0])); index++) { + for (index = 0; index < ARRAYLENGTH(status); index++) { if (value > 0 && *status[index] > max - value) new_value = max; diff --git a/src/map/clif.c b/src/map/clif.c index 1e3bcca1f..de0031fb7 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -8152,7 +8152,7 @@ void check_fake_id(int fd, struct map_session_data *sd, int target_id) memset(WPACKETP(0), 0, packet_len(0x95)); WPACKETW(0) = 0x95; WPACKETL(2) = server_fake_mob_id; - fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % (sizeof(fake_mob_list) / sizeof(fake_mob_list[0]))]; // never same mob + fake_mob = fake_mob_list[(sd->bl.m + sd->fd + sd->status.char_id) % ARRAYLENGTH(fake_mob_list)]; // never same mob if (!mobdb_checkid(fake_mob)) fake_mob = 1002; // poring (default) strncpy(WPACKETP(6), mob_db[fake_mob].name, 24); @@ -11775,7 +11775,7 @@ static int packetdb_readdb(void) // initialize packet_db[SERVER] from hardcoded packet_len_table[] values memset(packet_db,0,sizeof(packet_db)); - for( i = 0; i < sizeof(packet_len_table)/sizeof(packet_len_table[0]); ++i ) + for( i = 0; i < ARRAYLENGTH(packet_len_table); ++i ) packet_len(i) = packet_len_table[i]; sprintf(line, "%s/packet_db.txt", db_path); @@ -11868,7 +11868,7 @@ static int packetdb_readdb(void) ln++; continue; } - for(j=0;j<sizeof(clif_parse_func)/sizeof(clif_parse_func[0]);j++){ + for(j=0;j<ARRAYLENGTH(clif_parse_func);j++){ if(clif_parse_func[j].name != NULL && strcmp(str[2],clif_parse_func[j].name)==0) { if (packet_db[packet_ver][cmd].func != clif_parse_func[j].func) diff --git a/src/map/map.c b/src/map/map.c index 0325ff839..3263a6ed8 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -319,8 +319,7 @@ static struct block_list bl_head; *------------------------------------------*/ void map_addblcell(struct block_list *bl) { - if(bl->m<0 || bl->x<0 || bl->x>=map[bl->m].xs - || bl->y<0 || bl->y>=map[bl->m].ys || !(bl->type&BL_CHAR)) + if( bl->m<0 || bl->x<0 || bl->x>=map[bl->m].xs || bl->y<0 || bl->y>=map[bl->m].ys || !(bl->type&BL_CHAR) ) return; map[bl->m].cell_bl[bl->x+bl->y*map[bl->m].xs]++; return; @@ -328,8 +327,7 @@ void map_addblcell(struct block_list *bl) void map_delblcell(struct block_list *bl) { - if(bl->m <0 || bl->x<0 || bl->x>=map[bl->m].xs - || bl->y<0 || bl->y>=map[bl->m].ys || !(bl->type&BL_CHAR)) + if( bl->m <0 || bl->x<0 || bl->x>=map[bl->m].xs || bl->y<0 || bl->y>=map[bl->m].ys || !(bl->type&BL_CHAR) ) return; map[bl->m].cell_bl[bl->x+bl->y*map[bl->m].xs]--; } @@ -549,6 +547,7 @@ int map_count_oncell(int m, int x, int y, int type) if (x < 0 || y < 0 || (x >= map[m].xs) || (y >= map[m].ys)) return 0; + bx = x/BLOCK_SIZE; by = y/BLOCK_SIZE; @@ -612,16 +611,12 @@ int map_foreachinrange(int (*func)(struct block_list*,va_list), struct block_lis int blockcount=bl_list_count,i,c; int x0,x1,y0,y1; va_start(ap,type); + m = center->m; - x0 = center->x-range; - x1 = center->x+range; - y0 = center->y-range; - y1 = center->y+range; - - if (x0 < 0) x0 = 0; - if (y0 < 0) y0 = 0; - if (x1 >= map[m].xs) x1 = map[m].xs-1; - if (y1 >= map[m].ys) y1 = map[m].ys-1; + x0 = max(center->x-range, 0); + y0 = max(center->y-range, 0); + x1 = min(center->x+range, map[m].xs-1); + y1 = min(center->y+range, map[m].ys-1); if (type&~BL_MOB) for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { @@ -689,16 +684,12 @@ int map_foreachinshootrange(int (*func)(struct block_list*,va_list),struct block if (m < 0) return 0; va_start(ap,type); - x0 = center->x-range; - x1 = center->x+range; - y0 = center->y-range; - y1 = center->y+range; - - if (x0 < 0) x0 = 0; - if (y0 < 0) y0 = 0; - if (x1 >= map[m].xs) x1 = map[m].xs-1; - if (y1 >= map[m].ys) y1 = map[m].ys-1; - + + x0 = max(center->x-range, 0); + y0 = max(center->y-range, 0); + x1 = min(center->x+range, map[m].xs-1); + y1 = min(center->y+range, map[m].ys-1); + if (type&~BL_MOB) for (by = y0 / BLOCK_SIZE; by <= y1 / BLOCK_SIZE; by++) { for(bx=x0/BLOCK_SIZE;bx<=x1/BLOCK_SIZE;bx++){ @@ -846,6 +837,7 @@ int map_foreachinmovearea(int (*func)(struct block_list*,va_list), struct block_ if (!dx && !dy) return 0; //No movement. va_start(ap,type); m = center->m; + x0 = center->x-range; x1 = center->x+range; y0 = center->y-range; @@ -2326,45 +2318,19 @@ void map_setcell(int m,int x,int y,int cell) j=x+y*map[m].xs; switch (cell) { - case CELL_SETNPC: - map[m].cell[j] |= CELL_NPC; - break; - case CELL_CLRNPC: - map[m].cell[j] &= ~CELL_NPC; - break; - case CELL_SETICEWALL: - map[m].cell[j] |= CELL_ICEWALL; - break; - case CELL_CLRICEWALL: - map[m].cell[j] &= ~CELL_ICEWALL; - break; - case CELL_SETBASILICA: - map[m].cell[j] |= CELL_BASILICA; - break; - case CELL_CLRBASILICA: - map[m].cell[j] &= ~CELL_BASILICA; - break; - case CELL_SETPNEUMA: - map[m].cell[j] |= CELL_PNEUMA; - break; - case CELL_CLRPNEUMA: - map[m].cell[j] &= ~CELL_PNEUMA; - break; - case CELL_SETSAFETYWALL: - map[m].cell[j] |= CELL_SAFETYWALL; - break; - case CELL_CLRSAFETYWALL: - map[m].cell[j] &= ~CELL_SAFETYWALL; - break; - case CELL_SETLANDPROTECTOR: - map[m].cell[j] |= CELL_LANDPROTECTOR; - break; - case CELL_CLRLANDPROTECTOR: - map[m].cell[j] &= ~CELL_LANDPROTECTOR; - break; - case CELL_SETREGEN: - map[m].cell[j] |= CELL_REGEN; - break; + case CELL_SETNPC: map[m].cell[j] |= CELL_NPC; break; + case CELL_CLRNPC: map[m].cell[j] &= ~CELL_NPC; break; + case CELL_SETICEWALL: map[m].cell[j] |= CELL_ICEWALL; break; + case CELL_CLRICEWALL: map[m].cell[j] &= ~CELL_ICEWALL; break; + case CELL_SETBASILICA: map[m].cell[j] |= CELL_BASILICA; break; + case CELL_CLRBASILICA: map[m].cell[j] &= ~CELL_BASILICA; break; + case CELL_SETPNEUMA: map[m].cell[j] |= CELL_PNEUMA; break; + case CELL_CLRPNEUMA: map[m].cell[j] &= ~CELL_PNEUMA; break; + case CELL_SETSAFETYWALL: map[m].cell[j] |= CELL_SAFETYWALL; break; + case CELL_CLRSAFETYWALL: map[m].cell[j] &= ~CELL_SAFETYWALL; break; + case CELL_SETLANDPROTECTOR: map[m].cell[j] |= CELL_LANDPROTECTOR; break; + case CELL_CLRLANDPROTECTOR: map[m].cell[j] &= ~CELL_LANDPROTECTOR; break; + case CELL_SETREGEN: map[m].cell[j] |= CELL_REGEN; break; default: map[m].gat[j] = cell; break; @@ -2494,7 +2460,7 @@ int map_addmap(char* mapname) static void map_delmapid(int id) { - ShowNotice("Removing map [ %s ] from maplist\n",map[id].name); + ShowNotice("Removing map [ %s ] from maplist\n"CL_CLL,map[id].name); memmove(map+id, map+id+1, sizeof(map[0])*(map_num-id-1)); map_num--; } @@ -2569,7 +2535,7 @@ int map_readgat (struct map_data* m) xs = m->xs = *(int*)(gat+6); ys = m->ys = *(int*)(gat+10); - m->gat = (unsigned char *)aMallocA((m->xs * m->ys)*sizeof(unsigned char)); + m->gat = (unsigned char *)aMallocA((xs * ys)*sizeof(unsigned char)); wh = map_waterheight(m->name); for (y = 0; y < ys; y++) { @@ -2633,7 +2599,7 @@ int map_readallmaps (void) if (uidb_get(map_db,(unsigned int)map[i].index) != NULL) { - ShowWarning("Map %s already loaded!\n", map[i].name); + ShowWarning("Map %s already loaded!\n"CL_CLL, map[i].name); if (map[i].gat) { aFree(map[i].gat); map[i].gat = NULL; @@ -2677,7 +2643,6 @@ int map_readallmaps (void) fclose(fp); // finished map loading - printf("\r"); ShowInfo("Successfully loaded '"CL_WHITE"%d"CL_RESET"' maps."CL_CLL"\n",map_num); if (maps_removed) diff --git a/src/map/map.h b/src/map/map.h index c3a90cb81..4a0223610 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -1032,9 +1032,9 @@ enum { struct map_data { char name[MAP_NAME_LENGTH]; - unsigned short index; //Index is the map index used by the mapindex* functions. - unsigned char *gat; // If this is NULL, the map is not on this map-server - unsigned char *cell; //Contains temporary cell data that is set/unset on tiles. + unsigned short index; // The map index used by the mapindex* functions. + unsigned char *gat; // Holds the type of each map cell (NULL if the map is not on this map-server). + unsigned char *cell; // Contains temporary cell data that is set/unset on tiles. #ifdef CELL_NOSTACK unsigned char *cell_bl; //Holds amount of bls in any given cell. #endif @@ -1042,8 +1042,8 @@ struct map_data { struct block_list **block_mob; int *block_count,*block_mob_count; int m; - short xs,ys; - short bxs,bys; + short xs,ys; // map dimensions (in cells) + short bxs,bys; // map dimensions (in blocks) int npc_num; int users; struct map_flag { diff --git a/src/map/mercenary.c b/src/map/mercenary.c index ff13eacb1..ad30afa2c 100644 --- a/src/map/mercenary.c +++ b/src/map/mercenary.c @@ -1163,7 +1163,7 @@ int do_init_merc(void) //Stock view data for homuncs memset(&hom_viewdb, 0, sizeof(hom_viewdb)); - for (class_ = 0; class_ < sizeof(hom_viewdb)/sizeof(hom_viewdb[0]); class_++) + for (class_ = 0; class_ < ARRAYLENGTH(hom_viewdb); class_++) hom_viewdb[class_].class_ = HM_CLASS_BASE+class_; return 0; } diff --git a/src/map/npc.c b/src/map/npc.c index 29eff176b..7e442e615 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -828,16 +828,12 @@ int npc_check_areanpc(int flag, int m, int x, int y, int range) int xs,ys; if (range < 0) return 0; - x0 = x-range; - x1 = x+range; - y0 = y-range; - y1 = y+range; + x0 = max(x-range, 0); + y0 = max(y-range, 0); + x1 = min(x+range, map[m].xs-1); + y1 = min(y+range, map[m].ys-1); //First check for npc_cells on the range given - if (x0 < 0) x0 = 0; - if (y0 < 0) y0 = 0; - if (x1 >= map[m].xs) x1 = map[m].xs-1; - if (y1 >= map[m].ys) y1 = map[m].ys-1; i = 0; for (ys = y0; ys <= y1 && !i; ys++) { for(xs = x0; xs <= x1 && !i; xs++){ @@ -848,11 +844,13 @@ int npc_check_areanpc(int flag, int m, int x, int y, int range) if (!i) return 0; //No NPC_CELLs. //Now check for the actual NPC on said range. - for(i=0;i<map[m].npc_num;i++) { + for(i=0;i<map[m].npc_num;i++) + { if (map[m].npc[i]->sc.option&OPTION_INVISIBLE) continue; - switch(map[m].npc[i]->bl.subtype) { + switch(map[m].npc[i]->bl.subtype) + { case WARP: if (!(flag&1)) continue; @@ -868,9 +866,10 @@ int npc_check_areanpc(int flag, int m, int x, int y, int range) default: continue; } + if (x1 >= map[m].npc[i]->bl.x-xs/2 && x0 < map[m].npc[i]->bl.x-xs/2+xs && y1 >= map[m].npc[i]->bl.y-ys/2 && y0 < map[m].npc[i]->bl.y-ys/2+ys) - break; + break; // found a npc } if (i==map[m].npc_num) return 0; @@ -1959,10 +1958,8 @@ void npc_movenpc(struct npc_data* nd, int x, int y) const int m = nd->bl.m; if (m < 0 || nd->bl.prev == NULL) return; //Not on a map. - if (x < 0) x = 0; - else if (x >= map[m].xs) x = map[m].xs-1; - if (y < 0) y = 0; - else if (y >= map[m].ys) y = map[m].ys-1; + x = cap_value(x, 0, map[m].xs-1); + x = cap_value(y, 0, map[m].ys-1); npc_unsetcells(nd); map_foreachinrange(clif_outsight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl); diff --git a/src/map/pc.c b/src/map/pc.c index 99cde53d5..d259bc6e0 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -2761,16 +2761,10 @@ int pc_getzeny(struct map_session_data *sd,int zeny) int pc_search_inventory(struct map_session_data *sd,int item_id) { int i; - nullpo_retr(-1, sd); - for(i=0;i<MAX_INVENTORY;i++) { - if(sd->status.inventory[i].nameid == item_id && - (sd->status.inventory[i].amount > 0 || item_id == 0)) - return i; - } - - return -1; + ARR_FIND( 0, MAX_INVENTORY, i, sd->status.inventory[i].nameid == item_id && (sd->status.inventory[i].amount > 0 || item_id == 0) ); + return ( i < MAX_INVENTORY ) ? i : -1; } /*========================================== @@ -3660,7 +3654,7 @@ int pc_checkallowskill(struct map_session_data *sd) if(!sd->sc.count) return 0; - for (i = 0; i < sizeof(scw_list)/sizeof(scw_list[0]); i++) + for (i = 0; i < ARRAYLENGTH(scw_list); i++) { // Skills requiring specific weapon types if(sd->sc.data[scw_list[i]].timer!=-1 && !pc_check_weapontype(sd,skill_get_weapontype(StatusSkillChangeTable[scw_list[i]]))) @@ -3672,7 +3666,7 @@ int pc_checkallowskill(struct map_session_data *sd) status_change_end(&sd->bl,SC_SPURT,-1); if(sd->status.shield <= 0) { // Skills requiring a shield - for (i = 0; i < sizeof(scs_list)/sizeof(scs_list[0]); i++) + for (i = 0; i < ARRAYLENGTH(scs_list); i++) if(sd->sc.data[scs_list[i]].timer!=-1) status_change_end(&sd->bl,scs_list[i],-1); } diff --git a/src/map/script.c b/src/map/script.c index 116973f17..0d2d04650 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -1936,7 +1936,7 @@ struct script_code* parse_script(const char *src,const char *file,int line,int o if( setjmp( error_jump ) != 0 ) { //Restore program state when script has problems. [from jA] int i; - const int size = sizeof(syntax.curly)/sizeof(syntax.curly[0]); + const int size = ARRAYLENGTH(syntax.curly); if( error_report ) script_error(src,file,line,error_msg,error_pos); aFree( error_msg ); diff --git a/src/map/skill.c b/src/map/skill.c index 4651f035a..f3cc9a2c5 100644 --- a/src/map/skill.c +++ b/src/map/skill.c @@ -1789,13 +1789,13 @@ int skill_strip_equip(struct block_list *bl, unsigned short where, int rate, int if (!sc) return 0; - for (i = 0; i < sizeof(pos)/sizeof(pos[0]); i++) { + for (i = 0; i < ARRAYLENGTH(pos); i++) { if (where&pos[i] && sc->data[sc_def[i]].timer != -1) where&=~pos[i]; } if (!where) return 0; - for (i = 0; i < sizeof(pos)/sizeof(pos[0]); i++) { + for (i = 0; i < ARRAYLENGTH(pos); i++) { if (where&pos[i] && !sc_start(bl, sc_atk[i], 100, lv, time)) where&=~pos[i]; } @@ -3709,7 +3709,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in { static int changeclass[]={1038,1039,1046,1059,1086,1087,1112,1115 ,1157,1159,1190,1272,1312,1373,1492}; - int class_ = mob_random_class (changeclass,sizeof(changeclass)/sizeof(changeclass[0])); + int class_ = mob_random_class (changeclass,ARRAYLENGTH(changeclass)); clif_skill_nodamage(src,bl,skillid,skilllv,1); if(dstmd) mob_class_change(dstmd,class_); } @@ -3717,7 +3717,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in case SA_MONOCELL: { static int poringclass[]={1002}; - int class_ = mob_random_class (poringclass,sizeof(poringclass)/sizeof(poringclass[0])); + int class_ = mob_random_class (poringclass,ARRAYLENGTH(poringclass)); clif_skill_nodamage(src,bl,skillid,skilllv,1); if(dstmd) mob_class_change(dstmd,class_); } |