Weave Architecture & Making a new weave

Post Reply
Site Admin
Posts: 89
Joined: 2009-08-27 21:49
Location: Brisbane, Australia

Weave Architecture & Making a new weave

Post by DerSaidin » 2009-09-06 12:37

Adding a weave requires inserting code in both game and client game. This list is a reference for coders, so you don't miss any.

In summary:
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:
  1. Player weaves a combination of elements. This is stored in an array.
  2. ThreadsDefensive & ThreadsAgressive (in spell_shared.c) decode the array to the weave_weaves enum (in spell_common.h)
  3. CreateWeave (in g_spell_weave.c) is called with the spell enum.
    1. Creates a held weave entity with parameters specific to the spell enum provided.
    2. Associates newly created held weave entity with the player who cast it.
From firing held weave to weave effect:
  1. Weapon fire function checks if the currently selected weapon is a weave. If it is, UseHeldWeave (in g_spell_weave.c) is called.
  2. UseHeldWeave (in g_spell_weave.c) gets parameters from a held weave entity.
    1. 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.
    2. Decrements available shots on the held weave entity.
    3. Reduces the amount of power used by the held weave entity.
    4. Cleans up held weaves which are expired or have no more shots.
Code needed to add a new spell

Server Side Code:
  1. Add to weave_weaves enum (in spell_common.h), if its not already there
  2. Add the check to ThreadsDefensive or ThreadsAgressive (in spell_shared.c)
  3. In CreateWeave (in g_spell_weave.c) add a call to create the appropriate held weave entity.
  4. 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)
    1. Declare the new function (in g_spell_effects.h)
    2. Any constants used should be #defined (in spell_common.h)
    3. 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.
      1. On successfull cast, set heldWeave->s.frame = WST_INPROCESS;
      2. Set heldWeave->nextthink = 0; to prevent expiring
      3. Ensure heldWeave->target_ent references the weave effect entity;
      4. Add a EndWeave_ (in g_spell_effects.c) function and declare the new function (in g_spell_effects.h)
        1. Finalizes effects (ie, G_FreeEntity(heldWeave->target_ent);)
        2. Removes reference to effects (ie, heldWeave->target_ent = NULL;)
      5. In EndWeave (in g_spell_weave.c) add a call to the new EndWeave_ (in g_spell_effects.c).
  5. In ExecuteWeave (in g_spell_weave.c) add call to the new FireWeave_ (in g_spell_effects.c).
  6. 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).
  7. Add the weave to WeaveProtectScales (in spell_shared.c)
  8. Add the weave to WeaveTier (in spell_shared.c)
  9. If weave has more than 1 shot, add it to WeaveCharges (in spell_shared.c)
Client Side Code:
  1. In CG_WeaveEffect() (in cg_spell_effects.c) add a call to a function to create the client side effect.
    1. In most cases you should be able to use one of the functions already defined (in cg_spell_effects.c)
    2. If you must, define a new function above to render the effect.
    3. 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.
  2. In CG_RegisterWeaves() (in cg_main.c) add call to CG_RegisterWeave() (in cg_spell_weaves.c) for the new spell.
  3. 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.

Post Reply