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       

Corner-stabbing in SDL
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
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: Tue May 09, 2017 11:00 am
   Subject: Corner-stabbing in SDL
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

Remember how, in DOS, guards would get stuck on you around corners, allowing the player to just knife them without being shot at? Wolf4SDL added a fix for this, but I've found that it comes with its own drawbacks... For example, often the player will get stuck inside the guard, forcing you to kill him before you can move away... Sometimes another guard will even move into the first one, where he will be invincible until the first guard dies.

Anyway, here's another approach to fixing the old corner-stabbing trick:

In wl_def.h, under "#define MINACTORDIST 0x10000l", add "#define MINCORNERDIST 0xd800l"

Then in wl_state.cpp, find this:
::: CODE :::
    //
    // check to make sure it's not on top of player
    //
    if (areabyplayer[ob->areanumber])
    {
        deltax = ob->x - player->x;
        if (deltax < -MINACTORDIST || deltax > MINACTORDIST)
            goto moveok;
        deltay = ob->y - player->y;
        if (deltay < -MINACTORDIST || deltay > MINACTORDIST)
            goto moveok;

        if (ob->hidden)          // move closer until he meets CheckLine
            goto moveok;

And change it to this:
::: CODE :::

    //
    // check to make sure it's not on top of player
    //
    if (areabyplayer[ob->areanumber])
    {
        deltax = ob->x - player->x;
        if (deltax < -MINCORNERDIST || deltax > MINCORNERDIST)
            goto moveok;
        deltay = ob->y - player->y;
        if (deltay < -MINCORNERDIST || deltay > MINCORNERDIST)
            goto moveok;

        //if (ob->hidden)          // move closer until he meets CheckLine
            //goto moveok;


And finally, remove "hidden" from objstruct, and all of its uses from wl_act2.cpp. For example, in the T_Chase function:

::: CODE :::

void T_Chase (objtype *ob)
{
    int32_t move,target;
    int     dx,dy,dist,chance;
    boolean dodge;

    if (gamestate.victoryflag)
        return;

    dodge = false;
    if (CheckLine(ob))      // got a shot at player?
    {
        ob->hidden = false;
        dx = abs(ob->tilex - player->tilex);
        dy = abs(ob->tiley - player->tiley);
        dist = dx>dy ? dx : dy;

#ifdef PLAYDEMOLIKEORIGINAL
        if(DEMOCOND_ORIG)
        {
            if(!dist || (dist == 1 && ob->distance < 0x4000))
                chance = 300;
            else
                chance = (tics<<4)/dist;
        }
        else
#endif
        {
            if (dist)
                chance = (tics<<4)/dist;
            else
                chance = 300;

            if (dist == 1)
            {
                target = abs(ob->x - player->x);
                if (target < 0x14000l)
                {
                    target = abs(ob->y - player->y);
                    if (target < 0x14000l)
                        chance = 300;
                }
            }
        }

        if ( US_RndT()<chance)
        {
            //
            // go into attack frame
            //
            switch (ob->obclass)
            {
                case guardobj:
                    NewState (ob,&s_grdshoot1);
                    break;
                case blahblah...
            }
            return;
        }
        dodge = true;
    }
    //else
        //ob->hidden = true;


Basically, the smaller number allows the guard to meet CheckLine before he gets stuck on the player's radius, so he'll be able to shoot back. 0xd800 seems to be the largest number that will still make this work.

If you wanted, you could just define MINACTORDIST as 0xd800 instead of adding another constant, but that would change more than is necessary. Of course, there may still be some drawbacks with this method as well, but so far I've found that it works a little better than the original Wolf4SDL one.

_________________
"Way too many #ifdefs in the code!" - John Carmack
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 0:37 ago.

Topics: 160
Posts: 8011
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Tue May 09, 2017 2:02 pm
   Subject: Re: Corner-stabbing in SDL
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

Thanks for posting this one, Aryan. I had seen the "hidden" parameter before, but I never really found out how it was used. Smile
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: Wolf4SDL released
Author: Ripper
522 155233 Mon May 22, 2017 2:04 pm
Tricob 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
No new posts [SDL] Apply 2nd ScaleFactor to selected (hi-res) vga gfx
Author: Andy_Nonymous
9 3276 Sun Apr 27, 2008 2:30 am
AlumiuN 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