Skip to content

Custom Collisions

szapp edited this page Oct 30, 2017 · 16 revisions

The feature Custom Collisions (GFA_CUSTOM_COLLISIONS) allows to manipulate the collision behavior of projectiles (arrows and bolts) in ranged combat. It can be customized under what circumstances a projectiles bounces off of a surface, gets stuck in it or breaks on impact. Likewise the hit registration on NPCs can be customized to have projectile vanish or bounce off of an NPC armor instead of causing damage and eliciting an AI reaction.
Furthermore the damage behavior of projectiles can be altered. For example, projectiles can be set to never kill, but always only knockout a certain enemy.
 

Contents

1.   Constants
    1.1.   GFA_COLL_PRIOR_NPC
    1.2.   GFA_TRIGGER_COLL_FIX
2.   Config Functions
    2.1.   GFA_GetCollisionWithNpc
    2.2.   GFA_GetCollisionWithWorld
    2.3.   GFA_GetDamageBehavior


Constants

The constants can be found in the file config/settings.d.

GFA_COLL_PRIOR_NPC

Adjust the collision behavior on NPCs on rebound. That means when the projectile already collided with the world and is currently bouncing off. This constant can take values similar to GFA_GetCollisionWithNpc, plus one additional option :

  • -1 : No collision with NPCs after first collision (the projectile flies/falls through any NPC after collision).
  • 0 : No hit registration (no damage), projectile vanishes when hitting an NPC.
  • 1 : Positive hit registration. Gothic default.
  • 2 : No hit registration (no damage), projectile bounces off.

GFA_TRIGGER_COLL_FIX

When this constant is set to true, the trigger collision fix is applied.
This is a inherent bug in Gothic 2: When shooting a projectile inside a trigger with certain properties, the projectile collides continuously and causes a nerve wrecking sound. Any trigger colliding with a projectile is checked for certain properties to prevent the collision. Triggers that require projectile collision (like the levers on Irdorath) are unaffected and remain intact.
This constant is ignored when using GFA in in Gothic 1.


Config Functions

The configuration of this feature is found in the file config/collisions.d.

GFA_GetCollisionWithNpc

This function is called every time an NPC is hit (positive hit!) by a projectile (arrows and bolts). It can be used to define the collision behavior (or disabling hit registration and damage) on NPCs based on different criteria.

Note: Unlike most other config functions, this function is also called for NPC shooters!

Note: If GFA_TRUE_HITCHANCE == true, this function is called for ALL hits (all hits are positive hits).
          If GFA_TRUE_HITCHANCE == false, this function is called for POSITIVE hits only.

Ideas: 'ineffective' ranged weapons, armor materials immune to arrows, disable friendly-fire, maximum range, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.

func int GFA_GetCollisionWithNpc(C_Npc shooter, C_Npc target, C_Item weapon, int material)
shooter The NPC that shot the projectile.
target The NPC that was hit with the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
material Material of the armor of the target as defined as in Constants.d (MAT_METAL, MAT_WOOD, ...). -1 for no armor equipped.
returns The collision response, see below.
  • DAMAGE : Positive hit registration (projectile is put into inventory if GFA_REUSE_PROJECTILES is used).
  • DEFLECT : No hit registration (no damage), projectile bounces off.
  • DESTROY : No hit registration (no damage), projectile vanishes.
     

GFA_GetCollisionWithWorld

This function is called every time the world (static or vobs) is hit by a projectile (arrows and bolts). It can be used to define the collision behavior for different materials or surface textures.

Note: Unlike most other config functions, this function is also called for NPC shooters!

CAUTION: Unfortunately, all vobs in Gothic 1 belong to the UNDEF material group. With descriptive texture names, however, the material can be retrieved, e.g. (STR_IndexOf(textures, "WOOD") != 1). At the end of this function, there is an elaborate check for all wooden textures in Gothic 1 to compensate for the lack of material groups.

Ideas: projectiles get stuck in wood, always bounce off of metal, sometimes break when hitting stone, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.

func int GFA_GetCollisionWithWorld(C_Npc shooter, C_Item weapon, int materials, string textures)
shooter The NPC that shot the projectile.
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
materials Bit field for all materials attached to the surface.
textures String containing all texture names of the surface, delimiter: "|".
returns The collision response, see below.
  • DESTROY : Projectile is destroyed on impact.
  • STUCK : Projectile gets stuck in the surface.
  • DEFLECT : Projectile is repelled.
     

GFA_GetDamageBehavior

This function is called every time an NPC is hit by a projectile (arrows and bolts). It can be used to define the damage behavior on NPCs based on different criteria. Damage behavior defines how much damage is eventually applied to the victim. This allows, e.g. to prevent a victim from dying, and instead knock it out with one shot (see examples inside the function).

Note: This function is only called if the player is the shooter.

Ideas: special knockout munition, NPCs that cannot be killed by ranged weapons, instant kill on critical hit, ...
Examples are given inside the function, but commented out to serve as inspiration of what is possible.

func int GFA_GetDamageBehavior(C_Npc target, C_Item weapon, int talent, int isCritialHit)
target The NPC that is hit by the projectile
weapon The ranged weapon that the shooter used (might be empty if unequipped immediately!).
talent The talent value of the shooter depending on the ranged weapon.
isCriticalHit States whether the active shit is a critical hit (true/false).
returns The damage behavior, see below.
  • DO_NOT_KNOCKOUT : Gothic default: Normal damage, projectiles kill and never knockout (HP != 1).
  • DO_NOT_KILL : Normal damage, projectiles knockout and never kill (HP > 0).
  • INSTANT_KNOCKOUT : One shot knockout (1 HP).
  • INSTANT_KILL : One shot kill (0 HP).