[crossfire] Spellcasting Swords & Python Troubles
Andreas Kirschbaum
kirschbaum at myrealbox.com
Tue May 24 13:30:31 CDT 2005
Alex Schultz wrote:
>
From further analysis, I found that it is happening somewhere inside
>
this call "(PlugList[findPlugin(evt->plugin)].eventfunc) (&CFP);"
>
(server/attack.c line 693) but after the spell gets a chance to
>
activate.
You were right: the crash here happens because the called function
accesses an already freed object. The attached patch (fix-crash.diff)
fixes that problem for me but I'm not yet sure if it handles all
possible cases.
The other two attached files (test and swordcast.py) implement a few
spell casting swords. You should use the current CVS server because it
uses your new Python functions.
Note that I do not put a rod into the sword's inventory -- I just use
the spell itself. But this version still has a few problems left:
- It uses CastAbility() but not CastSpell(). CastAbility() creates the
spell object from the archetype name. Therefore it uses default
values (level 0) for the spell.
I cannot use CastSpell() (which takes a spell object) because it does
not include a "caster" parameter. Any objections to add that
parameter so that both functions (CastAbility and CastSpell)
basically have the same parameter list? (Btw: no script in
/maps-bigworld/python currently calls that function.)
- With some spells (for example firebolt) you gain only one handed
experience (both for direct kills from the sword and for kills from
the spell).
-------------- next part --------------
Index: plugin/plugin_python.c
===================================================================
RCS file: /cvsroot/crossfire/crossfire/plugin/plugin_python.c,v
retrieving revision 1.62
diff -w -c -5 -r1.62 plugin_python.c
*** plugin/plugin_python.c 20 May 2005 19:28:02 -0000 1.62
--- plugin/plugin_python.c 24 May 2005 17:55:24 -0000
***************
*** 72,81 ****
--- 72,85 ----
/* wrapper for fix_player */
static void PyFixPlayer( object* pl )
{
CFParm lCFR;
+
+ if(QUERY_FLAG(pl, FLAG_FREED))
+ return;
+
lCFR.Value[ 0 ] = pl;
PlugHooks[ HOOK_FIXPLAYER ]( &lCFR );
}
/* Set up an Python exception object.
Index: server/attack.c
===================================================================
RCS file: /cvsroot/crossfire/crossfire/server/attack.c,v
retrieving revision 1.106
diff -w -c -5 -r1.106 attack.c
*** server/attack.c 15 Apr 2005 00:41:34 -0000 1.106
--- server/attack.c 24 May 2005 17:55:26 -0000
***************
*** 639,648 ****
--- 639,651 ----
event *evt;
if (get_attack_mode (&op, &hitter, &simple_attack))
goto error;
+ op_tag = op->count;
+ hitter_tag = hitter->count;
+
/* GROS: Handle for plugin attack event */
if ((evt = find_event(op, EVENT_ATTACK)) != NULL)
{
CFParm CFP;
int k, l;
***************
*** 659,670 ****
CFP.Value[6] = &base_dam;
CFP.Value[7] = &base_wc;
CFP.Value[8] = &l;
CFP.Value[9] = evt->hook;
CFP.Value[10]= evt->options;
! if (findPlugin(evt->plugin)>=0)
((PlugList[findPlugin(evt->plugin)].eventfunc) (&CFP));
}
/* GROS: This is used to handle script_weapons with weapons. Only used for players */
if (hitter->type==PLAYER)
{
if (hitter->current_weapon != NULL)
--- 662,678 ----
CFP.Value[6] = &base_dam;
CFP.Value[7] = &base_wc;
CFP.Value[8] = &l;
CFP.Value[9] = evt->hook;
CFP.Value[10]= evt->options;
! if (findPlugin(evt->plugin)>=0) {
((PlugList[findPlugin(evt->plugin)].eventfunc) (&CFP));
+ if (was_destroyed(op, op_tag))
+ goto error;
+ if (was_destroyed(hitter, hitter_tag))
+ goto error;
+ }
}
/* GROS: This is used to handle script_weapons with weapons. Only used for players */
if (hitter->type==PLAYER)
{
if (hitter->current_weapon != NULL)
***************
*** 687,703 ****
CFP.Value[6] = &base_dam;
CFP.Value[7] = &base_wc;
CFP.Value[8] = &l;
CFP.Value[9] = evt->hook;
CFP.Value[10]= evt->options;
! if (findPlugin(evt->plugin)>=0)
(PlugList[findPlugin(evt->plugin)].eventfunc) (&CFP);
}
};
};
- op_tag = op->count;
- hitter_tag = hitter->count;
/*
* A little check to make it more difficult to dance forward and back
* to avoid ever being hit by monsters.
*/
--- 695,714 ----
CFP.Value[6] = &base_dam;
CFP.Value[7] = &base_wc;
CFP.Value[8] = &l;
CFP.Value[9] = evt->hook;
CFP.Value[10]= evt->options;
! if (findPlugin(evt->plugin)>=0) {
(PlugList[findPlugin(evt->plugin)].eventfunc) (&CFP);
+ if (was_destroyed(op, op_tag))
+ goto error;
+ if (was_destroyed(hitter, hitter_tag))
+ goto error;
+ }
}
};
};
/*
* A little check to make it more difficult to dance forward and back
* to avoid ever being hit by monsters.
*/
-------------- next part --------------
arch map
name test
msg
Creator: CF Java Map Editor
Date: 5/24/2005
endmsg
width 16
height 16
end
arch cobblestones
end
arch cobblestones
y 1
end
arch cobblestones
y 2
end
arch cobblestones
y 3
end
arch cobblestones
y 4
end
arch cobblestones
y 5
end
arch cobblestones
y 6
end
arch cobblestones
y 7
end
arch cobblestones
y 8
end
arch cobblestones
y 9
end
arch cobblestones
y 10
end
arch cobblestones
y 11
end
arch cobblestones
y 12
end
arch cobblestones
y 13
end
arch cobblestones
y 14
end
arch cobblestones
y 15
end
arch cobblestones
x 1
end
arch cobblestones
x 1
y 1
end
arch sword
name spellcaster (firebolt)
name_pl spellcasters (firebolt)
event_attack_plugin Python
event_attack /swordcast.py
x 1
y 1
arch spell_firebolt
end
end
arch sword
name swordcast (banishment)
name_pl swordcasts (banishment)
event_attack_plugin Python
event_attack /swordcast.py
x 1
y 1
arch spell_banishment
end
end
arch sword
name swordcast (windstorm)
name_pl swordcasts (windstorm)
event_attack_plugin Python
event_attack /swordcast.py
x 1
y 1
arch spell_windstorm
end
end
arch sword
name swordcast (faery fire)
name_pl swordcasts (faery fire)
event_attack_plugin Python
event_attack /swordcast.py
x 1
y 1
arch spell_faery_fire
end
end
arch sword
name swordcast (bullet swarm)
name_pl swordcasts (bullet swarm)
event_attack_plugin Python
event_attack /swordcast.py
x 1
y 1
arch spell_bullet_swarm
end
end
arch cobblestones
x 1
y 2
end
arch cobblestones
x 1
y 3
end
arch cobblestones
x 1
y 4
end
arch cobblestones
x 1
y 5
end
arch cobblestones
x 1
y 6
end
arch cobblestones
x 1
y 7
end
arch cobblestones
x 1
y 8
end
arch cobblestones
x 1
y 9
end
arch cobblestones
x 1
y 10
end
arch cobblestones
x 1
y 11
end
arch cobblestones
x 1
y 12
end
arch cobblestones
x 1
y 13
end
arch cobblestones
x 1
y 14
end
arch generate_mouse
x 1
y 14
end
arch cobblestones
x 1
y 15
end
arch cobblestones
x 2
end
arch cobblestones
x 2
y 1
end
arch cobblestones
x 2
y 2
end
arch cobblestones
x 2
y 3
end
arch cobblestones
x 2
y 4
end
arch cobblestones
x 2
y 5
end
arch cobblestones
x 2
y 6
end
arch cobblestones
x 2
y 7
end
arch cobblestones
x 2
y 8
end
arch cobblestones
x 2
y 9
end
arch cobblestones
x 2
y 10
end
arch cobblestones
x 2
y 11
end
arch cobblestones
x 2
y 12
end
arch cobblestones
x 2
y 13
end
arch cobblestones
x 2
y 14
end
arch cobblestones
x 2
y 15
end
arch cobblestones
x 3
end
arch cobblestones
x 3
y 1
end
arch cobblestones
x 3
y 2
end
arch cobblestones
x 3
y 3
end
arch cobblestones
x 3
y 4
end
arch cobblestones
x 3
y 5
end
arch cobblestones
x 3
y 6
end
arch cobblestones
x 3
y 7
end
arch cobblestones
x 3
y 8
end
arch cobblestones
x 3
y 9
end
arch cobblestones
x 3
y 10
end
arch cobblestones
x 3
y 11
end
arch cobblestones
x 3
y 12
end
arch cobblestones
x 3
y 13
end
arch cobblestones
x 3
y 14
end
arch cobblestones
x 3
y 15
end
arch cobblestones
x 4
end
arch cobblestones
x 4
y 1
end
arch cobblestones
x 4
y 2
end
arch cobblestones
x 4
y 3
end
arch cobblestones
x 4
y 4
end
arch cobblestones
x 4
y 5
end
arch cobblestones
x 4
y 6
end
arch cobblestones
x 4
y 7
end
arch cobblestones
x 4
y 8
end
arch cobblestones
x 4
y 9
end
arch cobblestones
x 4
y 10
end
arch cobblestones
x 4
y 11
end
arch cobblestones
x 4
y 12
end
arch cobblestones
x 4
y 13
end
arch cobblestones
x 4
y 14
end
arch cobblestones
x 4
y 15
end
arch cobblestones
x 5
end
arch cobblestones
x 5
y 1
end
arch cobblestones
x 5
y 2
end
arch cobblestones
x 5
y 3
end
arch cobblestones
x 5
y 4
end
arch cobblestones
x 5
y 5
end
arch cobblestones
x 5
y 6
end
arch cobblestones
x 5
y 7
end
arch cobblestones
x 5
y 8
end
arch cobblestones
x 5
y 9
end
arch cobblestones
x 5
y 10
end
arch cobblestones
x 5
y 11
end
arch cobblestones
x 5
y 12
end
arch cobblestones
x 5
y 13
end
arch cobblestones
x 5
y 14
end
arch cobblestones
x 5
y 15
end
arch cobblestones
x 6
end
arch cobblestones
x 6
y 1
end
arch cobblestones
x 6
y 2
end
arch cobblestones
x 6
y 3
end
arch cobblestones
x 6
y 4
end
arch cobblestones
x 6
y 5
end
arch cobblestones
x 6
y 6
end
arch cobblestones
x 6
y 7
end
arch cobblestones
x 6
y 8
end
arch cobblestones
x 6
y 9
end
arch cobblestones
x 6
y 10
end
arch cobblestones
x 6
y 11
end
arch cobblestones
x 6
y 12
end
arch cobblestones
x 6
y 13
end
arch cobblestones
x 6
y 14
end
arch cobblestones
x 6
y 15
end
arch cobblestones
x 7
end
arch cobblestones
x 7
y 1
end
arch cobblestones
x 7
y 2
end
arch cobblestones
x 7
y 3
end
arch cobblestones
x 7
y 4
end
arch cobblestones
x 7
y 5
end
arch cobblestones
x 7
y 6
end
arch cobblestones
x 7
y 7
end
arch cobblestones
x 7
y 8
end
arch cobblestones
x 7
y 9
end
arch cobblestones
x 7
y 10
end
arch cobblestones
x 7
y 11
end
arch cobblestones
x 7
y 12
end
arch cobblestones
x 7
y 13
end
arch cobblestones
x 7
y 14
end
arch cobblestones
x 7
y 15
end
arch cobblestones
x 8
end
arch cobblestones
x 8
y 1
end
arch cobblestones
x 8
y 2
end
arch cobblestones
x 8
y 3
end
arch cobblestones
x 8
y 4
end
arch cobblestones
x 8
y 5
end
arch cobblestones
x 8
y 6
end
arch cobblestones
x 8
y 7
end
arch cobblestones
x 8
y 8
end
arch cobblestones
x 8
y 9
end
arch cobblestones
x 8
y 10
end
arch cobblestones
x 8
y 11
end
arch cobblestones
x 8
y 12
end
arch cobblestones
x 8
y 13
end
arch cobblestones
x 8
y 14
end
arch cobblestones
x 8
y 15
end
arch cobblestones
x 9
end
arch cobblestones
x 9
y 1
end
arch cobblestones
x 9
y 2
end
arch cobblestones
x 9
y 3
end
arch cobblestones
x 9
y 4
end
arch cobblestones
x 9
y 5
end
arch cobblestones
x 9
y 6
end
arch cobblestones
x 9
y 7
end
arch cobblestones
x 9
y 8
end
arch cobblestones
x 9
y 9
end
arch cobblestones
x 9
y 10
end
arch cobblestones
x 9
y 11
end
arch cobblestones
x 9
y 12
end
arch cobblestones
x 9
y 13
end
arch cobblestones
x 9
y 14
end
arch cobblestones
x 9
y 15
end
arch cobblestones
x 10
end
arch cobblestones
x 10
y 1
end
arch cobblestones
x 10
y 2
end
arch cobblestones
x 10
y 3
end
arch cobblestones
x 10
y 4
end
arch cobblestones
x 10
y 5
end
arch cobblestones
x 10
y 6
end
arch cobblestones
x 10
y 7
end
arch cobblestones
x 10
y 8
end
arch cobblestones
x 10
y 9
end
arch cobblestones
x 10
y 10
end
arch cobblestones
x 10
y 11
end
arch cobblestones
x 10
y 12
end
arch cobblestones
x 10
y 13
end
arch cobblestones
x 10
y 14
end
arch cobblestones
x 10
y 15
end
arch cobblestones
x 11
end
arch cobblestones
x 11
y 1
end
arch cobblestones
x 11
y 2
end
arch cobblestones
x 11
y 3
end
arch cobblestones
x 11
y 4
end
arch cobblestones
x 11
y 5
end
arch cobblestones
x 11
y 6
end
arch cobblestones
x 11
y 7
end
arch cobblestones
x 11
y 8
end
arch cobblestones
x 11
y 9
end
arch cobblestones
x 11
y 10
end
arch cobblestones
x 11
y 11
end
arch cobblestones
x 11
y 12
end
arch cobblestones
x 11
y 13
end
arch cobblestones
x 11
y 14
end
arch cobblestones
x 11
y 15
end
arch cobblestones
x 12
end
arch cobblestones
x 12
y 1
end
arch cobblestones
x 12
y 2
end
arch cobblestones
x 12
y 3
end
arch cobblestones
x 12
y 4
end
arch cobblestones
x 12
y 5
end
arch cobblestones
x 12
y 6
end
arch cobblestones
x 12
y 7
end
arch cobblestones
x 12
y 8
end
arch cobblestones
x 12
y 9
end
arch cobblestones
x 12
y 10
end
arch cobblestones
x 12
y 11
end
arch cobblestones
x 12
y 12
end
arch cobblestones
x 12
y 13
end
arch cobblestones
x 12
y 14
end
arch cobblestones
x 12
y 15
end
arch cobblestones
x 13
end
arch cobblestones
x 13
y 1
end
arch cobblestones
x 13
y 2
end
arch cobblestones
x 13
y 3
end
arch cobblestones
x 13
y 4
end
arch cobblestones
x 13
y 5
end
arch cobblestones
x 13
y 6
end
arch cobblestones
x 13
y 7
end
arch cobblestones
x 13
y 8
end
arch cobblestones
x 13
y 9
end
arch cobblestones
x 13
y 10
end
arch cobblestones
x 13
y 11
end
arch cobblestones
x 13
y 12
end
arch cobblestones
x 13
y 13
end
arch cobblestones
x 13
y 14
end
arch cobblestones
x 13
y 15
end
arch cobblestones
x 14
end
arch cobblestones
x 14
y 1
end
arch cobblestones
x 14
y 2
end
arch cobblestones
x 14
y 3
end
arch cobblestones
x 14
y 4
end
arch cobblestones
x 14
y 5
end
arch cobblestones
x 14
y 6
end
arch cobblestones
x 14
y 7
end
arch cobblestones
x 14
y 8
end
arch cobblestones
x 14
y 9
end
arch cobblestones
x 14
y 10
end
arch cobblestones
x 14
y 11
end
arch cobblestones
x 14
y 12
end
arch cobblestones
x 14
y 13
end
arch cobblestones
x 14
y 14
end
arch cobblestones
x 14
y 15
end
arch cobblestones
x 15
end
arch cobblestones
x 15
y 1
end
arch cobblestones
x 15
y 2
end
arch cobblestones
x 15
y 3
end
arch cobblestones
x 15
y 4
end
arch cobblestones
x 15
y 5
end
arch cobblestones
x 15
y 6
end
arch cobblestones
x 15
y 7
end
arch cobblestones
x 15
y 8
end
arch cobblestones
x 15
y 9
end
arch cobblestones
x 15
y 10
end
arch cobblestones
x 15
y 11
end
arch cobblestones
x 15
y 12
end
arch cobblestones
x 15
y 13
end
arch cobblestones
x 15
y 14
end
arch cobblestones
x 15
y 15
end
-------------- next part --------------
A non-text attachment was scrubbed...
Name: swordcast.py
Type: text/x-python
Size: 258 bytes
Desc: not available
Url :
http://shadowknight.real-time.com/pipermail/crossfire/attachments/20050524/2192ab9e/swordcast.py
More information about the crossfire
mailing list