Skip to content

Commit

Permalink
Fix #195 change no-aim-no-focus to INI setting
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Dec 4, 2018
1 parent 4eb17bc commit 9e94db5
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
12 changes: 8 additions & 4 deletions _work/data/Scripts/Content/GFA/_intern/activate.d
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ func void GFA_UpdateSettings(var int on) {
if (on) {
// Turn free aiming on
if (GFA_Flags & GFA_RANGED) {
// Set stricter focus collection
Focus_Ranged.npc_azi = castFromIntf(castToIntf(GFA_FOCUS_FAR_NPC)); // Cast twice, Deadalus floats are dumb
if (GFA_NoAimNoFocus) {
// Set stricter focus collection
Focus_Ranged.npc_azi = castFromIntf(castToIntf(GFA_FOCUS_FAR_NPC)); // Cast twice for, Deadalus floats
};

// New camera mode (does not affect Gothic 1)
MEM_WriteString(zString_CamModRanged, STR_Upper(GFA_CAMERA));
Expand Down Expand Up @@ -224,8 +226,10 @@ func void GFA_IsActive() {
return;
};
} else {
// Spell uses free aiming: Set stricter focus collection
Focus_Magic.npc_azi = castFromIntf(castToIntf(GFA_FOCUS_SPL_NPC)); // Cast twice, Deadalus floats are dumb
if (GFA_NoAimNoFocus) {
// Spell uses free aiming: Set stricter focus collection
Focus_Magic.npc_azi = castFromIntf(castToIntf(GFA_FOCUS_SPL_NPC)); // Cast twice for Deadalus floats
};
Focus_Magic.item_prio = GFA_FOCUS_SPL_ITM;
};

Expand Down
1 change: 1 addition & 0 deletions _work/data/Scripts/Content/GFA/_intern/const.d
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const int GFA_MIN_AIM_DIST = 140; // Minimum targeting
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_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 = 200; // Smallest reticle size in virtual coordinates
const int GFA_RETICLE_MAX_SIZE = 400; // Biggest reticle size in virtual coordinates
Expand Down
6 changes: 4 additions & 2 deletions _work/data/Scripts/Content/GFA/_intern/controls.d
Original file line number Diff line number Diff line change
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_NO_AIM_NO_FOCUS.
* states. At that offset, the focus collection remains normal, which will counteract the idea of GFA_NoAimNoFocus.
* This only happens for Gothic 2.
*/
func void GFA_PreventFocusCollectionBodyStates() {
Expand All @@ -399,7 +399,9 @@ 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
GFA_SetFocusAndTarget(0);
if (GFA_NoAimNoFocus) || ((GFA_ACTIVE_CTRL_SCHEME == 2) && (her.fmode == FMODE_MAGIC)) {
GFA_SetFocusAndTarget(0);
};

// With Gothic 2 controls, the reticle is still visible
if (GFA_ACTIVE_CTRL_SCHEME == 2) {
Expand Down
10 changes: 9 additions & 1 deletion _work/data/Scripts/Content/GFA/_intern/init.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func void GFA_InitFeatureFreeAiming() {
HookEngineF(oCAniCtrl_Human__SearchStandAni_walkmode, 6, GFA_FixStandingBodyState); // Fix bug with wrong body state
HookEngineF(oCNpc__SetWeaponMode2_walkmode, 6, GFA_FixStandingBodyState); // Fix bug with wrong body state
// Prevent focus collection during jumping and falling (necessary for Gothic 2 only)
if (GOTHIC_BASE_VERSION == 2) && (GFA_NO_AIM_NO_FOCUS) {
if (GOTHIC_BASE_VERSION == 2) {
HookEngineF(oCAIHuman__PC_ActionMove_bodyState, 6, GFA_PreventFocusCollectionBodyStates);
};

Expand Down Expand Up @@ -152,6 +152,11 @@ func void GFA_InitFeatureFreeAiming() {
MEM_SetGothOpt("GFA", "focusUpdateIntervalMS", "0");
};

if (!MEM_GothOptExists("GFA", "showFocusWhenNotAiming")) {
// Add INI-entry, if not set (disable by default)
MEM_SetGothOpt("GFA", "showFocusWhenNotAiming", "0");
};

if (GOTHIC_BASE_VERSION == 2) {
if (GFA_Flags & GFA_RANGED) {
if (!MEM_GothOptExists("GFA", "overwriteControlSchemeRanged")) {
Expand Down Expand Up @@ -320,6 +325,9 @@ func void GFA_InitAlways() {
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"));

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func void GFA_RangedIdle() {
// In bow mode but not pressing down the aiming key
GFA_RemoveReticle();

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

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

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

Expand Down
1 change: 0 additions & 1 deletion _work/data/Scripts/Content/GFA/config/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const int GFA_MAX_RECOIL = 15; // Visual angle (degrees) of maximum

// GFA_RANGED and/or GFA_SPELLS
const int GFA_STRAFING = TRUE; // Enable/disable movement while aiming (for both ranged and spell combat)
const int GFA_NO_AIM_NO_FOCUS = TRUE; // Remove focus when not aiming: Prevent using bow/spell as enemy detector
const float GFA_ROTATION_SCALE = 0.16; // Turn rate while aiming (changes Gothic 1 controls only)
const int GFA_CAMERA_X_SHIFT = FALSE; // Set to true, if camera is set to shoulderview (not recommended)
const int GFA_DEBUG_CONSOLE = TRUE; // Enable console commands (debugging). Disable in final mod
Expand Down

0 comments on commit 9e94db5

Please sign in to comment.