LOG FILES IN WOLF4SDL

In this tutorial I'll explain to you how to add the log disc feature from Absence in Wolf4SDL.

Code Legend:
Blue lines - Code changes
Red lines - Code additions

First of all, make sure that you've enabled the "Read This!" feature in Wolf4SDL, otherwise you can't add this feature! You can find a tutorial on how to add the "Read This!" feature in Wolf4SDL for the Spear of Destiny code base here. If you're using the Wolfenstein 3D code base, just follow this tutorial by MCS.

If you've successfully added the "Read This!" feature to your mod, we can start to add the log files feature. Open your wl_text.cpp and add the first red code block at the beginning of the file and the second red code block at the end of the file:

Click to show code

// WL_TEXT.C

// Added by Havoc
#include <sys/stat.h>
#include <sys/types.h>
#ifdef _WIN32
	#include <io.h>
#else
	#include <unistd.h>
#endif

#include "wl_def.h"
#pragma hdrstop

[...]

/*
======================
=
= Log Disc Screens
=
= By Havoc
=
======================
*/
void LogDiscScreens(char* choice)
{
    struct stat statbuf;
    char*       text;
    memptr      layout;
    char        logfilename[13] = "LOG000.";

    strcat(logfilename, extension);

#ifndef SPEAR
    logfilename[3] = '0' + (gamestate.episode + 1);
    logfilename[4] = '0' + (gamestate.mapon + 1);
#else
    logfilename[3] = '0' + ((gamestate.mapon + 1) / 10);
    logfilename[4] = '0' + ((gamestate.mapon + 1) % 10);
#endif
    logfilename[5] = *choice;
	
    if (!stat(logfilename, &statbuf))
    {
        CA_LoadFile(logfilename, &layout);

        text = (char*)layout;

        ShowArticle(text);

        free(layout);
		
        VW_FadeOut();
    }
}

Now open your wl_def.h and add the following code:

Click to show code

[...]

/*
=============================================================================

                             WL_TEXT DEFINITIONS

=============================================================================
*/

extern  char    helpfilename[],endfilename[];

extern  void    HelpScreens(void);
extern  void    EndText(void);
extern  void    LogDiscScreens(char* choice);

[...]

Our next step is to set up the object which shall display the log disc screens. Open your wl_agent.cpp and add these code lines:

Click to show code

[...]

/*
===============
=
= Cmd_Use
=
===============
*/

void Cmd_Use (void)
{
    int     checkx,checky,doornum,dir;
    boolean elevatorok;
    statobj_t* statptr;    // Added by Havoc for interactive objects

    //
    // find which cardinal direction the player is facing
    //
    if (player->angle < ANGLES/8 || player->angle > 7*ANGLES/8)
    {
        checkx = player->tilex + 1;
        checky = player->tiley;
        dir = di_east;
        elevatorok = true;
    }
    else if (player->angle < 3*ANGLES/8)
    {
        checkx = player->tilex;
        checky = player->tiley-1;
        dir = di_north;
        elevatorok = false;
    }
    else if (player->angle < 5*ANGLES/8)
    {
        checkx = player->tilex - 1;
        checky = player->tiley;
        dir = di_west;
        elevatorok = true;
    }
    else
    {
        checkx = player->tilex;
        checky = player->tiley + 1;
        dir = di_south;
        elevatorok = false;
    }

    // Added by Havoc for interactive objects
    for (statptr = &statobjlist[0]; statptr != laststatobj; statptr++)
    {
        if (statptr->tilex == checkx && statptr->tiley == checky &&
            (statptr->shapenum == SPR_STAT_4 || statptr->shapenum == SPR_STAT_9 || statptr->shapenum == SPR_STAT_19) &&
            !buttonheld[bt_use])
        {
            buttonheld[bt_use] = true;

            ClearMemory();

            VW_FadeOut();
			
            switch (statptr->shapenum)
            {
                case SPR_STAT_4:
                    LogDiscScreens("1");
                    break;
				
                case SPR_STAT_9:
                    LogDiscScreens("2");
                    break;
				
                case SPR_STAT_19:
                    LogDiscScreens("3");
                    break;
            }

            ClearMemory();

            IN_ClearKeysDown();

            DrawPlayScreen();
        }
    }

    doornum = tilemap[checkx][checky];
    if (*(mapsegs[1]+(checky<<mapshift)+checkx) == PUSHABLETILE)
    {
        //
        // pushable wall
        //

        PushWall (checkx,checky,dir);
        return;
    }

[...]

Now you just need to create log text files which work just like the help text files for the "Read This!" feature. Here are some examples on how the text file names need to look like in order to get displayed on the correct maps and objects:

  • log111.wl6 = Episode 1, Map 1, Object 1 (In my tutorial example this would be SPR_STAT_4 (Chandelier))
  • log122.wl6 = Episode 1, Map 2, Object 2 (In my tutorial example this would be SPR_STAT_9 (Skeleton))
  • log213.wl6 = Episode 2, Map 1, Object 3 (In my tutorial example this would be SPR_STAT_19 (Bones 1))

Congratulations, you've successfully added log files to your mod!

Don't use any of the code from this tutorial in your mod without giving me credit!

- Havoc