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       

Adding a HUD automap
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
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 2:01 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Tue Feb 28, 2017 5:38 pm
   Subject: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

After a few requests for it, I figured I should probably make a tutorial for my automap. So here it is. This will give you an automap in the top-right hand corner of the screen, centered on the player, showing only areas the player has seen, as well as the ability to bring up the map in its entirety (still with only the seen areas, of course).

The automap:


The overview:


First, put this in WL_DEF.H somewhere (I put it at the bottom):

::: CODE :::
   extern bool automap[MAPSIZE][MAPSIZE];
   void DrawFullmap(void);


Next, in WL_DRAW, insert this code above the ThreeDRefresh function:

::: CODE :::
bool automap[MAPSIZE][MAPSIZE];

#define AUTOSCALE 1         // The scale of the automap view
#define FULLSCALE 2         // The scale of the enlarged automap view
#define AUTORANGE 20        // The range (in tiles) of the automap view from the player in each direction
#define AUTOOFFSET 5        // The distance from the corner of the screen to draw the automap

#define WALLCOLOUR 145      // The colour used to draw walls and unexplored areas
#define EMPTYCOLOUR 154     // The colour used to draw empty space
#define DOORCOLOUR 95       // The colour used to draw a closed door
#define OPNDRCOLOUR 104     // The colour used to draw an open door
#define PLAYERCOLOUR 120    // The colour used to draw the player

//#define DRAWENEMIES       // Have the automap draw visible, active enemies
#define ENEMYCOLOUR 32      // The colour to draw visible, active enemies

byte *scr = NULL;

void DrawTile (int scx, int scy, int scwidth, int scheight, int color)
{
   byte *ptr = scr + scy * bufferPitch + scx;

   while (scheight--)
   {
      memset(ptr, color, scwidth);
      ptr += bufferPitch;
   }
}

void DrawAutomap(void)
{
   int x1 = player->tilex - AUTORANGE, x2 = player->tilex + AUTORANGE;
   int y1 = player->tiley - AUTORANGE, y2 = player->tiley + AUTORANGE;
   int ts = AUTOSCALE * scaleFactor;
   int sx = (320 - ((AUTORANGE*2)+1)*AUTOSCALE - AUTOOFFSET) * scaleFactor, sy = AUTOOFFSET * scaleFactor;
   int dx = 0, dy;

    scr = VL_LockSurface(screenBuffer);

   for (int x = x1; x <= x2; x++)
    {
        dy = 0;
      for (int y = y1; y <= y2; y++)
      {
         if (player->tilex == x && player->tiley == y)
            DrawTile(sx + dx, sy + dy, ts, ts, PLAYERCOLOUR);
         else if (x < 0 || y < 0 || x > MAPSIZE-1 || y > MAPSIZE-1 || !automap[x][y])
            DrawTile(sx + dx, sy + dy, ts, ts, WALLCOLOUR);
         else
         {
            if (!tilemap[x][y])
               DrawTile(sx + dx, sy + dy, ts, ts, EMPTYCOLOUR);
            else if (tilemap[x][y] >= 128)
            {
               if (!doorposition[tilemap[x][y] - 128])
                  DrawTile(sx + dx, sy + dy, ts, ts, DOORCOLOUR);
               else
                  DrawTile(sx + dx, sy + dy, ts, ts, OPNDRCOLOUR);
            }
            else
               DrawTile(sx + dx, sy + dy, ts, ts, WALLCOLOUR);
         }
         dy += ts;
      }
      dx += ts;
    }

#ifdef DRAWENEMIES
   for (objtype *ob = objlist; ob; ob = ob->next)
   {
      if (ob->flags & FL_SHOOTABLE && ob->flags & FL_VISABLE && ob->flags & FL_ATTACKMODE
        && spotvis[ob->tilex][ob->tiley] && ob != player)
      {
         dx = (ob->tilex - player->tilex) * ts;
         dy = (ob->tiley - player->tiley) * ts;
         if (ABS(dx) >= (AUTORANGE+1)*ts
            || ABS(dy) >= AUTORANGE*ts)
            continue;
         DrawTile(sx + dx, sy + dy, ts, ts, ENEMYCOLOUR);
      }
   }
#endif

    VL_UnlockSurface(screenBuffer);
    scr = NULL;
}

void DrawFullmap(void)
{
   int ts = FULLSCALE * scaleFactor;
   int sx = viewwidth/2 - (MAPSIZE/2) * ts;
   int sy = viewheight/2 - (MAPSIZE/2) * ts;
   int dx = 0, dy;

    scr = VL_LockSurface(screenBuffer);

   for (int x = 0; x < MAPSIZE; x++)
    {
        dy = 0;
      for (int y = 0; y < MAPSIZE; y++)
      {
         if (player->tilex == x && player->tiley == y)
            DrawTile(sx + dx, sy + dy, ts, ts, PLAYERCOLOUR);
         else if (x < 0 || y < 0 || x > MAPSIZE-1 || y > MAPSIZE-1 || !automap[x][y])
            DrawTile(sx + dx, sy + dy, ts, ts, WALLCOLOUR);
         else
         {
            if (!tilemap[x][y])
               DrawTile(sx + dx, sy + dy, ts, ts, EMPTYCOLOUR);
            else if (tilemap[x][y] >= 128)
            {
               if (!doorposition[tilemap[x][y] - 128])
                  DrawTile(sx + dx, sy + dy, ts, ts, DOORCOLOUR);
               else
                  DrawTile(sx + dx, sy + dy, ts, ts, OPNDRCOLOUR);
            }
            else
               DrawTile(sx + dx, sy + dy, ts, ts, WALLCOLOUR);
         }
         dy += ts;
      }
        dx += ts;
    }

#ifdef DRAWENEMIES
   for (objtype *ob = objlist; ob; ob = ob->next)
   {
      if (ob->flags & FL_SHOOTABLE && ob->flags & FL_VISABLE && ob->flags & FL_ATTACKMODE
        && spotvis[ob->tilex][ob->tiley] && ob != player)
      {
         dx = ob->tilex * ts;
         dy = ob->tiley * ts;
         DrawTile(sx + dx, sy + dy, ts, ts, ENEMYCOLOUR);
      }
   }
#endif

    VL_UnlockSurface(screenBuffer);
    scr = NULL;
}


If you're using the newer repository or Chris's MAXDOORS/etc. fix, you'll need to change the section:

::: CODE :::
            else if (tilemap[x][y] >= 128)
            {
               if (!doorposition[tilemap[x][y] - 128])


to:

::: CODE :::
            else if (tilemap[x][y] & BIT_DOOR)
            {
               if (!doorposition[tilemap[x][y] & ~BIT_DOOR])


The defines at the top of that can be changed as you wish, although note that setting FULLSCALE higher might cause issues, as at a scale of 2 it takes up a large amount of the screen space anyway.

Now add the following code in ThreeDRefresh:

::: CODE :::
    DrawPlayerWeapon();

    for (int x = 0; x < MAPSIZE; x++)
        for (int y = 0; y < MAPSIZE; y++)
            if (spotvis[x][y])
                automap[x][y] = true;

        DrawAutomap();


Now to WL_GAME. First, in SetupGameLevel, add the following:

::: CODE :::
    memset (tilemap,0,sizeof(tilemap));
    memset (actorat,0,sizeof(actorat));
    memset (automap,0,sizeof(automap));


And in Died, add the following:
::: CODE :::
        gamestate.attackframe = gamestate.attackcount =
            gamestate.weaponframe = 0;
        memset (automap,0,sizeof(automap));


Then in GameLoop add the following two sections:

::: CODE :::
            spearflag = false;
            Thrust (0,0);
            memset (automap,0,sizeof(automap));


::: CODE :::
            case ex_completed:
            case ex_secretlevel:
                if(viewsize == 21) DrawPlayScreen();
                gamestate.keys = 0;
                memset (automap,0,sizeof(automap));


Now, in WL_MAIN, add the following in NewGame:

::: CODE :::
    gamestate.nextextra = EXTRAPOINTS;
    gamestate.episode=episode;
    memset (automap,0,sizeof(automap));


Then in SaveTheGame, add the following:

::: CODE :::
    fwrite (&pwallpos,sizeof(pwallpos),1,file);
    checksum = DoChecksum((byte *)&pwallpos,sizeof(pwallpos),checksum);
    fwrite (automap,sizeof(automap),1,file);
    checksum = DoChecksum((byte *)automap,sizeof(automap),checksum);


Then add the following in LoadTheGame:

::: CODE :::
    fread (&pwallpos,sizeof(pwallpos),1,file);
    checksum = DoChecksum((byte *)&pwallpos,sizeof(pwallpos),checksum);
    fread (automap,sizeof(automap),1,file);
    checksum = DoChecksum((byte *)automap,sizeof(automap),checksum);


Finally, to add a key for the map overview, add the following in CheckKeys in WL_PLAY (I put it below the pause key section)

::: CODE :::
//
// Display full automap
//
    if(Keyboard[sc_M])
    {
        DrawFullmap();
        VH_UpdateScreen();

        IN_ClearKeysDown();
        ScanCode key = IN_WaitForKey();
        while(key != sc_Tab && key != sc_Escape)
            key = IN_WaitForKey();
        IN_ClearKeysDown();

        if (MousePresent && IN_IsInputGrabbed())
            IN_CenterMouse();     // Clear accumulated mouse movement
        lasttimecount = GetTimeCount();
        return;
    }


Note that you can 'sc_M' to whichever key you want to bring up the map.

Additionally, if you want to have a debug command to reveal the whole map, you can use the following in DebugKeys; I've replaced the normal quick program exit code with it.

::: CODE :::
    else if (Keyboard[sc_Q])        // Q = full map
   {
        memset(automap,1,sizeof(automap));
        CenterWindow (12,3);
        US_PrintCentered ("Full map!");
        VW_UpdateScreen();
        IN_Ack ();
        return 1;

   }


Of course, feel free to ask any questions Smile
gerolf
DieHard Wolfer
DieHard Wolfer


Joined: 28 Jan 2010
Last Visit: 11 Dec 2017

Topics: 162
Posts: 1081
Location: Alabama
usa.gif

PostPosted: Tue Feb 28, 2017 11:11 pm
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

If you just wanted this for the overview part, and maybe in a different color than blue, how would you go about doing this?

_________________
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 2:01 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Wed Mar 01, 2017 12:08 am
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

If you just want the overview you can remove the DrawAutomap call in ThreeDRefresh. The colours are defined above the DrawTile function and can be changed at will.
Ginyu
I am Death Incarnate
I am Death Incarnate


Joined: 29 Jan 2016
Last Visit: 10 Jun 2017

Topics: 2
Posts: 186

france.gif

PostPosted: Wed Mar 01, 2017 7:18 am
   Subject: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Thanks for sharing that code.
With 32 screen bit and modified wolf engine, you can also add tranparency to the map. Smile
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 2:01 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Wed Mar 01, 2017 4:31 pm
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

You could arguably kind of do it with the 8-bit colour depth and some coding Razz
Ginyu
I am Death Incarnate
I am Death Incarnate


Joined: 29 Jan 2016
Last Visit: 10 Jun 2017

Topics: 2
Posts: 186

france.gif

PostPosted: Thu Mar 02, 2017 1:38 am
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Yup, that would be doable indeed. Smile
That makes me think of what Carmack did with the software renderer on Quake 2.
http://fabiensanglard.net/quake2/quake2_software_renderer.php
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 2:01 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Thu Mar 02, 2017 2:40 am
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Ginyu wrote:
Yup, that would be doable indeed. Smile
That makes me think of what Carmack did with the software renderer on Quake 2.
http://fabiensanglard.net/quake2/quake2_software_renderer.php


Funnily enough that's pretty much exactly what I would do to implement it Razz
ThunderEnema
I am Death Incarnate
I am Death Incarnate


Joined: 05 Jul 2012
Last Visit: 4:41 ago.

Topics: 4
Posts: 186
Location: Washington
usa.gif

PostPosted: Sat Mar 04, 2017 1:02 am
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Is this code compatible with maps larger than 64x64 (I am using 128x128 maps)?

_________________
"When I see someone wearing crocs in public, I have all the information I need to know that I will never get along with that person." -Me
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 2:01 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Sat Mar 04, 2017 12:02 pm
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I haven't had opportunity to test it, but it should work fine as long as you set FULLSCALE to 1.
ThunderEnema
I am Death Incarnate
I am Death Incarnate


Joined: 05 Jul 2012
Last Visit: 4:41 ago.

Topics: 4
Posts: 186
Location: Washington
usa.gif

PostPosted: Sat Mar 04, 2017 2:18 pm
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

AluMiuN: Just tested it. The code works just fine with bigger maps... but you are right, I did have to set FULLSCALE to 1, otherwise the game would crash.

Awesome tutorial. Thanks for posting this!

_________________
"When I see someone wearing crocs in public, I have all the information I need to know that I will never get along with that person." -Me
AlumiuN
DieHard Wolfer
DieHard Wolfer


Joined: 29 Nov 2007
Last Visit: 2:01 ago.

Topics: 37
Posts: 2401
Location: Christchurch, New Zealand
newzealand.gif

PostPosted: Sat Mar 04, 2017 3:17 pm
   Subject: Re: Adding a HUD automap
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

No problem 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 Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 17503 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 [SDL-Help] Wall patches fix
Author: insurrectionman
0 915 Tue Jul 15, 2008 11:12 am
insurrectionman 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