DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial] Weapon accuracy stat on Level screen
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 11 Dec 2017

Topics: 86
Posts: 752
Location: Wisconsin
usa.gif

PostPosted: Thu Aug 24, 2017 7:00 pm
   Subject: [Tutorial] Weapon accuracy stat on Level screen
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

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
Bring 'em On
Bring 'em On


Joined: 16 Oct 2012
Last Visit: 15:17 ago.

Topics: 6
Posts: 145


PostPosted: Thu Sep 07, 2017 6:39 pm
   Subject: Re: [Tutorial] Weapon accuracy stat on Level screen
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

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:

::: CODE :::

void    GunAttack (objtype *ob)
{
...
        if ( (US_RndT() / 12) < dist)           // missed
...
}
Aryan_Wolf3D
I am Death Incarnate
I am Death Incarnate


Joined: 21 Jul 2011
Last Visit: 16 Dec 2017

Topics: 6
Posts: 172

blank.gif

PostPosted: Fri Sep 08, 2017 2:02 am
   Subject: Re: [Tutorial] Weapon accuracy stat on Level screen
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

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.

_________________
"Way too many #ifdefs in the code!" - John Carmack
insurrectionman
DieHard Mutant
DieHard Mutant


Joined: 07 May 2005
Last Visit: 11 Dec 2017

Topics: 86
Posts: 752
Location: Wisconsin
usa.gif

PostPosted: Sat Sep 09, 2017 7:26 am
   Subject: Re: [Tutorial] Weapon accuracy stat on Level screen
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

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
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Announcement: Wolf3d & Spear of Destiny Shareware SDL Downloads
Author: BrotherTank
10 13132 Tue Aug 24, 2010 10:18 am
dcbasic View latest post
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 17505 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 7362 Fri May 26, 2017 8:19 am
Military View latest post
No new posts [WOLF4SDL Help] Blake Stone Style doors
Author: Haasboy
3 2197 Sun Jul 20, 2008 7:56 am
Haasboy View latest post
No new posts [Help] Problem with Checkweaponchange function (wolf4sdl)
Author: Mortimer
4 2335 Sat May 17, 2008 11:26 am
Mortimer View latest post
 
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