Skip to content

Commit

Permalink
Change ini settings to constants, read once only
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Dec 9, 2018
1 parent 439b2bf commit 234caa7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
4 changes: 2 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/activate.d
Expand Up @@ -37,7 +37,7 @@ func void GFA_UpdateSettings(var int on) {
if (on) {
// Turn free aiming on
if (GFA_Flags & GFA_RANGED) {
if (GFA_NoAimNoFocus) {
if (GFA_NO_AIM_NO_FOCUS) {
// Set stricter focus collection
Focus_Ranged.npc_azi = castFromIntf(castToIntf(GFA_FOCUS_FAR_NPC)); // Cast twice for, Deadalus floats
};
Expand Down Expand Up @@ -226,7 +226,7 @@ func void GFA_IsActive() {
return;
};
} else {
if (GFA_NoAimNoFocus) {
if (GFA_NO_AIM_NO_FOCUS) {
// Spell uses free aiming: Set stricter focus collection
Focus_Magic.npc_azi = castFromIntf(castToIntf(GFA_FOCUS_SPL_NPC)); // Cast twice for Deadalus floats
};
Expand Down
4 changes: 2 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/aimRay.d
Expand Up @@ -117,9 +117,9 @@ func int GFA_AimRayHead(var int npcPtr, var int fromPosPtr, var int dirPosPtr, v
*/
func int GFA_AimRay(var int distance, var int focusType, var int vobPtr, var int posPtr, var int distPtr,
var int trueDistPtr) {
// Only run full trace ray machinery every so often (see GFA_AimRayInterval) to allow weaker machines to run this
// Only run full trace ray machinery every so often (see GFA_RAY_INTERVAL) to allow weaker machines to run this
var int curTime; curTime = MEM_Timer.totalTime; // Get current time
if (curTime-GFA_AimRayPrevCalcTime >= GFA_AimRayInterval) { // If the interval has passed, recompute trace ray
if (curTime-GFA_AimRayPrevCalcTime >= GFA_RAY_INTERVAL) { // If the interval has passed, recompute trace ray
// Update time of previous calculation
GFA_AimRayPrevCalcTime = curTime;

Expand Down
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/_intern/ccommands.d
Expand Up @@ -247,7 +247,7 @@ func string GFA_GetInfo(var string _) {
SB(MEM_ReadStatStringArr(onOff, GFA_STRAFING > 0));

SB(". Focus update every ");
SBi(GFA_AimRayInterval);
SBi(GFA_RAY_INTERVAL);
SB(" ms");
};
SBc(13); SBc(10);
Expand Down
4 changes: 2 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/const.d
Expand Up @@ -61,9 +61,9 @@ const float GFA_MAX_TURN_RATE_G1 = 2.0; // Gothic 1 has a ma

const int GFA_MIN_AIM_DIST = 140; // Minimum targeting distance. Fixes vertical shooting bug
const int GFA_MAX_DIST = 5000; // Distance for shooting/reticle. Do not change
var int GFA_AimRayInterval; // Perform trace ray every x ms (change in ini-file)
var int GFA_NO_AIM_NO_FOCUS; // Remove focus when not aiming (change in ini-file)
var int GFA_RAY_INTERVAL; // Perform trace ray every x ms (change in ini-file)
var int GFA_AimRayPrevCalcTime; // Time of last trace ray calculation
var int GFA_NoAimNoFocus; // Remove focus when not aiming (change in ini-file)

const int GFA_RETICLE_MIN_SIZE = 32; // Reticle size in pixels (at its smallest)
const int GFA_RETICLE_MAX_SIZE = 64; // Reticle size in pixels (at its biggest)
Expand Down
4 changes: 2 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/controls.d
Expand Up @@ -388,7 +388,7 @@ func void GFA_TreatBodyStates() {
/*
* Prevent focus collection while jumping and falling during free aiming fight modes. This function hooks
* oCAIHuman::PC_ActionMove() at an offset at which the fight modes are not reached. This happens during certain body
* states. At that offset, the focus collection remains normal, which will counteract the idea of GFA_NoAimNoFocus.
* states. At that offset, the focus collection remains normal, which will counteract the idea of GFA_NO_AIM_NO_FOCUS.
* This only happens for Gothic 2.
*/
func void GFA_PreventFocusCollectionBodyStates() {
Expand All @@ -399,7 +399,7 @@ func void GFA_PreventFocusCollectionBodyStates() {
var oCNpc her; her = getPlayerInst();
if ((her.fmode == FMODE_FAR) || (her.fmode == FMODE_FAR+1)) && (GFA_Flags & GFA_RANGED) // Bow or crossbow
|| ((her.fmode == FMODE_MAGIC) && (GFA_Flags & GFA_SPELLS)) { // Spell
if (GFA_NoAimNoFocus) || ((GFA_ACTIVE_CTRL_SCHEME == 2) && (her.fmode == FMODE_MAGIC)) {
if (GFA_NO_AIM_NO_FOCUS) || ((GFA_ACTIVE_CTRL_SCHEME == 2) && (her.fmode == FMODE_MAGIC)) {
GFA_SetFocusAndTarget(0);
};

Expand Down
33 changes: 15 additions & 18 deletions _work/data/Scripts/Content/GFA/_intern/init.d
Expand Up @@ -147,20 +147,35 @@ func void GFA_InitFeatureFreeAiming() {
MEM_SetGothOpt("GFA", "freeAimingEnabled", "1");
};

// Retrieve trace ray interval: Recalculate trace ray intersection every x ms
if (!MEM_GothOptExists("GFA", "focusUpdateIntervalMS")) {
// Add INI-entry, if not set (set to instantaneous=0ms by default)
MEM_SetGothOpt("GFA", "focusUpdateIntervalMS", "0");
};
GFA_RAY_INTERVAL = STR_ToInt(MEM_GetGothOpt("GFA", "focusUpdateIntervalMS"));
if (GFA_RAY_INTERVAL > 500) {
GFA_RAY_INTERVAL = 500;
MEM_SetGothOpt("GFA", "focusUpdateIntervalMS", IntToString(GFA_RAY_INTERVAL));
};

// Remove focus when not aiming: Prevent using bow/spell as enemy detector
if (!MEM_GothOptExists("GFA", "showFocusWhenNotAiming")) {
// Add INI-entry, if not set (disable by default)
MEM_SetGothOpt("GFA", "showFocusWhenNotAiming", "0");
};
GFA_NO_AIM_NO_FOCUS = !STR_ToInt(MEM_GetGothOpt("GFA", "showFocusWhenNotAiming"));

// Set the reticle size in pixels
if (!MEM_GothOptExists("GFA", "reticleSizePx")) {
// Add INI-entry, if not set
MEM_SetGothOpt("GFA", "reticleSizePx", IntToString(GFA_RETICLE_MAX_SIZE));
};
GFA_RETICLE_MAX_SIZE = STR_ToInt(MEM_GetGothOpt("GFA", "reticleSizePx"));
if (GFA_RETICLE_MAX_SIZE < GFA_RETICLE_MIN_SIZE) {
GFA_RETICLE_MAX_SIZE = GFA_RETICLE_MIN_SIZE;
MEM_SetGothOpt("GFA", "reticleSizePx", IntToString(GFA_RETICLE_MAX_SIZE));
};
GFA_RETICLE_MIN_SIZE = GFA_RETICLE_MAX_SIZE/2;

if (GOTHIC_BASE_VERSION == 2) {
if (GFA_Flags & GFA_RANGED) {
Expand Down Expand Up @@ -323,24 +338,6 @@ func int GFA_InitOnce() {
* GFA_Init().
*/
func void GFA_InitAlways() {
// Retrieve trace ray interval: Recalculate trace ray intersection every x ms
GFA_AimRayInterval = STR_ToInt(MEM_GetGothOpt("GFA", "focusUpdateIntervalMS"));
if (GFA_AimRayInterval > 500) {
GFA_AimRayInterval = 500;
MEM_SetGothOpt("GFA", "focusUpdateIntervalMS", IntToString(GFA_AimRayInterval));
};

// Remove focus when not aiming: Prevent using bow/spell as enemy detector
GFA_NoAimNoFocus = !STR_ToInt(MEM_GetGothOpt("GFA", "showFocusWhenNotAiming"));

// Set the reticle size in pixels
GFA_RETICLE_MAX_SIZE = STR_ToInt(MEM_GetGothOpt("GFA", "reticleSizePx"));
if (GFA_RETICLE_MAX_SIZE < GFA_RETICLE_MIN_SIZE) {
GFA_RETICLE_MAX_SIZE = GFA_RETICLE_MIN_SIZE;
MEM_SetGothOpt("GFA", "reticleSizePx", IntToString(GFA_RETICLE_MAX_SIZE));
};
GFA_RETICLE_MIN_SIZE = GFA_RETICLE_MAX_SIZE/2;

// Reset/reinitialize free aiming settings every time to prevent crashes
if (GFA_Flags & GFA_RANGED) || (GFA_Flags & GFA_SPELLS) {
// On level change, Gothic does not maintain the focus instances (see Focus.d), nor does it reinitialize them.
Expand Down
4 changes: 2 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/rangedAiming.d
Expand Up @@ -61,7 +61,7 @@ func void GFA_RangedIdle() {
// In bow mode but not pressing down the aiming key
GFA_RemoveReticle();

if (GFA_NoAimNoFocus) {
if (GFA_NO_AIM_NO_FOCUS) {
GFA_SetFocusAndTarget(0);
};

Expand All @@ -81,7 +81,7 @@ func void GFA_RangedAiming() {
return;
} else if (GFA_ACTIVE < FMODE_FAR) {
GFA_RemoveReticle();
if (GFA_NoAimNoFocus) {
if (GFA_NO_AIM_NO_FOCUS) {
GFA_SetFocusAndTarget(0);
};
return;
Expand Down
2 changes: 1 addition & 1 deletion _work/data/Scripts/Content/GFA/_intern/spell.d
Expand Up @@ -81,7 +81,7 @@ func void GFA_SpellAiming() {

if (GFA_IsSpellEligible(spell) & GFA_ACT_FREEAIM) {
// Remove focus and target
if (GFA_NoAimNoFocus) {
if (GFA_NO_AIM_NO_FOCUS) {
GFA_SetFocusAndTarget(0);
};

Expand Down

0 comments on commit 234caa7

Please sign in to comment.