Skip to content

Commit

Permalink
Improve compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed May 9, 2024
1 parent f15b6a2 commit 7698c3c
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 45 deletions.
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/_intern/activate.d
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func void GFA_IsActive() {
GFA_SetCameraModes(1);

// Check if active spell supports free aiming
var C_Spell spell; spell = GFA_GetActiveSpellInst(hero);
var GFA_C_Spell spell; spell = GFA_GetActiveSpellInst(hero);
var int eligible; eligible = GFA_IsSpellEligible(spell);
if (!(eligible & GFA_ACT_FREEAIM)) {
// Reset spell focus collection
Expand Down
12 changes: 6 additions & 6 deletions _work/data/Scripts/Content/GFA/_intern/aimRay.d
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ func int GFA_AimRay(var int distance, var int focusType, var int vobPtr, var int

// Line consisting of two points: Left and right of the player model along the camera right vector
var int line[6];
line[0] = subf(her._zCVob_trafoObjToWorld[ 3], mulf(camPos.v0[zMAT4_rightVec], FLOAT1K)); // Left
line[1] = subf(her._zCVob_trafoObjToWorld[ 7], mulf(camPos.v1[zMAT4_rightVec], FLOAT1K));
line[2] = subf(her._zCVob_trafoObjToWorld[11], mulf(camPos.v2[zMAT4_rightVec], FLOAT1K));
line[3] = addf(her._zCVob_trafoObjToWorld[ 3], mulf(camPos.v0[zMAT4_rightVec], FLOAT1K)); // Right
line[4] = addf(her._zCVob_trafoObjToWorld[ 7], mulf(camPos.v1[zMAT4_rightVec], FLOAT1K));
line[5] = addf(her._zCVob_trafoObjToWorld[11], mulf(camPos.v2[zMAT4_rightVec], FLOAT1K));
line[0] = subf(her._zCVob_trafoObjToWorld[ 3], mulf(camPos.v0[zMAT4_rightVec], GFA_FLOAT1K)); // Left
line[1] = subf(her._zCVob_trafoObjToWorld[ 7], mulf(camPos.v1[zMAT4_rightVec], GFA_FLOAT1K));
line[2] = subf(her._zCVob_trafoObjToWorld[11], mulf(camPos.v2[zMAT4_rightVec], GFA_FLOAT1K));
line[3] = addf(her._zCVob_trafoObjToWorld[ 3], mulf(camPos.v0[zMAT4_rightVec], GFA_FLOAT1K)); // Right
line[4] = addf(her._zCVob_trafoObjToWorld[ 7], mulf(camPos.v1[zMAT4_rightVec], GFA_FLOAT1K));
line[5] = addf(her._zCVob_trafoObjToWorld[11], mulf(camPos.v2[zMAT4_rightVec], GFA_FLOAT1K));

// Subtract both points of the line from the camera position
var int u[3]; var int v[3];
Expand Down
6 changes: 3 additions & 3 deletions _work/data/Scripts/Content/GFA/_intern/auxiliary.d
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func int GFA_ObjCheckInheritance(var int objPtr, var int classDef) {
func MEMINT_HelperClass GFA_GetActiveSpellInst(var C_Npc slf) {
if (Npc_GetActiveSpell(slf) == -1) {
// NPC does not have a spell drawn
var C_Spell ret; ret = MEM_NullToInst();
var GFA_C_Spell ret; ret = MEM_NullToInst();
MEMINT_StackPushInst(ret);
return;
};
Expand Down Expand Up @@ -169,7 +169,7 @@ func int GFA_GetActiveSpellIsScroll(var C_Npc slf) {
* Do not change the properties that make a spell eligible! This is very well thought through and works for ALL Gothic 1
* and Gothic 2 spells. For new spells, adjust THEIR properties accordingly.
*/
func int GFA_IsSpellEligible(var C_Spell spell) {
func int GFA_IsSpellEligible(var GFA_C_Spell spell) {
// Exit if the spell instance is invalid
if (!_@(spell)) {
return FALSE;
Expand Down Expand Up @@ -377,7 +377,7 @@ func string GFA_AnimateReticleByTime(var string fileName, var int fps, var int n
*/
func string GFA_AnimateReticleByPercent(var string fileName, var int percent, var int numFrames) {
// Cycle through [0, numFrames-1] by percentage
var int cycle; cycle = roundf(mulf(mkf(percent), divf(mkf(numFrames-1), FLOAT1C)));
var int cycle; cycle = roundf(mulf(mkf(percent), divf(mkf(numFrames-1), GFA_FLOAT1C)));

// Base name (without extension)
var string prefix; prefix = STR_SubStr(fileName, 0, STR_Len(fileName)-4);
Expand Down
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/_intern/ccommands.d
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func string GFA_GetShootingStats(var string args) {
// Division by zero
pAccuracy = FLOATNULL;
} else {
pAccuracy = mulf(fracf(GFA_StatsHits, GFA_StatsShots), FLOAT1C);
pAccuracy = mulf(fracf(GFA_StatsHits, GFA_StatsShots), GFA_FLOAT1C);
};
SB(STR_Prefix(toStringf(pAccuracy), 4));
SB("%");
Expand Down
21 changes: 21 additions & 0 deletions _work/data/Scripts/Content/GFA/_intern/classes.d
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,24 @@ class GFA_Reticle {
var int size;
var int color;
};


/*
* Class: Re-define the C_Spell class under a different name
*/
const int sizeof_GFA_C_Spell = 48;

class GFA_C_Spell {
var float time_per_mana;
var int damage_per_level;
var int damageType;
var int spellType;
var int canTurnDuringInvest;
var int canChangeTargetDuringInvest;
var int isMultiEffect;
var int targetCollectAlgo;
var int targetCollectType;
var int targetCollectRange;
var int targetCollectAzi;
var int targetCollectElev;
};
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/_intern/collectable.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func void GFA_RP_KeepProjectileInWorld() {

// Always keep the projectile alive, set infinite life time
if (gef(MEM_ReadInt(arrowAI+oCAIArrowBase_lifeTime_offset), FLOATNULL)) {
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, FLOATONE_NEG);
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, GFA_FLOATONE_NEG);
projectile._zCVob_visualAlpha = FLOATONE; // Fully visible
};

Expand Down
6 changes: 3 additions & 3 deletions _work/data/Scripts/Content/GFA/_intern/collision.d
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func void GFA_CC_ProjectileCollisionWithWorld() {
};

// Destroy the projectile only if it is still fast enough and check number of prior collisions
if (gf(speed, FLOAT3C)) && (collisionCounter < 2) {
if (gf(speed, GFA_FLOAT3C)) && (collisionCounter < 2) {
// For both Gothic 1 and Gothic 2
GFA_CC_ProjectileDestroy(arrowAI);

Expand Down Expand Up @@ -455,7 +455,7 @@ func void GFA_CC_ProjectileCollisionWithWorld() {
const int WATER = 1<<5;
const int SNOW = 1<<6;

if (gf(speed, FLOAT3C)) && (collisionCounter < 3) {
if (gf(speed, GFA_FLOAT3C)) && (collisionCounter < 3) {
// Play sound on first collisions and if fast enough only
if (materials & METAL) {
Snd_Play3d(projectile, GFA_COLL_SND_METAL);
Expand Down Expand Up @@ -500,7 +500,7 @@ func void GFA_CC_FadeProjectileVisibility() {
if (!(projectile.bitfield[0] & zCVob_bitfield0_physicsEnabled)) {
var int arrowAI; arrowAI = ESI; // oCAIArrow*
var int lifeTime; lifeTime = MEM_ReadInt(arrowAI+oCAIArrowBase_lifeTime_offset);
if (lifeTime == FLOATONE_NEG) {
if (lifeTime == GFA_FLOATONE_NEG) {
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, FLOATONE);
};
};
Expand Down
8 changes: 4 additions & 4 deletions _work/data/Scripts/Content/GFA/_intern/const.d
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ var int GFA_DebugBoneOBBox; // Handle of bone or

/* Numerical constants */

const int FLOATONE_NEG = -1082130432; // -1 as float
const int FLOAT1C = 1120403456; // 100 as float
const int FLOAT3C = 1133903872; // 300 as float
const int FLOAT1K = 1148846080; // 1000 as float
const int GFA_FLOATONE_NEG = -1082130432; // -1 as float
const int GFA_FLOAT1C = 1120403456; // 100 as float
const int GFA_FLOAT3C = 1133903872; // 300 as float
const int GFA_FLOAT1K = 1148846080; // 1000 as float
4 changes: 2 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/rangedAiming.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func void GFA_RangedIdle() {

// Additionally, update reticle
if (GFA_UPDATE_RET_SHOOT) {
distance = roundf(divf(mulf(distance, FLOAT1C), mkf(GFA_MAX_DIST))); // Distance scaled between [0, 100]
distance = roundf(divf(mulf(distance, GFA_FLOAT1C), mkf(GFA_MAX_DIST))); // Distance scaled between [0, 100]

// Create reticle
var int reticlePtr; reticlePtr = MEM_Alloc(sizeof_GFA_Reticle);
Expand Down Expand Up @@ -80,7 +80,7 @@ func void GFA_RangedAiming() {
// Shoot aim ray to retrieve the focus NPC and distance to it from the camera(!)
var int distance; var int target;
GFA_AimRay(GFA_MAX_DIST, TARGET_TYPE_NPCS, _@(target), 0, _@(distance), 0);
distance = roundf(divf(mulf(distance, FLOAT1C), mkf(GFA_MAX_DIST))); // Distance scaled between [0, 100]
distance = roundf(divf(mulf(distance, GFA_FLOAT1C), mkf(GFA_MAX_DIST))); // Distance scaled between [0, 100]

// Create reticle
var int reticlePtr; reticlePtr = MEM_Alloc(sizeof_GFA_Reticle);
Expand Down
36 changes: 18 additions & 18 deletions _work/data/Scripts/Content/GFA/_intern/rangedShooting.d
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func int GFA_GetInitialBaseDamage_(var int baseDamage, var int damageType, var i

// Scale distance between [0, 100] for [RANGED_CHANCE_MINDIST, RANGED_CHANCE_MAXDIST], see AI_Constants.d
// For readability: 100*(aimingDistance-RANGED_CHANCE_MINDIST)/(RANGED_CHANCE_MAXDIST-RANGED_CHANCE_MINDIST)
aimingDistance = roundf(divf(mulf(FLOAT1C, subf(aimingDistance, castToIntf(GFA_RANGED_CHANCE_MINDIST))),
aimingDistance = roundf(divf(mulf(GFA_FLOAT1C, subf(aimingDistance, castToIntf(GFA_RANGED_CHANCE_MINDIST))),
subf(castToIntf(GFA_RANGED_CHANCE_MAXDIST), castToIntf(GFA_RANGED_CHANCE_MINDIST))));
// Clip to range [0, 100]
if (aimingDistance > 100) {
Expand Down Expand Up @@ -241,7 +241,7 @@ func void GFA_SetupProjectile() {
// -------------------------------- + 1
// -100
var int maxArea;
maxArea = addf(divf(mulf(subf(hitArea, FLOATONE), mkf(100-accuracy)), FLOAT1C), FLOATONE);
maxArea = addf(divf(mulf(subf(hitArea, FLOATONE), mkf(100-accuracy)), GFA_FLOAT1C), FLOATONE);

// Convert back to a radius
rmax = sqrtf(divf(maxArea, PI));
Expand All @@ -257,7 +257,7 @@ func void GFA_SetupProjectile() {
};

// r_MinMax works with integers: scale up
var int rmaxI; rmaxI = roundf(mulf(rmax, FLOAT1K));
var int rmaxI; rmaxI = roundf(mulf(rmax, GFA_FLOAT1K));

// Azimuth scatter (horizontal deviation from a perfect shot in degrees)
var int angleX; angleX = fracf(r_Max(rmaxI), 1000); // Here the 1000 are scaled down again
Expand All @@ -273,7 +273,7 @@ func void GFA_SetupProjectile() {
};

// r_MinMax works with integers: scale up
var int rminI; rminI = roundf(mulf(rmin, FLOAT1K));
var int rminI; rminI = roundf(mulf(rmin, GFA_FLOAT1K));

// Adjust rmax
if (lf(angleX, rmax)) {
Expand All @@ -283,7 +283,7 @@ func void GFA_SetupProjectile() {
};

// r_MinMax works with integers: scale up
rmaxI = roundf(mulf(rmax, FLOAT1K));
rmaxI = roundf(mulf(rmax, GFA_FLOAT1K));

// Elevation scatter (vertical deviation from a perfect shot in degrees)
var int angleY; angleY = fracf(r_MinMax(rminI, rmaxI), 1000); // Here the 1000 are scaled down again
Expand Down Expand Up @@ -427,7 +427,7 @@ func void GFA_SetupProjectile() {
var int s; s = SB_New();

SB(" aiming distance: ");
SB(STR_Prefix(toStringf(divf(distPlayer, FLOAT1C)), 4));
SB(STR_Prefix(toStringf(divf(distPlayer, GFA_FLOAT1C)), 4));
SB("m");
MEM_Info(SB_ToString());
SB_Clear();
Expand Down Expand Up @@ -520,26 +520,26 @@ func void GFA_EnableProjectileGravity() {
EAX = TRUE;
} else {
// No (collectable feature). Reset life time to -1
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, FLOATONE_NEG);
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, GFA_FLOATONE_NEG);
EAX = FALSE;
};
} else if (!(projectile.bitfield[0] & zCVob_bitfield0_physicsEnabled)) {
// Stopped moving: Decrease visibility?
if (GFA_Flags & GFA_REUSE_PROJECTILES) {
// No (collectable feature). Reset life time to -1
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, FLOATONE_NEG);
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, GFA_FLOATONE_NEG);
EAX = FALSE;
} else {
// Yes (no collectable feature). Reset life time to 1
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, FLOATONE);
// Decrease life time and visibility (default behavior)
EAX = TRUE;
};
} else if (lf(lifeTime, FLOATONE_NEG)) {
} else if (lf(lifeTime, GFA_FLOATONE_NEG)) {
// lifeTime < -1: Continue counting flight time until gravity drop
lifeTime = addf(lifeTime, MEM_Timer.frameTimeFloat);
if (gef(lifeTime, FLOATONE_NEG)) {
lifeTime = FLOATONE_NEG;
if (gef(lifeTime, GFA_FLOATONE_NEG)) {
lifeTime = GFA_FLOATONE_NEG;
// Apply gravity. Reset life time to -1
var int rigidBody; rigidBody = projectile.rigidBody; // zCRigidBody*
if (rigidBody) {
Expand Down Expand Up @@ -573,9 +573,9 @@ func void GFA_ResetProjectileGravity() {

// Reset projectile gravity (zCRigidBody.gravity) after collision (oCAIArrow.collision) to default
MEM_WriteInt(rigidBody+zCRigidBody_gravity_offset, FLOATONE);
if (lf(MEM_ReadInt(arrowAI+oCAIArrowBase_lifeTime_offset), FLOATONE_NEG)) {
if (lf(MEM_ReadInt(arrowAI+oCAIArrowBase_lifeTime_offset), GFA_FLOATONE_NEG)) {
// Reset gravity timer
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, FLOATONE_NEG);
MEM_WriteInt(arrowAI+oCAIArrowBase_lifeTime_offset, GFA_FLOATONE_NEG);
};

// Remove trail strip FX
Expand Down Expand Up @@ -627,7 +627,7 @@ func void GFA_OverwriteHitChance() {
} else {
// If accuracy/scattering is enabled, all shots that hit the target are always positive hits
hit = TRUE;
MEM_WriteInt(hitChancePtr, GFA_SwitchExe(FLOAT1C, FLOAT1C, 100, 100)); // Overwrite to hit always
MEM_WriteInt(hitChancePtr, GFA_SwitchExe(GFA_FLOAT1C, GFA_FLOAT1C, 100, 100)); // Overwrite to hit always
};

// Update the shooting statistics
Expand Down Expand Up @@ -680,12 +680,12 @@ func int GFA_RefinedProjectileCollisionCheck(var int vobPtr, var int arrowAI) {
MEM_CopyBytes(vobPtr+zCVob_bbox3D_offset, _@(bbox), sizeof_zTBBox3D);
var int dist; // Distance from bbox.mins to bbox.max
dist = sqrtf(addf(addf(sqrf(subf(bbox[3], bbox[0])), sqrf(subf(bbox[4], bbox[1]))), sqrf(subf(bbox[5], bbox[2]))));
dist = addf(dist, FLOAT3C); // Add the 3m-shift of the start (see below)
dist = addf(dist, GFA_FLOAT3C); // Add the 3m-shift of the start (see below)

// Adjust length of ray (large models have huge bounding boxes)
GFA_CollTrj[0] = subf(GFA_CollTrj[0], mulf(GFA_CollTrj[3], FLOAT3C)); // Start 3m behind projectile
GFA_CollTrj[1] = subf(GFA_CollTrj[1], mulf(GFA_CollTrj[4], FLOAT3C));
GFA_CollTrj[2] = subf(GFA_CollTrj[2], mulf(GFA_CollTrj[5], FLOAT3C));
GFA_CollTrj[0] = subf(GFA_CollTrj[0], mulf(GFA_CollTrj[3], GFA_FLOAT3C)); // Start 3m behind projectile
GFA_CollTrj[1] = subf(GFA_CollTrj[1], mulf(GFA_CollTrj[4], GFA_FLOAT3C));
GFA_CollTrj[2] = subf(GFA_CollTrj[2], mulf(GFA_CollTrj[5], GFA_FLOAT3C));
GFA_CollTrj[3] = mulf(GFA_CollTrj[3], dist); // Trace trajectory from the edge through the bounding box
GFA_CollTrj[4] = mulf(GFA_CollTrj[4], dist);
GFA_CollTrj[5] = mulf(GFA_CollTrj[5], dist);
Expand Down
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/_intern/reticle.d
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func void GFA_GetRangedReticle_(var int target, var int distance, var int return
* Wrapper function for the config function GFA_GetSpellReticle(). It is called from GFA_SpellAiming().
* This function supplies a lot of spell properties.
*/
func void GFA_GetSpellReticle_(var int target, var C_Spell spellInst, var int distance, var int returnPtr) {
func void GFA_GetSpellReticle_(var int target, var GFA_C_Spell spellInst, var int distance, var int returnPtr) {
// Define spell properties
var int spellID; spellID = Npc_GetActiveSpell(hero);
var int spellLvl; spellLvl = Npc_GetActiveSpellLevel(hero);
Expand Down
8 changes: 4 additions & 4 deletions _work/data/Scripts/Content/GFA/_intern/spell.d
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func void GFA_SetupSpell() {
};

// Determine focus type. For TARGET_COLLECT_NONE no focus will be collect, but only an intersection with the world
var C_Spell spell; spell = _^(spellOC+oCSpell_C_Spell_offset);
var GFA_C_Spell spell; spell = _^(spellOC+oCSpell_C_Spell_offset);
var int focusType;
if (spell.targetCollectAlgo == TARGET_COLLECT_NONE) {
focusType = 0;
Expand All @@ -55,7 +55,7 @@ func void GFA_SetupSpell() {
* but exits right away if the active spell does not support free aiming or if the player is not currently aiming.
*/
func void GFA_SpellAiming() {
var C_Spell spell; spell = GFA_GetActiveSpellInst(hero);
var GFA_C_Spell spell; spell = GFA_GetActiveSpellInst(hero);
var int aniCtrlPtr; aniCtrlPtr = ECX;

// Only show reticle for spells that support free aiming and during aiming (Gothic 1 controls)
Expand Down Expand Up @@ -117,7 +117,7 @@ func void GFA_SpellAiming() {

// Shoot aim ray, to retrieve the distance to an intersection and a possible target
GFA_AimRay(spell.targetCollectRange, focusType, _@(target), 0, _@(distance), 0);
distance = roundf(divf(mulf(distance, FLOAT1C), mkf(spell.targetCollectRange))); // Distance scaled to [0, 100]
distance = roundf(divf(mulf(distance, GFA_FLOAT1C), mkf(spell.targetCollectRange))); // Distance scaled [0, 100]

} else {
// No focus collection
Expand Down Expand Up @@ -316,7 +316,7 @@ func void GFA_ResetSpell() {
return;
};

var C_Spell spell; spell = GFA_GetActiveSpellInst(hero);
var GFA_C_Spell spell; spell = GFA_GetActiveSpellInst(hero);
if (!_@(spell)) {
return;
};
Expand Down
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/config/reticle.d
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func void GFA_GetRangedReticle(var C_Npc target, var C_Item weapon, var int tale
* Here, for example, the size is scaled by aiming distance. As indicated by the in-line comments, basing the size (or
* color) on the any provided spell properties is easily possible.
*/
func void GFA_GetSpellReticle(var C_Npc target, var int spellID, var C_Spell spellInst, var int spellLevel,
func void GFA_GetSpellReticle(var C_Npc target, var int spellID, var GFA_C_Spell spellInst, var int spellLevel,
var int isScroll, var int manaInvested, var int dist, var int returnPtr) {
// Get reticle instance from call-by-reference argument
var GFA_Reticle reticle; reticle = _^(returnPtr);
Expand Down

0 comments on commit 7698c3c

Please sign in to comment.