Infodump about multiple ammo types
Posted: 24 Sep 2013, 18:10
Recently, I showed that it's possible for an OnEquip script to safely remove an item. This is an infodump about all the states we have to deal with during the two OnEquip scripts.
If there are both a Launcher and an Ammo equipped, the launcher's OnEquip script is called before the Ammo's.
lowercase means it is not equipped.
Initial login:
l, a: nothing to do.
L, a: same as Equip, l->L, a.
l, A: same as Equip, l, a->A.
L, A: should always be okay, but is identical to Equip, L, a->A.
Use-up:
l, A->a: impossible.
L, A->a: same as Unequip: L, A->a.
Unequip: remember there is NO hook here!
l, A->a: enters null state, want no vars in case ammo is equipped first.
L, A->a: if launcher sets a var, no chance to unset it.
L->l, a: enters null state, want no vars in case ammo is equipped first.
L->l, A: if ammo sets a var, no chance to unset it.
Equip:
l, a->A: always okay, launcher var untouched, ammo script called should be a nop.
L, a->A: may remove ammo, needs to know launcher var.
l->L, a: always okay, launcher should not create pollution in case it is unequipped.
l->L, A: may remove ammo (!), needs to know launcher var.
Other notes:
Only one item can be unequipped at a time. This means the want-unequip event should set the ID to something it won't use. OTOH a call to unequip an empty slot is probably a noop ...
We should take special steps to make sure scripts don't set variables if the other slot has nothing.
So in item_db:
Bow has set @launcher, MAT_BOW; callfunc "LauncherCheck";
Arrow has set @ammo, MAT_BOW; callfunc "AmmoCheck";
(using appropriate nonzero constants from const.txt)
The launcher function looks like:
if nothing in ammo slot, set @launcher, 0
if something in ammo slot, set @launcher to something
return
The ammo function looks like:
Get @ammo from item_db before the call.
if !@launcher, goto L_Return
if @launcher == @ammo, goto L_Return
addtimer to unequip, then fallthroughto L_Return
L_Return clears @launcher and @ammo unconditionally.
return
If there are both a Launcher and an Ammo equipped, the launcher's OnEquip script is called before the Ammo's.
lowercase means it is not equipped.
Initial login:
l, a: nothing to do.
L, a: same as Equip, l->L, a.
l, A: same as Equip, l, a->A.
L, A: should always be okay, but is identical to Equip, L, a->A.
Use-up:
l, A->a: impossible.
L, A->a: same as Unequip: L, A->a.
Unequip: remember there is NO hook here!
l, A->a: enters null state, want no vars in case ammo is equipped first.
L, A->a: if launcher sets a var, no chance to unset it.
L->l, a: enters null state, want no vars in case ammo is equipped first.
L->l, A: if ammo sets a var, no chance to unset it.
Equip:
l, a->A: always okay, launcher var untouched, ammo script called should be a nop.
L, a->A: may remove ammo, needs to know launcher var.
l->L, a: always okay, launcher should not create pollution in case it is unequipped.
l->L, A: may remove ammo (!), needs to know launcher var.
Other notes:
Only one item can be unequipped at a time. This means the want-unequip event should set the ID to something it won't use. OTOH a call to unequip an empty slot is probably a noop ...
We should take special steps to make sure scripts don't set variables if the other slot has nothing.
So in item_db:
Bow has set @launcher, MAT_BOW; callfunc "LauncherCheck";
Arrow has set @ammo, MAT_BOW; callfunc "AmmoCheck";
(using appropriate nonzero constants from const.txt)
The launcher function looks like:
if nothing in ammo slot, set @launcher, 0
if something in ammo slot, set @launcher to something
return
The ammo function looks like:
Get @ammo from item_db before the call.
if !@launcher, goto L_Return
if @launcher == @ammo, goto L_Return
addtimer to unequip, then fallthroughto L_Return
L_Return clears @launcher and @ammo unconditionally.
return