* Script engine:

- calling functions without using the return value doesn't generate warnings
  - more work on Ticket #41
* Took care of two warnings and a minor change to the makefile.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@10025 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
FlavioJS 2007-03-18 16:07:16 +00:00
parent 66c7c0d040
commit 14e2d760f9
4 changed files with 187 additions and 121 deletions

View File

@ -3,6 +3,11 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK. AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/03/19
* Script engine:
- calling functions without using the return value doesn't generate warnings
- more work on Ticket #41
* Took care of two warnings and a minor change to the makefile. [FlavioJS]
2007/03/18 2007/03/18
* Added missing VC++ 7.1 project files for mapcache. [Lance] * Added missing VC++ 7.1 project files for mapcache. [Lance]
* A followup to the login_sql server changes: * A followup to the login_sql server changes:

View File

@ -133,9 +133,8 @@ endif
conf: conf:
cp -r conf-tmpl conf cp -r conf-tmpl conf
rm -rf conf/.svn conf/*/.svn
cp -r save-tmpl save cp -r save-tmpl save
rm -rf save/.svn rm -rf conf/.svn conf/*/.svn save/.svn
common: src/common/GNUmakefile common: src/common/GNUmakefile
$(MAKE) -C src/$@ $(MKDEF) $(MAKE) -C src/$@ $(MKDEF)

View File

@ -1515,7 +1515,7 @@ int parse_login(int fd)
} }
} }
} else { } else {
char* error; const char* error = "";
WFIFOHEAD(fd,23); WFIFOHEAD(fd,23);
if (login_config.log_login) if (login_config.log_login)
{ {
@ -1547,7 +1547,7 @@ int parse_login(int fd)
default : error = "Unknown Error."; break; default : error = "Unknown Error."; break;
} }
sprintf(tmpsql, "INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%u', '%s', '%d','login failed : %s')", loginlog_db, ntohl(ipl), t_uid, result, error); sprintf(tmpsql, "INSERT DELAYED INTO `%s`(`time`,`ip`,`user`,`rcode`,`log`) VALUES (NOW(), '%lu', '%s', '%d','login failed : %s')", loginlog_db, ntohl(ipl), t_uid, result, error);
//query //query
if(mysql_query(&mysql_handle, tmpsql)) { if(mysql_query(&mysql_handle, tmpsql)) {

View File

@ -2850,19 +2850,15 @@ void run_script_main(struct script_state *st)
c= get_com(st->script->script_buf,&st->pos); c= get_com(st->script->script_buf,&st->pos);
switch(c){ switch(c){
case C_EOL: case C_EOL:
if(stack->sp!=stack->defsp){ if( stack->sp != stack->defsp )
if(stack->sp > stack->defsp) {
if( stack->sp > stack->defsp )
{ //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex] { //sp > defsp is valid in cases when you invoke functions and don't use the returned value. [Skotlex]
//Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded. //Since sp is supposed to be defsp in these cases, we could assume the extra stack elements are unneeded.
if (battle_config.etc_log)
{
ShowWarning("Clearing unused stack stack.sp(%d) -> default(%d)\n",stack->sp,stack->defsp);
report_src(st);
}
pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section. pop_stack(stack, stack->defsp, stack->sp); //Clear out the unused stack-section.
} else if(battle_config.error_log) } else if( battle_config.error_log )
ShowError("stack.sp(%d) != default(%d)\n",stack->sp,stack->defsp); ShowError("script:run_script_main: unexpected stack position stack.sp(%d) != default(%d)\n", stack->sp, stack->defsp);
stack->sp=stack->defsp; stack->sp = stack->defsp;
} }
break; break;
case C_INT: case C_INT:
@ -4175,8 +4171,8 @@ struct script_function buildin_func[] = {
BUILDIN_DEF(mobremove,"i"), BUILDIN_DEF(mobremove,"i"),
BUILDIN_DEF(getmobdata,"i*"), BUILDIN_DEF(getmobdata,"i*"),
BUILDIN_DEF(setmobdata,"iii"), BUILDIN_DEF(setmobdata,"iii"),
BUILDIN_DEF(mobassist,"i*"), BUILDIN_DEF(mobassist,"i?"),
BUILDIN_DEF(mobattach,"i*"), BUILDIN_DEF(mobattach,"i?"),
BUILDIN_DEF(unitwalk,"ii?"), BUILDIN_DEF(unitwalk,"ii?"),
BUILDIN_DEF(unitkill,"i"), BUILDIN_DEF(unitkill,"i"),
BUILDIN_DEF(unitwarp,"isii"), BUILDIN_DEF(unitwarp,"isii"),
@ -12511,6 +12507,8 @@ BUILDIN_FUNC(pcstopfollow)
} }
// <--- [zBuffer] List of player cont commands // <--- [zBuffer] List of player cont commands
// [zBuffer] List of mob control commands ---> // [zBuffer] List of mob control commands --->
//## TODO always return if the request/whatever was successfull [FlavioJS]
BUILDIN_FUNC(mobspawn) BUILDIN_FUNC(mobspawn)
{ {
int class_,x,y,id; int class_,x,y,id;
@ -12589,156 +12587,193 @@ BUILDIN_FUNC(getmobdata)
return 0; return 0;
} }
/// Changes the data of a mob
///
/// setmobdata <mob unit id>,<type>,<value>;
BUILDIN_FUNC(setmobdata) BUILDIN_FUNC(setmobdata)
{ {
int id, value, value2; struct block_list* mob_bl;
struct mob_data *md = NULL;
id = conv_num(st, & (st->stack->stack_data[st->start+2])); mob_bl = map_id2bl(conv_num(st, script_getdata(st, 2)));
value = conv_num(st, & (st->stack->stack_data[st->start+3]));
value2 = conv_num(st, & (st->stack->stack_data[st->start+4])); if( mob_bl != NULL && mob_bl->type == BL_MOB )
if(!(md = (struct mob_data *)map_id2bl(id)) || md->bl.type != BL_MOB){ {
ShowWarning("buildin_setmobdata: Error in argument!\n"); TBL_MOB* md = (TBL_MOB*)mob_bl;
return -1; int type;
} int value;
switch(value){
type = conv_num(st, script_getdata(st, 3));
value = conv_num(st, script_getdata(st, 4));
switch( type )
{
case 0: case 0:
md->class_ = (short)value2; md->class_ = (short)value;
break; break;
case 1: case 1:
md->level = (unsigned short)value2; md->level = (unsigned short)value;
break; break;
case 2: case 2:
md->status.hp = (unsigned int)value2; md->status.hp = (unsigned int)value;
break; break;
case 3: case 3:
md->status.max_hp = (unsigned int)value2; md->status.max_hp = (unsigned int)value;
break; break;
case 4: case 4:
md->master_id = value2; md->master_id = value;
break; break;
case 5: case 5:
md->bl.m = (short)value2; md->bl.m = (short)value;
break; break;
case 6: case 6:
md->bl.x = (short)value2; md->bl.x = (short)value;
break; break;
case 7: case 7:
md->bl.y = (short)value2; md->bl.y = (short)value;
break; break;
case 8: case 8:
md->status.speed = (unsigned short)value2; md->status.speed = (unsigned short)value;
break; break;
case 9: case 9:
md->status.mode = (unsigned short)value2; md->status.mode = (unsigned short)value;
break; break;
case 10: case 10:
md->special_state.ai = (unsigned int)value2; md->special_state.ai = (unsigned int)value;
break; break;
case 11: case 11:
md->sc.option = (unsigned short)value2; md->sc.option = (unsigned short)value;
break; break;
case 12: case 12:
md->vd->sex = (char)value2; md->vd->sex = (char)value;
break; break;
case 13: case 13:
md->vd->class_ = (unsigned short)value2; md->vd->class_ = (unsigned short)value;
break; break;
case 14: case 14:
md->vd->hair_style = (unsigned short)value2; md->vd->hair_style = (unsigned short)value;
break; break;
case 15: case 15:
md->vd->hair_color = (unsigned short)value2; md->vd->hair_color = (unsigned short)value;
break; break;
case 16: case 16:
md->vd->head_bottom = (unsigned short)value2; md->vd->head_bottom = (unsigned short)value;
break; break;
case 17: case 17:
md->vd->head_mid = (unsigned short)value2; md->vd->head_mid = (unsigned short)value;
break; break;
case 18: case 18:
md->vd->head_top = (unsigned short)value2; md->vd->head_top = (unsigned short)value;
break; break;
case 19: case 19:
md->vd->cloth_color = (unsigned short)value2; md->vd->cloth_color = (unsigned short)value;
break; break;
case 20: case 20:
md->vd->shield = (unsigned short)value2; md->vd->shield = (unsigned short)value;
break; break;
case 21: case 21:
md->vd->weapon = (unsigned short)value2; md->vd->weapon = (unsigned short)value;
break; break;
case 22: case 22:
md->vd->shield = (unsigned short)value2; md->vd->shield = (unsigned short)value;
break; break;
case 23: case 23:
md->ud.dir = (unsigned char)value2; md->ud.dir = (unsigned char)value;
break; break;
case 24: case 24:
md->state.killer = value2>0?1:0; md->state.killer = value > 0 ? 1 : 0;
break; break;
case 25: case 25:
md->callback_flag = (short)value2; md->callback_flag = (short)value;
break; break;
case 26: case 26:
md->state.no_random_walk = value2>0?1:0; md->state.no_random_walk = value > 0 ? 1 : 0;
break; break;
default: default:
ShowError("buildin_setmobdata: argument id is not identified."); ShowError("script:setmobdata: unknown data identifier %d\n", type);
return -1; return 1;
}
} }
return 0; return 0;
} }
/// Makes the mob assist the target unit as a slave
///
/// mobassist <mob unit id>,"<player name>";
/// mobassist <mob unit id>,<target id>;
BUILDIN_FUNC(mobassist) BUILDIN_FUNC(mobassist)
{ {
int id; struct block_list* mob_bl;
const char *target;
struct mob_data *md = NULL;
struct block_list *bl = NULL;
struct unit_data *ud;
id = conv_num(st, & (st->stack->stack_data[st->start+2]));
target = conv_str(st, & (st->stack->stack_data[st->start+3]));
if((bl =&(map_nick2sd(target)->bl)) || (bl = map_id2bl(atoi(target)))) { // get mob
md = (struct mob_data *)map_id2bl(id); mob_bl = map_id2bl(conv_num(st, script_getdata(st,2)));
if(md && md->bl.type == BL_MOB) { if( mob_bl != NULL && mob_bl->type == BL_MOB )
ud = unit_bl2ud(bl); {
md->master_id = bl->id; TBL_MOB* md = (TBL_MOB*)mob_bl;
struct block_list* target_bl = NULL;
struct script_data* data;
// get target
data = script_getdata(st, 3);
get_val(st, data);
if( data_isstring(data) )
{
struct map_session_data* sd = map_nick2sd(conv_str(st, data));
if( sd != NULL )
target_bl = &sd->bl;
}
if( target_bl == NULL )
target_bl = map_id2bl(conv_num(st, data));
// set mob as slave
if( target_bl != NULL )
{
struct unit_data* ud;
md->master_id = target_bl->id;
md->state.killer = 1; md->state.killer = 1;
mob_convertslave(md); mob_convertslave(md);
if (ud) { ud = unit_bl2ud(mob_bl);
if (ud->target) if( ud != NULL )
{
if( ud->target != 0 )
md->target_id = ud->target; md->target_id = ud->target;
else if (ud->skilltarget) else if( ud->skilltarget != 0 )
md->target_id = ud->skilltarget; md->target_id = ud->skilltarget;
if(md->target_id) if( md->target_id != 0 )
unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2); unit_walktobl(&md->bl, map_id2bl(md->target_id), 65025, 2);
} }
} }
} }
return 0; return 0;
} }
/// Attaches the current npc or the target npc to the mob unit
///
/// mobattach <mob unit id>{,"<npc name>"};
BUILDIN_FUNC(mobattach) BUILDIN_FUNC(mobattach)
{ {
int id; struct block_list* mob_bl;
struct mob_data *md = NULL;
struct npc_data *nd = NULL;
const char *npcname = NULL;
id = conv_num(st, & (st->stack->stack_data[st->start+2]));
if(st->end > st->start + 3){
npcname = conv_str(st, & (st->stack->stack_data[st->start+3]));
}
if(npcname) mob_bl = map_id2bl(conv_num(st, script_getdata(st,2)));
nd = npc_name2id(npcname); if( mob_bl != NULL && mob_bl->type == BL_MOB )
else {
nd = (struct npc_data *)map_id2bl(st->oid); TBL_MOB* md = (TBL_MOB*)mob_bl;
TBL_NPC* nd = NULL;
if(nd) if( script_hasdata(st,3) )
if((md = (struct mob_data *)map_id2bl(id)) && md->bl.type == BL_MOB) nd = npc_name2id(conv_str(st, script_getdata(st,3)));
else
{
struct block_list* npc_bl = map_id2bl(st->oid);
if( npc_bl != NULL && npc_bl->type == BL_NPC )
nd = (TBL_NPC*)npc_bl;
}
if( nd != NULL )
md->nd = nd; md->nd = nd;
}
return 0; return 0;
} }
@ -12746,8 +12781,8 @@ BUILDIN_FUNC(mobattach)
/// Makes the unit walk to target position or map /// Makes the unit walk to target position or map
/// Returns if it was successfull /// Returns if it was successfull
/// ///
/// unitwalk(<unit_id>,<x>,<y>) -> <bool>; /// unitwalk(<unit_id>,<x>,<y>) -> <bool>
/// unitwalk(<unit_id>,<map_id>) -> <bool>; /// unitwalk(<unit_id>,<map_id>) -> <bool>
BUILDIN_FUNC(unitwalk) BUILDIN_FUNC(unitwalk)
{ {
struct block_list* bl; struct block_list* bl;
@ -12787,7 +12822,7 @@ BUILDIN_FUNC(unitkill)
/// Warps the unit to the target position in the target map /// Warps the unit to the target position in the target map
/// Returns if it was successfull /// Returns if it was successfull
/// ///
/// unitwarp(<unit_id>,"<map name>",<x>,<y>) -> <bool>; /// unitwarp(<unit_id>,"<map name>",<x>,<y>) -> <bool>
BUILDIN_FUNC(unitwarp) BUILDIN_FUNC(unitwarp)
{ {
int unit_id; int unit_id;
@ -12802,7 +12837,7 @@ BUILDIN_FUNC(unitwarp)
y = (short)conv_num(st, script_getdata(st,5)); y = (short)conv_num(st, script_getdata(st,5));
bl = map_id2bl(unit_id); bl = map_id2bl(unit_id);
if( map != 0 && bl != NULL ) if( map > 0 && bl != NULL )
{ {
script_pushint(st, unit_warp(bl,map,x,y,0)); script_pushint(st, unit_warp(bl,map,x,y,0));
} }
@ -12814,48 +12849,71 @@ BUILDIN_FUNC(unitwarp)
return 0; return 0;
} }
/// TODO clean up /// Makes the unit attack the target.
/// If the unit is a player and <action type> is not 0, it does a continuous
/// attack instead of a single attack.
/// Returns if the request was successfull.
/// ///
/// unitattack(<unit_id>,"<target name>",<action type>) -> <bool>; /// unitattack(<unit_id>,"<target name>"{,<action type>}) -> <bool>
/// unitattack(<unit_id>,<target_id>,<action type>) -> <bool>; /// unitattack(<unit_id>,<target_id>{,<action type>}) -> <bool>
/// unitattack(<unit_id>,"<target name>") -> <bool>;
/// unitattack(<unit_id>,<target_id>) -> <bool>;
BUILDIN_FUNC(unitattack) BUILDIN_FUNC(unitattack)
{ {
struct block_list* unit_bl;
int id = 0, actiontype = 0; int id = 0, actiontype = 0;
const char *target = NULL; const char *target = NULL;
struct map_session_data *sd = NULL; struct map_session_data *sd = NULL;
struct block_list *bl = NULL, *tbl = NULL; struct block_list *bl = NULL, *tbl = NULL;
id = conv_num(st, & (st->stack->stack_data[st->start+2]));
target = conv_str(st, & (st->stack->stack_data[st->start+3]));
if(st->end > st->start + 4)
actiontype = conv_num(st, & (st->stack->stack_data[st->start+4]));
sd = map_nick2sd(target); // get unit
if(!sd) unit_bl = map_id2bl(conv_num(st, script_getdata(st, 2)));
tbl = map_id2bl(atoi(target)); if( unit_bl != NULL )
else {
tbl = &sd->bl; struct block_list* target_bl = NULL;
struct script_data* data;
int actiontype = 0;
if((bl = map_id2bl(id))){ // get target
switch (bl->type) { data = script_getdata(st, 3);
case BL_PC: get_val(st, data);
clif_parse_ActionRequest_sub(((TBL_PC *)bl), actiontype > 0?0x07:0x00, tbl->id, gettick()); if( data_isstring(data) )
push_val(st->stack,C_INT,1); {
return 0; struct map_session_data* sd = map_nick2sd(conv_str(st, data));
case BL_MOB: if( sd != NULL )
((TBL_MOB *)bl)->state.killer = 1; target_bl = &sd->bl;
((TBL_MOB *)bl)->target_id = tbl->id; }
break; if( target_bl == NULL )
case BL_PET: target_bl = map_id2bl(conv_num(st, data));
((TBL_PET *)bl)->target_id = tbl->id;
break; // get actiontype
if( script_hasdata(st,4) )
actiontype = conv_num(st, script_getdata(st, 4));
// request the attack
if( target_bl != NULL )
{
switch( unit_bl->type )
{
case BL_PC:
clif_parse_ActionRequest_sub(((TBL_PC *)unit_bl), actiontype > 0 ? 0x07 : 0x00, target_bl->id, gettick());
script_pushint(st, 1);
return 0;
case BL_MOB:
((TBL_MOB *)unit_bl)->state.killer = 1;
((TBL_MOB *)unit_bl)->target_id = target_bl->id;
break;
case BL_PET:
((TBL_PET *)unit_bl)->target_id = target_bl->id;
break;
default:
ShowError("script:unitattack: unsupported source unit type %d\n", unit_bl->type);
script_pushint(st, 0);
return 0;
}
script_pushint(st, unit_walktobl(unit_bl, target_bl, 65025, 2));
} }
push_val(st->stack,C_INT,unit_walktobl(bl, tbl, 65025, 2));
} else {
push_val(st->stack,C_INT,0);
} }
script_pushint(st, 0);
return 0; return 0;
} }
@ -12953,6 +13011,10 @@ BUILDIN_FUNC(unitdeadsit)
WBUFL(buf, 2) = bl->id; WBUFL(buf, 2) = bl->id;
WBUFB(buf,26) = (unsigned char)action; WBUFB(buf,26) = (unsigned char)action;
clif_send(buf, 61, bl, AREA); clif_send(buf, 61, bl, AREA);
} else
{
ShowWarning("script:unitdeadsit: %d is not a valid action\n", action);
report_src(st);
} }
} }