Cast -> Held weave entity.
Fire (with a Held weave selected) -> FireWeave_* (specific to Held weave selected) -> Fireball entity spawned (or whatever the spell does)
The entity spawned will be of an eType (entity type) which leads to CG_WeaveEffect being called, or event added such as EV_WEAVE_SHOT which leads to CG_WeaveEffect being called.
CG_WeaveEffect then calls a function to produce client side effects for the spell.
How casting works
From casting to held weave:
- Player weaves a combination of elements. This is stored in an array.
- ThreadsDefensive & ThreadsAgressive (in spell_shared.c) decode the array to the weave_weaves enum (in spell_common.h)
- CreateWeave (in g_spell_weave.c) is called with the spell enum.
- Creates a held weave entity with parameters specific to the spell enum provided.
- Associates newly created held weave entity with the player who cast it.
- Weapon fire function checks if the currently selected weapon is a weave. If it is, UseHeldWeave (in g_spell_weave.c) is called.
- UseHeldWeave (in g_spell_weave.c) gets parameters from a held weave entity.
- Calls ExecuteWeave (in g_spell_weave.c) which calls the FireWeave_ (in g_spell_effects.c) function of that spell. This function does spell specific effects, such as spawning a fireball.
- Decrements available shots on the held weave entity.
- Reduces the amount of power used by the held weave entity.
- Cleans up held weaves which are expired or have no more shots.
Server Side Code:
- Add to weave_weaves enum (in spell_common.h), if its not already there
- Add the check to ThreadsDefensive or ThreadsAgressive (in spell_shared.c)
- In CreateWeave (in g_spell_weave.c) add a call to create the appropriate held weave entity.
- Add function to create the weave in a similar format to existing spells FireWeave_ (in g_spell_effects.c) this function is the one that will be called from ExecuteWeave (in g_spell_weave.c)
- Declare the new function (in g_spell_effects.h)
- Any constants used should be #defined (in spell_common.h)
- If the weave is something like a shield, UseHeldWeave once to start then UseHeldWeave a second time to end it, then the FireWeave_ (in g_spell_effects.c) needs to do the following so that the held weave goes to a "In process" state. For weaves such as this, the shots count is not decremented until the held weave is used in it's "In Process" state.
- On successfull cast, set heldWeave->s.frame = WST_INPROCESS;
- Set heldWeave->nextthink = 0; to prevent expiring
- Ensure heldWeave->target_ent references the weave effect entity;
- Add a EndWeave_ (in g_spell_effects.c) function and declare the new function (in g_spell_effects.h)
- Finalizes effects (ie, G_FreeEntity(heldWeave->target_ent);)
- Removes reference to effects (ie, heldWeave->target_ent = NULL;)
- In EndWeave (in g_spell_weave.c) add a call to the new EndWeave_ (in g_spell_effects.c).
- In ExecuteWeave (in g_spell_weave.c) add call to the new FireWeave_ (in g_spell_effects.c).
- If the spell has an entity which must be run, such as a missile, In G_RunWeaveEffect (in g_spell_weave.c) add call to the appropriate Think function of the effect. This will typically be a common function, such as RunWeave_Missile (in g_spell_weave.c).
- Add the weave to WeaveProtectScales (in spell_shared.c)
- Add the weave to WeaveTier (in spell_shared.c)
- If weave has more than 1 shot, add it to WeaveCharges (in spell_shared.c)
- In CG_WeaveEffect() (in cg_spell_effects.c) add a call to a function to create the client side effect.
- In most cases you should be able to use one of the functions already defined (in cg_spell_effects.c)
- If you must, define a new function above to render the effect.
- You should probably ask DerSaidin first, and we'll consider adding to the weaver_weaveInfo struct. The rest of the steps are all about defining the weaveInfo struct for the new spell.
- In CG_RegisterWeaves() (in cg_main.c) add call to CG_RegisterWeave() (in cg_spell_weaves.c) for the new spell.
- In CG_RegisterWeave() (in cg_spell_weaves.c) add a case to the switch to define parameters for effects of the spell. Keep in mind how each parameter will be used by the function called from CG_WeaveEffect (in cg_spell_effects.c), the call that was added back in step 1.