Skip to content

Commit

Permalink
Fix #137 add accessible shooting statisitcs
Browse files Browse the repository at this point in the history
  • Loading branch information
szapp committed Aug 9, 2017
1 parent 99c127b commit 8446afb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 9 deletions.
44 changes: 42 additions & 2 deletions _work/data/Scripts/Content/freeAim/_intern/ccommands.d
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,48 @@ func string GFA_DebugTraceRay(var string command) {
};


/*
* Console function to show GFA shooting statistics. This function is registered as console command.
* When entered in the console, the current shooting statistics are displayed as the console output.
*/
func string GFA_GetShootingStats(var string command) {
if (!GFA_RANGED) {
return "Shooting statistics not available. (Requires free aiming for ranged weapons)";
};

var int s; s = SB_New();
SB("Total shots taken: ");
SBi(GFA_StatsShots);
SBc(13); SBc(10);

SB("Shots on target: ");
SBi(GFA_StatsHits);
SBc(13); SBc(10);

SB("Personal accuracy: ");
var int pAccuracy;
if (!GFA_StatsShots) {
// Division by zero
pAccuracy = FLOATNULL;
} else {
pAccuracy = mulf(fracf(GFA_StatsHits, GFA_StatsShots), FLOAT1C);
};
SB(STR_Prefix(toStringf(pAccuracy), 4));
SB("%");

if (GFA_CRITICALHITS) {
SBc(13); SBc(10);
SB("Critical hits: ");
SBi(GFA_StatsCriticalHits);
};

var string ret; ret = SB_ToString();
SB_Destroy();

return ret;
};


/*
* Console function to show GFA version. This function is registered as console command.
* When entered in the console, the current GFA version is displayed as the console output.
Expand Down Expand Up @@ -92,7 +134,6 @@ func string GFA_GetLicense(var string command) {
SBc(13); SBc(10);

SB("For more details see <http://opensource.org/licenses/MIT>.");
SBc(13); SBc(10);

var string ret; ret = SB_ToString();
SB_Destroy();
Expand Down Expand Up @@ -139,7 +180,6 @@ func string GFA_GetInfo(var string command) {

SB("Criticial hit detection: ");
SB(MEM_ReadStatStringArr(onOff, GFA_CRITICALHITS));
SBc(13); SBc(10);

var string ret; ret = SB_ToString();
SB_Destroy();
Expand Down
5 changes: 5 additions & 0 deletions _work/data/Scripts/Content/freeAim/_intern/collision.d
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ func void GFA_CC_ProjectileCollisionWithNpc() {
};
};

// Update shooting statistics
if (GFA_RANGED) {
GFA_StatsHits += hit;
};

// The hit chance percentage is either determined by skill and distance (default Gothic hit chance) or is always
// 100%, if free aiming is enabled and the accuracy is defined by the scattering (GFA_TRUE_HITCHANCE == TRUE).
var int hitChancePtr; hitChancePtr = MEMINT_SwitchG1G2(/*esp+3Ch-28h*/ ESP+20, /*esp+1ACh-194h*/ ESP+24);
Expand Down
17 changes: 10 additions & 7 deletions _work/data/Scripts/Content/freeAim/_intern/const.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,26 @@ const int GFA_MAX_DIST = 5000; // Distance for shoo
var int GFA_AimRayInterval; // Perform trace ray every x ms (change in ini-file)
var int GFA_AimRayPrevCalcTime; // Time of last trace ray calculation


const float GFA_SCATTER_HIT = 2.6; // (Visual angle)/2 within which everything is a hit
const float GFA_SCATTER_MISS = 3.3; // (Visual angle)/2 outside which everything is a miss
const float GFA_SCATTER_MAX = 5.0; // (Visual angle)/2 of maximum scatter (all in degrees)

const float GFA_MAX_TURN_RATE_G1 = 2.0; // Gothic 1 has a maximum turn rate (engine default: 2.0)

var int GFA_Recoil; // Amount of vertical mouse movement on recoil

const int FLOAT1C = 1120403456; // 100 as float
const int FLOAT3C = 1133903872; // 300 as float
const int FLOAT1K = 1148846080; // 1000 as float
var int GFA_LastHitCritical; // Was the last hit critical (will be reset immediately)

var int GFA_StatsShots; // Shooting statistics: Count total number of shots taken
var int GFA_StatsHits; // Shooting statistics: Count positive hits on target
var int GFA_StatsCriticalHits; // Shooting statistics: Count number of critical hits

const float GFA_MAX_TURN_RATE_G1 = 2.0; // Gothic 1 has a maximum turn rate (engine default: 2.0)

const int GFA_ACTIVE = 0; // Status indicator of free aiming
const int GFA_INIT_HITREG = 0; // Check if hit registration hook was initialized

var int GFA_LastHitCritical; // Was the last hit critical (will be reset immediately)
const int FLOAT1C = 1120403456; // 100 as float
const int FLOAT3C = 1133903872; // 300 as float
const int FLOAT1K = 1148846080; // 1000 as float

var int GFA_DebugWSBBox[6]; // Weakspot bounding box for debug visualization
var int GFA_DebugWSTrj[6]; // Projectile trajectory for debug visualization
Expand Down
1 change: 1 addition & 0 deletions _work/data/Scripts/Content/freeAim/_intern/criticalHit.d
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func void GFA_CH_DetectCriticalHit() {
GFA_CH_StartCriticalHitEvent_(targetNpc); // Use this function to add an event, e.g. a print or a sound
MEM_WriteInt(damagePtr, weakspot.bDmg); // Base damage not final damage
GFA_LastHitCritical = TRUE; // Used for GFA_CC_SetDamageBehavior(), will be reset to FALSE immediately
GFA_StatsCriticalHits += 1; // Update shooting statistics
};
MEM_Free(weakspotPtr);
};
Expand Down
1 change: 1 addition & 0 deletions _work/data/Scripts/Content/freeAim/_intern/init.d
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func int GFA_InitOnce() {
CC_Register(GFA_GetVersion, "GFA version", "print GFA version info");
CC_Register(GFA_GetLicense, "GFA license", "print GFA license info");
CC_Register(GFA_GetInfo, "GFA info", "print GFA config info");
CC_Register(GFA_GetShootingStats, "GFA stats", "print shooting statistics");
if (GFA_DEBUG_CONSOLE) {
CC_Register(GFA_DebugPrint, "debug GFA zSpy", "turn on GFA debug information in zSpy");
};
Expand Down
3 changes: 3 additions & 0 deletions _work/data/Scripts/Content/freeAim/_intern/rangedShooting.d
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ func void GFA_SetupProjectile() {
var int vobPtr; vobPtr = GFA_SetupAimVob(_@(pos));
MEM_WriteInt(ESP+12, vobPtr); // Overwrite the third argument (target vob) passed to oCAIArrow::SetupAIVob

// Update the shooting statistics
GFA_StatsShots += 1;


if (GFA_DEBUG_PRINT) {
MEM_Info("GFA_SetupProjectile:");
Expand Down

0 comments on commit 8446afb

Please sign in to comment.