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] Interact with guards using Spacebar
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
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 17 Sep 2018

Topics: 163
Posts: 8192
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Wed Nov 30, 2011 3:42 pm
   Subject: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

In this tutorial, you'll be able to "identify" any guard in front of you by pressing the Spacebar. This code can possibly be used as a base for the "Informant Interaction" feature in Blake Stone.

The tutorial assumes you have WSJ's In-game Messages feature working. But the code can easily be changed to accomodate a different feature.

First, go into WL_AGENT.CPP. Do a search for "elevatorok". You should see this code:

::: CODE :::
void Cmd_Use (void)
{
    int     checkx,checky,doornum,dir;
    boolean elevatorok;

Insert this code just below it:
::: CODE :::
    int32_t  dist=0x7fffffff;
    objtype *closest = NULL;

    for (objtype *check=player->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;
            }
        }
    }

Now do a search for "leveldone". You should see this code:
::: CODE :::
        SD_PlaySound (LEVELDONESND);
        SD_WaitSoundDone();
    }

Insert this code just below it:
::: CODE :::
    else if (closest && dist <= 0x18000l && !buttonheld[bt_use])
       {
             switch (closest->obclass)
                    {
                    case guardobj:
                         buttonheld[bt_use] = true;
                         GetMessage("I'm a guard.");
                         break;
                    case officerobj:
                         buttonheld[bt_use] = true;
                         GetMessage("I'm an Officer.");
                         break;
                    case mutantobj:
                         buttonheld[bt_use] = true;
                         GetMessage("I'm a Mutant.");
                         break;
                    case ssobj:
                         buttonheld[bt_use] = true;
                         GetMessage("I'm an SS.");
                         break;
                    case dogobj:
                         buttonheld[bt_use] = true;
                         GetMessage("Woof!");
                         break;
                    }
       }

Note that if you don't have WSJ's In-game Messages feature enabled, just replace each "GetMessage" line with something else. Smile

This routine is actually just a cheap hack of the T_KnifeAttack code, but I optimized it somewhat. Hope it's useful to someone. Smile
Soldat 555
Guest



Last Visit:





PostPosted: Thu Jan 26, 2012 7:25 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

That's cool, Tricob. Smile Even though I'm not making games anymore, I do have a theory you could stick something like "HealSelf" in the code and you could have vending machines or something... The advantage of making vending machine enemies being a stray shot amidst a firefight could cause them to explode, preventing them from giving you health.
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 17 Sep 2018

Topics: 163
Posts: 8192
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Fri Jan 27, 2012 4:09 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Soldat 555 wrote:
That's cool, Tricob. Smile Even though I'm not making games anymore, I do have a theory you could stick something like "HealSelf" in the code and you could have vending machines or something...
Like the vending machines in Blake Stone? It's pretty much just a hack of the Interactive Wall Patches Tutorial. That's actually a strong reason I wrote the code to begin with; it's a good base for the Blake4SDL code.

Quote:
The advantage of making vending machine enemies being a stray shot amidst a firefight could cause them to explode, preventing them from giving you health.
You've been playing Planet Strike lately, haven't you? Smile That's not too different from the experimental creatures from Blake Stone AOG, which are unleashed from those metal canisters when you shoot them.
Soldat 555
Guest



Last Visit:





PostPosted: Sat Jan 28, 2012 12:17 am
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Very Happy lol
In all honesty I HAVEN'T been playing either Blake Stone games in years. Skyrim and Saints Row 3 is just so addicting.

But yeah, I was thinking something of the vending machines in Blake Stone. Totally forgot of those canisters holding the brown beast-things. Before cancelling my work I actually thought of doing some bit of code like this for a destructible Hot Dog stand in Tara Carmichael, something that could do healing but also be fragile to stray shots.

But hey, even though my work is finito this is still cool to see and hope people use in their mods. Smile
ronwolf1705
Moderator
<B>Moderator</B>


Joined: 31 Jul 2006
Last Visit: 6:36 ago.

Topics: 73
Posts: 3765

blank.gif

PostPosted: Sat Jan 28, 2012 6:07 am
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Quote:
Saints Row 3


OT: I played that over at a friend's house, that game is insane! Laughing
Soldat 555
Guest



Last Visit:





PostPosted: Sun Jan 29, 2012 3:11 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

ronwolf1705 wrote:
OT: I played that over at a friend's house, that game is insane![/quote
It is, and very fun to play... My only real disappointment with it was the story seems A LOT shorter than Saints Row 2. SR3 I beat in like 17 hours where SR2 took me more like 30-40 hours to beat as it's got so many more missions and enemies. Make no mistake, I still love SR3. Smile


Actually, wouldn't you be able to use this same bit of code for stealth kills? Like...
::: CODE :::
                    case guardobj:
                         buttonheld[bt_use] = true;
                         GivePoints (100);
                         NewState (ob,&s_grddie1);
                         break;
Merthsoft
Bring 'em On
Bring 'em On


Joined: 12 May 2004
Last Visit: 25 Apr 2018

Topics: 5
Posts: 97
Location: Wisconsin
usa.gif

PostPosted: Thu Mar 08, 2012 6:22 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I thought this was neat, but I wanted to interact with non-shootable things, and static things, so here're my modifications (note that I tag my code with a comment so that I know what I've changed, all I have to do is do a search for [Shaun]--obviously the comments are not needed for the functionality):
In wl_def.h, find the "WL_DRAW DEFINITIONS" section, and at the bottom of that section add this:
::: CODE :::
//
// [Shaun] Interact with static objects
//
#define MAXVISABLE 250

typedef struct
{
    short      viewx,
               viewheight,
               shapenum;
    short      flags;          // this must be changed to uint32_t, when you
                               // you need more than 16-flags for drawing
#ifdef USE_DIR3DSPR
    statobj_t *transsprite;
#endif
} visobj_t;

boolean TransformTile (int tx, int ty, short *dispx, short *dispheight, int* transx, int* transy);

extern visobj_t vislist[MAXVISABLE];
extern visobj_t *visptr,*visstep,*farthest;

Then find the flags in objflag_t, and add this:
::: CODE :::
FL_DEAD            = 0x00002000   // [Shaun] Interact with non-shootable actors

at the end (adjust the number for your purposes).
Now in wl_draw.cpp find the TransformTile function, and redefine it to match the header:
::: CODE :::
boolean TransformTile (int tx, int ty, short *dispx, short *dispheight, int* transx, int* transy) // [Shaun] Interact with static objects

In that function scroll down to the "// calculate newx" section, and make it look like this
::: CODE :::
//
// calculate newx
//
    gxt = FixedMul(gx,viewcos);
    gyt = FixedMul(gy,viewsin);
    nx = gxt-gyt-0x2000;            // 0x2000 is size of object
   *transx = nx; // [Shaun] Interact with static objects
//
// calculate newy
//
    gxt = FixedMul(gx,viewsin);
    gyt = FixedMul(gy,viewcos);
    ny = gyt+gxt;
   *transy = ny; // [Shaun] Interact with static objects

Still in wl_draw.cpp go to the DrawScaleds (vode) function, and near the top with all the variable declarations, add:
::: CODE :::
int       transx,transy; // [Shaun] Interact with static objects

Scroll down a few lines to the call to TransformTile, and change it to:
::: CODE :::
if (TransformTile (statptr->tilex,statptr->tiley,
            &visptr->viewx,&visptr->viewheight, &transx, &transy) && statptr->flags & FL_BONUS) // [Shaun] Interact with static objects

Above the DrawScaleds function you'll see the visobj_t struct definition and the #define MAXVISABLE 250, you'll want to remove those or comment them out from there, since they're in the wl_def.h, keep the actual variable definitions, though, so it should look like:
::: CODE :::
/*
=====================
=
= DrawScaleds
=
= Draws all objects that are visable
=
=====================
*/

// [Shaun] Interact with static objects
//#define MAXVISABLE 250
//
//typedef struct
//{
//    short      viewx,
//               viewheight,
//               shapenum;
//    short      flags;          // this must be changed to uint32_t, when you
//                               // you need more than 16-flags for drawing
//#ifdef USE_DIR3DSPR
//    statobj_t *transsprite;
//#endif
//} visobj_t;

visobj_t vislist[MAXVISABLE];
visobj_t *visptr,*visstep,*farthest;

void DrawScaleds (void)


Now open up wl_agent.cpp and go to void Cmd_Use (void). Underneath the variable declarations for Tricob's stuff, add:
::: CODE :::
   // [Shaun] Interact with static objects
   int      statDist=0x7fffffff;
   statobj_t *statptr;
   statobj_t *closestStat = NULL;
   visptr = &vislist[0];

Under that, you'll want to change the loop that gets the actor a bit, and add another one or the static objects:
::: CODE :::
   // [Tricob] Interact with actors [Shaun] Interact with non-shootable actors
    for (objtype *check=player->next; check; check=check->next) {
        if ((check->flags & FL_VISABLE) && abs(check->viewx-centerx) < shootdelta && check->transx < dist) {
         dist = check->transx;
         closest = check;
        }
    }

   // [Shaun] Interact with static objects
   for (statptr = &statobjlist[0] ; statptr !=laststatobj ; statptr++)  {
        if ((visptr->shapenum = statptr->shapenum) == -1)
            continue;                                               // object has been deleted

        if (!*statptr->visspot)
            continue;                                               // not visable

      int transx, transy;
        TransformTile (statptr->tilex,statptr->tiley,&visptr->viewx,&visptr->viewheight, &transx, &transy);
         if (transx < statDist) { closestStat=statptr; statDist = transx; }
        //}

        if (!visptr->viewheight)
            continue;                                               // to close to the object

        if (visptr < &vislist[MAXVISABLE-1])    // don't let it overflow
        {
            visptr->flags = (short) statptr->flags;
            visptr++;
        }
    }

Now in the spot at the bottom where Tricob's code was, you'll want instead to have this:
::: CODE :::
else if (closest && dist <= 0x18000l && !buttonheld[bt_use]) { // [Tricob] Interact with actors [Shaun] Interact with non-shootable actors
      switch (closest->obclass) {
         case guardobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "This guard is dead." : "I'm a guard.");
            break;
         case officerobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "This Officer is dead." : "I'm an Officer.");
            break;
         case mutantobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "This Mutant is dead." : "I'm a Mutant.");
            break;
         case ssobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "This SS is dead." : "I'm an SS.");
            break;
         case dogobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "This dog is dead." : "Woof!");
            break;
         case columnobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "This column has collapsed." : "This column looks a little weak...");
            break;
         case bossobj:
            buttonheld[bt_use] = true;
            GetMessage(closest->flags & FL_DEAD ? "Motti." : "Guten Tag!");
            break;
      }
   } else if (closestStat && statDist <= 0x18000l && !buttonheld[bt_use]) { // [Shaun] Interact with static objects
      switch (closestStat->shapenum) {
         case 9:
            buttonheld[bt_use] = true;
            GetMessage("Pillar.");
            break;
         case 16:
            buttonheld[bt_use] = true;
            GetMessage("Lamp.");
            break;
         case 29:
            buttonheld[bt_use] = true;
            GetMessage("A machine gun.");
            break;
         case 30:
            buttonheld[bt_use] = true;
            GetMessage("A chain gun.");
            break;
         case 33:
            buttonheld[bt_use] = true;
            GetMessage("The silver key.");
            break;
         case 436:
            buttonheld[bt_use] = true;
            GetMessage("A pistol.");
            break;
         case 437:
            buttonheld[bt_use] = true;
            GetMessage("A case of ammo.");
            break;
         default:
            // This is for debug purposes, so I can see what number items have as I play.
            char msg[100];
            sprintf(msg, "%i\0", closestStat->shapenum);
            GetMessage(msg);
            break;
      }
   }

Now go to wl_state.cpp and at the bottom of KillActor, add this:
::: CODE :::
ob->flags |= FL_DEAD; // [Shaun] Interact with non-shootable actors

And that's that! There are some kinks to iron out (I'd prefer it if it too the one you were directly looking at, not necessarily the one you were closest to, and the distance needs to be adjusted), but it works, at least. You're also going to want to adjust the numbers and messages and such, since you may not have a pistol for sprite number 436, and you might not have a columnobj becase maybe you don't have collapsible columns or whatever.
Here're some screen shots of it in action:






Also, a note worth noting, you don't need the FL_DEAD, you could just check that it's not FL_SHOOTABLE, but I like making a distinction. Maybe there could be dead things that are shootable? Who knows.

_________________
Shaun
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 17 Sep 2018

Topics: 163
Posts: 8192
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Fri Mar 09, 2012 4:36 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Actually, FL_DEAD isn't necessary if you simply want any easy-to-use label for determining "dead" Actors. Instead, you could have this in the beginning of WL_AGENT.CPP (assuming I have the code right):
::: CODE :::
void    ActorDeadCheck (objtype *ob)
{
    if (ob->hitpoints<1) return true;
    return false;
}


Then, when you run the code:
::: CODE :::
ActorDeadCheck(closest)

It will return a "true" if the Actor is "dead", or a "false" if he's still alive.

I haven't actually tested the code yet, though.
Merthsoft
Bring 'em On
Bring 'em On


Joined: 12 May 2004
Last Visit: 25 Apr 2018

Topics: 5
Posts: 97
Location: Wisconsin
usa.gif

PostPosted: Fri Mar 09, 2012 9:30 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Mm, yeah, good point, it could even be simplified to just:
::: CODE :::
inline void IsActorDead(objtype* ob) { return ob->hitpoints < 1; }

or even just a macro. I'm trying to think if there's ever a reason that something might have negative hit points, but no FL_DEAD or vice-versa, but I can't think of a reason where I'd want that. Good catch.

_________________
Shaun
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 17 Sep 2018

Topics: 163
Posts: 8192
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sat Mar 10, 2012 8:22 pm
   Subject: Re: [tutorial] Interact with guards using Spacebar
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

I suppose you could take the code a step further, and have all the text put into an array, and then have the dead/alive actor messages called up by a number. You seem to have a very good handle on coding here, so you're likely to make the code far more compact than I could. Proves once again that I'm better at BASIC coding than I am at C. 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: Wolf3d & Spear of Destiny Shareware SDL Downloads
Author: BrotherTank
10 15112 Tue Aug 24, 2010 10:18 am
dcbasic View latest post
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 24553 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [HELP] Different ammo types.
Author: Raziel
15 2311 Thu Jan 01, 2009 4:45 am
Raziel View latest post
No new posts [HELP] One-way doors (Blake Stone Style)
Author: Haasboy
3 1020 Mon Jul 28, 2008 7:37 pm
Tricob View latest post
No new posts [WOLF4SDL Help] Blake Stone Style doors
Author: Haasboy
3 2998 Sun Jul 20, 2008 7:56 am
Haasboy 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