
|
|
Author |
Message |
insurrectionman
DieHard Mutant


Joined: 07 May 2005
Last Visit: 03 Nov 2019
Topics: 87
Posts: 758
Location: Wisconsin

|
Posted: Thu Aug 24, 2017 7:00 pm
Subject: [Tutorial] Weapon accuracy stat on Level screen
[ IP : Logged ]
|

 
|
|
Hi all,
I've come up with some interesting features that might be fun to have in a mod. This one being Weapon accuracy at the end. This doesn't accumulate at the end of the episode, it just is visible for that one level, and then it's gone. But there is always the option for a little extra to make that show on the Victory screen. Also give the player a bonus for 100% accuracy, etc etc. I'll just say this is a stepping stone for more ideas.
Let's get started, open WL_DEF.H and find the "gamestate structure", and add this at the end:
::: CODE :::
int32_t TimeCount;
int32_t killx,killy;
boolean victoryflag; // set during victory animations
short weaponShotsHit, weaponShotsFired;
} gametype;
These will get the values stored on how many shots you've fired, and how many shots hit enemies.
Next, open WL_AGENT.CPP, and find the GunAttack function, adding this:
::: CODE :::
madenoise = true;
gamestate.weaponShotsFired++;
//
// find potential targets
//
viewdist = 0x7fffffffl;
closest = NULL;
and a little farther down:
::: CODE :::
damage = US_RndT() / 6;
}
gamestate.weaponShotsHit++;
DamageActor (closest,damage);
}
And if you choose to also count knife hits/total, you can add these 2 lines to the KnifeAttack function:
::: CODE :::
void KnifeAttack (objtype *ob)
{
objtype *check,*closest;
int32_t dist;
SD_PlaySound (ATKKNIFESND);
gamestate.weaponShotsFired++;
// actually fire
dist = 0x7fffffff;
closest = NULL;
for (check=ob->next; check; check=check->next)
{
if ( (check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE)
&& abs(check->viewx-centerx) < shootdelta)
{
if (check->transx < dist)
{
dist = check->transx;
closest = check;
}
}
}
if (!closest || dist > 0x18000l)
{
// missed
return;
}
gamestate.weaponShotsHit++;
// hit something
DamageActor (closest,US_RndT() >> 4);
}
Now we want to set the values to 0 on a NewGame, so we go to WL_MAIN.CPP, the NewGame function:
::: CODE :::
void NewGame (int difficulty,int episode)
{
memset (&gamestate,0,sizeof(gamestate));
gamestate.difficulty = difficulty;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.health = 100;
gamestate.ammo = STARTAMMO;
gamestate.lives = 3;
gamestate.nextextra = EXTRAPOINTS;
gamestate.episode=episode;
gamestate.weaponShotsFired =
gamestate.weaponShotsHit = 0;
startgame = true;
}
Now, it needs to be reset when the player dies, so open WL_GAME.CPP and go to the Died function:
::: CODE :::
if (gamestate.lives > -1)
{
gamestate.health = 100;
gamestate.weapon = gamestate.bestweapon
= gamestate.chosenweapon = wp_pistol;
gamestate.ammo = STARTAMMO;
gamestate.keys = 0;
pwallstate = pwallpos = 0;
gamestate.attackframe = gamestate.attackcount =
gamestate.weaponframe = 0;
gamestate.weaponShotsFired =
gamestate.weaponShotsHit = 0;
And down to the GameLoop function, we want to reset the counts every level:
::: CODE :::
gamestate.oldscore = gamestate.score;
gamestate.weaponShotsFired =
gamestate.weaponShotsHit = 0;
#ifndef SPEAR
//
// COMING BACK FROM SECRET LEVEL
//
Now that all of the logic to record the values is done, we can go to WL_INTER.CPP to the LevelCompleted function, and add in how we will see the stats. I just replaced the "Floor X Completed" text for demonstration purposes, so I'm sure you'll find a way to make it fit on the screen.
::: CODE :::
#ifndef SPEAR
if (mapon < 8)
#else
if (mapon != 4 && mapon != 9 && mapon != 15 && mapon < 17)
#endif
{
#ifndef JAPAN
#ifdef SPANISH
Write (14, 2, "piso\ncompletado");
#else
//Write (14, 2, "floor\ncompleted");
Write (14,2, "Accuracy %");
char accuracyStr[3];
int accuracy = ((float)gamestate.weaponShotsHit / gamestate.weaponShotsFired) * 100;
itoa(accuracy, accuracyStr, 10);
int offset = 38 - (int) strlen(accuracyStr) * 2;
Write(offset,2,accuracyStr);
#endif
Write (14, 7, STR_BONUS " 0");
Write (16, 10, STR_TIME);
Write (16, 12, STR_PAR);
#ifdef SPANISH
Write (11, 14, STR_RAT2KILL);
Write (11, 16, STR_RAT2SECRET);
Write (11, 18, STR_RAT2TREASURE);
#else
Write (9, 14, STR_RAT2KILL);
Write (5, 16, STR_RAT2SECRET);
Write (1, 18, STR_RAT2TREASURE);
#endif
//Write (26, 2, itoa (gamestate.mapon + 1, tempstr, 10));
#endif
I hope this finds use for someone! If there are any suggestions, comments, let me know |
_________________ I'm back! I missed this community!
Youtube Channel: TreeSapThief
New Site: http://www.treesapthief.com
Twitter: @treesapthief
|
|
 |
linuxwolf
DieHard Guard


Joined: 16 Oct 2012
Last Visit: 18 Nov 2019
Topics: 8
Posts: 202

|
|
 |
Aryan_Wolf3D
DieHard Guard

Joined: 21 Jul 2011
Last Visit: 04 Dec 2019
Topics: 8
Posts: 271

|
|
 |
insurrectionman
DieHard Mutant


Joined: 07 May 2005
Last Visit: 03 Nov 2019
Topics: 87
Posts: 758
Location: Wisconsin

|
Posted: Sat Sep 09, 2017 7:26 am
Subject: Re: [Tutorial] Weapon accuracy stat on Level screen
[ IP : Logged ]
|

 
|
|
Aryan_Wolf3D wrote:
linuxwolf wrote:
This is a good start. Its still missing the 10000 bonus points when you achieve 100% accuracy. However I'll say it would be very difficult to achieve 100% accuracy anyway. Remember hits are randomized:
Yeah, getting 100% accuracy would be practically impossible, so anything > 50% accuracy would probably be enough.
I forgot about the random part when I came up with this idea. I think also, I had the ray-tracing bullets also in mind, so it wasn't a random chance of hit/miss. Although the ray trace also is random on where it'll go (if you have a spread or something to that effect). |
_________________ I'm back! I missed this community!
Youtube Channel: TreeSapThief
New Site: http://www.treesapthief.com
Twitter: @treesapthief
|
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum
|
|
You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group
|