summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2016-02-19 14:53:45 +0100
committerHaru <haru@dotalux.com>2016-03-20 18:32:06 +0100
commit3ce598dc1ef86c5fe319536a999246a49c3406bc (patch)
tree3e14246e64adff903d18ffdccd4030071eed9c47 /src/map
parent504770250595fdb8f3f56400ea101a4d0d45faff (diff)
downloadhercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.tar.gz
hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.tar.bz2
hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.tar.xz
hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.zip
Added const qualifier to some typecasts
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/map')
-rw-r--r--src/map/atcommand.c28
-rw-r--r--src/map/intif.c4
-rw-r--r--src/map/script.c85
-rw-r--r--src/map/storage.c4
-rw-r--r--src/map/vending.c6
5 files changed, 64 insertions, 63 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index e422a5de4..963f5c970 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -547,7 +547,7 @@ ACMD(jumpto) {
return false;
}
- if((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
+ if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
@@ -2747,7 +2747,7 @@ ACMD(recall) {
return false;
}
- if((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
+ if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
@@ -3072,7 +3072,7 @@ ACMD(kick)
return false;
}
- if((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
+ if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
@@ -5125,8 +5125,7 @@ ACMD(follow) {
return true;
}
- if ((pl_sd = map->nick2sd((const char *)message)) == NULL)
- {
+ if ((pl_sd = map->nick2sd(message)) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
@@ -5603,7 +5602,7 @@ ACMD(changegm) {
return false;
}
- if ((pl_sd=map->nick2sd((const char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
+ if ((pl_sd=map->nick2sd(message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) {
clif->message(fd, msg_fd(fd,1184)); // Target character must be online and be a guild member.
return false;
}
@@ -5623,7 +5622,7 @@ ACMD(changeleader) {
return false;
}
- if (party->changeleader(sd, map->nick2sd((const char *) message)))
+ if (party->changeleader(sd, map->nick2sd(message)))
return true;
return false;
}
@@ -6382,7 +6381,7 @@ ACMD(trade) {
return false;
}
- if ( (pl_sd = map->nick2sd((const char *)message)) == NULL ) {
+ if ((pl_sd = map->nick2sd(message)) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
@@ -6425,8 +6424,7 @@ ACMD(unmute) {
return false;
}
- if ((pl_sd = map->nick2sd((const char *)message)) == NULL)
- {
+ if ((pl_sd = map->nick2sd(message)) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
@@ -7667,9 +7665,10 @@ ACMD(showdelay)
* @reject - reject invitation
* @leave - leave duel
*------------------------------------------*/
-ACMD(invite) {
+ACMD(invite)
+{
unsigned int did = sd->duel_group;
- struct map_session_data *target_sd = map->nick2sd((const char *)message);
+ struct map_session_data *target_sd = map->nick2sd(message);
if (did == 0)
{
@@ -7741,8 +7740,7 @@ ACMD(duel) {
}
duel->create(sd, maxpl);
} else {
- struct map_session_data *target_sd;
- target_sd = map->nick2sd((const char *)message);
+ struct map_session_data *target_sd = map->nick2sd(message);
if (target_sd != NULL) {
unsigned int newduel;
if ((newduel = duel->create(sd, 2)) != -1) {
@@ -7884,7 +7882,7 @@ ACMD(clone) {
return false;
}
- if ((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
+ if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) {
clif->message(fd, msg_fd(fd,3)); // Character not found.
return false;
}
diff --git a/src/map/intif.c b/src/map/intif.c
index 7d2493d46..4b3e913e1 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -1110,7 +1110,7 @@ void intif_parse_Registers(int fd)
safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len));
cursor += len + 1;
- script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)sval, NULL);
+ script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, sval, NULL);
}
/**
* Vessel!
@@ -1132,7 +1132,7 @@ void intif_parse_Registers(int fd)
ival = RFIFOL(fd, cursor);
cursor += 4;
- script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)h64BPTRSIZE(ival), NULL);
+ script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (const void *)h64BPTRSIZE(ival), NULL);
}
}
script->parser_current_file = NULL;/* reset */
diff --git a/src/map/script.c b/src/map/script.c
index fd653523d..c054d3bc4 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -6386,16 +6386,13 @@ BUILDIN(input)
} else {
// take received text/value and store it in the designated variable
sd->state.menu_or_input = 0;
- if( is_string_variable(name) )
- {
+ if (is_string_variable(name)) {
int len = (int)strlen(sd->npc_str);
- script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2));
+ script->set_reg(st, sd, uid, name, sd->npc_str, script_getref(st,2));
script_pushint(st, (len > max ? 1 : len < min ? -1 : 0));
- }
- else
- {
+ } else {
int amount = sd->npc_amount;
- script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2));
+ script->set_reg(st, sd, uid, name, (const void *)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2));
script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0));
}
st->state = RUN;
@@ -6482,9 +6479,9 @@ BUILDIN(__setr)
}
if (is_string_variable(name))
- script->set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2));
+ script->set_reg(st, sd, num, name, script_getstr(st, 3), script_getref(st, 2));
else
- script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(script_getnum(st,3)),script_getref(st,2));
+ script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(script_getnum(st, 3)), script_getref(st, 2));
return true;
}
@@ -6531,15 +6528,14 @@ BUILDIN(setarray)
if( end > SCRIPT_MAX_ARRAYSIZE )
end = SCRIPT_MAX_ARRAYSIZE;
- if( is_string_variable(name) )
- {// string array
- for( i = 3; start < end; ++start, ++i )
- script->set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data));
- }
- else
- {// int array
- for( i = 3; start < end; ++start, ++i )
- script->set_reg(st, sd, reference_uid(id, start), name, (void*)h64BPTRSIZE(script_getnum(st,i)), reference_getref(data));
+ if (is_string_variable(name)) {
+ // string array
+ for (i = 3; start < end; ++start, ++i)
+ script->set_reg(st, sd, reference_uid(id, start), name, script_getstr(st, i), reference_getref(data));
+ } else {
+ // int array
+ for (i = 3; start < end; ++start, ++i)
+ script->set_reg(st, sd, reference_uid(id, start), name, (const void *)h64BPTRSIZE(script_getnum(st, i)), reference_getref(data));
}
return true;
}
@@ -6555,7 +6551,7 @@ BUILDIN(cleararray)
uint32 start;
uint32 end;
int32 id;
- void* v;
+ const void *v = NULL;
struct map_session_data *sd = NULL;
data = script_getdata(st, 2);
@@ -6578,10 +6574,10 @@ BUILDIN(cleararray)
return true;// no player attached
}
- if( is_string_variable(name) )
- v = (void*)script_getstr(st, 3);
+ if (is_string_variable(name))
+ v = script_getstr(st, 3);
else
- v = (void*)h64BPTRSIZE(script_getnum(st, 3));
+ v = (const void *)h64BPTRSIZE(script_getnum(st, 3));
end = start + script_getnum(st, 4);
if( end > SCRIPT_MAX_ARRAYSIZE )
@@ -6667,7 +6663,12 @@ BUILDIN(copyarray)
script_removetop(st, -1, 0);
} else {
// out of range - assume ""/0
- script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1));
+ const void *value;
+ if (is_string_variable(name1))
+ value = "";
+ else
+ value = (const void *)0;
+ script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, value, reference_getref(data1));
}
}
}
@@ -6696,8 +6697,9 @@ BUILDIN(getarraysize)
script_pushint(st, script->array_highest_key(st,st->rid ? script->rid2sd(st) : NULL,reference_getname(data),reference_getref(data)));
return true;
}
-int script_array_index_cmp(const void *a, const void *b) {
- return ( *(const unsigned int*)a - *(const unsigned int*)b );
+int script_array_index_cmp(const void *a, const void *b)
+{
+ return (*(const unsigned int *)a - *(const unsigned int *)b); // FIXME: Is the unsigned difference really intended here?
}
/// Deletes count or all the elements in an array, from the starting index.
@@ -11054,9 +11056,9 @@ BUILDIN(getstatus)
case 4: script_pushint(st, sd->sc.data[id]->val4); break;
case 5:
{
- const struct TimerData* td = (const struct TimerData*)timer->get(sd->sc.data[id]->timer);
+ const struct TimerData *td = timer->get(sd->sc.data[id]->timer);
- if( td ) {
+ if (td != NULL) {
// return the amount of time remaining
script_pushint(st, (int)(td->tick - timer->gettick())); // TODO: change this to int64 when we'll support 64 bit script values
}
@@ -14407,7 +14409,7 @@ BUILDIN(getmapxy)
sd=script->rid2sd(st);
else
sd=NULL;
- script->set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2));
+ script->set_reg(st, sd, num, name, mapname, script_getref(st, 2));
//Set MapX
num=st->stack->stack_data[st->start+3].u.num;
@@ -14418,7 +14420,7 @@ BUILDIN(getmapxy)
sd=script->rid2sd(st);
else
sd=NULL;
- script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(x),script_getref(st,3));
+ script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(x), script_getref(st, 3));
//Set MapY
num=st->stack->stack_data[st->start+4].u.num;
@@ -14429,7 +14431,7 @@ BUILDIN(getmapxy)
sd=script->rid2sd(st);
else
sd=NULL;
- script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(y),script_getref(st,4));
+ script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(y), script_getref(st, 4));
//Return Success value
script_pushint(st,0);
@@ -15089,7 +15091,7 @@ BUILDIN(explode)
if (str[i] == delimiter && (int64)start + k < (int64)(SCRIPT_MAX_ARRAYSIZE-1)) { // FIXME[Haru]: SCRIPT_MAX_ARRAYSIZE should really be unsigned (and INT32_MAX)
//break at delimiter but ignore after reaching last array index
temp[j] = '\0';
- script->set_reg(st, sd, reference_uid(id, start + k), name, (void*)temp, reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start + k), name, temp, reference_getref(data));
k++;
j = 0;
} else {
@@ -15098,7 +15100,7 @@ BUILDIN(explode)
}
//set last string
temp[j] = '\0';
- script->set_reg(st, sd, reference_uid(id, start + k), name, (void*)temp, reference_getref(data));
+ script->set_reg(st, sd, reference_uid(id, start + k), name, temp, reference_getref(data));
aFree(temp);
@@ -15418,12 +15420,12 @@ BUILDIN(sscanf) {
if(sscanf(str, buf, ref_str)==0) {
break;
}
- script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data));
+ script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, ref_str, reference_getref(data));
} else { // Number
if(sscanf(str, buf, &ref_int)==0) {
break;
}
- script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)h64BPTRSIZE(ref_int), reference_getref(data));
+ script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (const void *)h64BPTRSIZE(ref_int), reference_getref(data));
}
arg++;
@@ -15863,8 +15865,8 @@ BUILDIN(swap)
value2 = script_getstr(st,3);
if (strcmpi(value1, value2)) {
- script->set_reg(st, sd, uid1, varname1, (void*)(value2), script_getref(st,3));
- script->set_reg(st, sd, uid2, varname2, (void*)(value1), script_getref(st,2));
+ script->set_reg(st, sd, uid1, varname1, value2, script_getref(st,3));
+ script->set_reg(st, sd, uid2, varname2, value1, script_getref(st,2));
}
}
else {
@@ -15874,8 +15876,8 @@ BUILDIN(swap)
value2 = script_getnum(st,3);
if (value1 != value2) {
- script->set_reg(st, sd, uid1, varname1, (void*)h64BPTRSIZE(value2), script_getref(st,3));
- script->set_reg(st, sd, uid2, varname2, (void*)h64BPTRSIZE(value1), script_getref(st,2));
+ script->set_reg(st, sd, uid1, varname1, (const void *)h64BPTRSIZE(value2), script_getref(st,3));
+ script->set_reg(st, sd, uid2, varname2, (const void *)h64BPTRSIZE(value1), script_getref(st,2));
}
}
return true;
@@ -16529,7 +16531,7 @@ BUILDIN(searchitem)
for( i = 0; i < count; ++start, ++i )
{// Set array
- void* v = (void*)h64BPTRSIZE((int)items[i]->nameid);
+ const void *v = (const void *)h64BPTRSIZE((int)items[i]->nameid);
script->set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data));
}
@@ -19743,9 +19745,10 @@ BUILDIN(checkbound)
/* bg_match_over( arena_name {, optional canceled } ) */
/* returns 0 when successful, 1 otherwise */
-BUILDIN(bg_match_over) {
+BUILDIN(bg_match_over)
+{
bool canceled = script_hasdata(st,3) ? true : false;
- struct bg_arena *arena = bg->name2arena((const char*)script_getstr(st, 2));
+ struct bg_arena *arena = bg->name2arena(script_getstr(st, 2));
if( arena ) {
bg->match_over(arena,canceled);
diff --git a/src/map/storage.c b/src/map/storage.c
index ceac85916..b8ec1e31e 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -52,8 +52,8 @@ struct guild_storage_interface *gstorage;
*------------------------------------------*/
int storage_comp_item(const void *i1_, const void *i2_)
{
- const struct item *i1 = (const struct item *)i1_;
- const struct item *i2 = (const struct item *)i2_;
+ const struct item *i1 = i1_;
+ const struct item *i2 = i2_;
if (i1->nameid == i2->nameid)
return 0;
diff --git a/src/map/vending.c b/src/map/vending.c
index 2346932ba..d9001f6f5 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -118,7 +118,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid,
// some checks
z = 0; // zeny counter
w = 0; // weight counter
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
short amount = *(const uint16*)(data + 4*i + 0);
short idx = *(const uint16*)(data + 4*i + 2);
idx -= 2;
@@ -184,7 +184,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid,
z -= apply_percentrate64(z, battle_config.vending_tax, 10000);
pc->getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd);
- for( i = 0; i < count; i++ ) {
+ for (i = 0; i < count; i++) {
short amount = *(const uint16*)(data + 4*i + 0);
short idx = *(const uint16*)(data + 4*i + 2);
idx -= 2;
@@ -265,7 +265,7 @@ void vending_openvending(struct map_session_data* sd, const char* message, const
// filter out invalid items
i = 0;
- for( j = 0; j < count; j++ ) {
+ for (j = 0; j < count; j++) {
short index = *(const uint16*)(data + 8*j + 0);
short amount = *(const uint16*)(data + 8*j + 2);
unsigned int value = *(const uint32*)(data + 8*j + 4);