Wolf3d Haven Forum

Please log in or register. Smile

Join the forum, it's quick and easy

Wolf3d Haven Forum

Please log in or register. Smile

Wolf3d Haven Forum

Would you like to react to this message? Create an account in a few clicks or log in to continue.
Wolf3d Haven Forum

A friendly Wolfenstein 3D community, about Wolfenstein 3D, the game that gave birth to first person shooters...


    SDL Tut Adding Body Armor

    Agent_Falcon93
    Agent_Falcon93
    Can I Play, Daddy?
    Can I Play, Daddy?


    Male
    Number of posts : 39
    Age : 37
    Location : subterranean caverns & catacombs
    Job : Entrepreneur
    Hobbie : Beach Days & Gardening
    Message : Author of Castle Erzengel Demo, and the upcoming Runes of North Castle Court, and the rest of the Series : Knights of the ᛋᛋ.
    Registration date : 2021-12-05

    SDL Tut Adding Body Armor  Empty SDL Tut Adding Body Armor

    Post by Agent_Falcon93 Thu Sep 21, 2023 6:03 pm

    The original tutorials to add Body Armor have been lost to dead web pages. And as it is a commonly desired addition I thought we should have a tutorial covering all of it. 
    The most important part of this tutorial comes from Brother Tank's Armor Effectiveness / Take Damage Routine on DHW 
    @     :       http://dhw.wolfenstein3d.com/viewtopic.php?t=1609

    From this I just added what I knew of what else was needed, and the rest I filled in with a peak at TFS30 code from Tristan Van Puten. 
    Then there was just to realize my silly mistake of having my drawarmor routine calling gamestate.health....because I copy and pasted it and forgot to change that part...  Frustrated  but now it seems to work.  Cool
    Also used chatgpt to fix some stuff in the interactive object armor pickup to make it only take the armor if armor is below 90.

    Here's a few important notes about implementing body armor, and this tutorial;
    1 you may need to change your status bar.
    2  on that note some of this tutorials methods may not be right for your mod, ie for the time being I have removed the Face(temporary I hope) to fit other things including objective points, keys, items, and of course Armor, some mods add onto health some have armor with its own count on status bar, some have other ways, in this method it displays on status bar as it's own count. 
    3 your armor pick up, this also a design question, I will include info on 2 methods ie traditional wolf3d bonus object on floor, and interactive object,  but there are others ie interactive walls etc. you can also make enemies drop it but it would be critically damaged irl so....
    4 I haven't added helmets or any other armor and I don't know how so if you want to add those Question maybe peak at some source codes, but it may be as simple as adding a helmet bonus object that gives armor percent. 
    5 coding is still something I struggle with and I haven't fully tested this yet so this could have problems, but it seems to work with basic testing. 
    6 I could not get givearmor (); to work so I used gamestat.armor = __;
    7 I included in the comments some code that you may or may not need / want by all means just delete if you don't want it, but if you do want it       its already there. 
    ____________________________________________________________________________________________________________


    Alright now lets add the armor;


    Use your IDEs Search All Files function to Search for every instance of :
    DrawHealth


    Start with WL_Def.h 
    in the section // player state info
    You should see :
    void    DrawHealth (void);

    under that add
    Code:
    void    DrawArmor (void); 

    Now while we are in Def.h lets define some other things needed
    Search for :   // gamestate structure 
    find : typedef struct
    add here
    Code:
    short       armor;

    Now search for :  WL_AGENT DEFINITIONS
    under the line for take damage  add this line 
    Code:
    void    GiveArmor (int points);


    Now lets add the armor object(s)
    most people use bonus objects so lets start there
    find where in your static sprites list you want to add the pick up
    I recommend adding a new object after your attack frames
    Code:
    SPR_Armor_Vest
    And or if you want to add an interactive object 
    Code:
    Armor_Vest_Table,Table_No_Armor

    Now if your adding a bonus object add that bonus part 
    search : typedef enum
    add this under say bo_firstaid or bo_health
    Code:
    bo_armor,

    Now in WL_Act1 where your static sprites are set again you need to assign one to the bonus object(s)
    Code:
    {SPR_Armor_Vest,bo_armor},


    and add in the stuff for it with the other bonus items ie 
    Code:
    case    bo_armor:



    (By All Means if you haven't implemented and or don't want the extra stuff commented out just delete it. ie the cmd use, get message, etc) 
    In WL_Agent.cpp you in 
    = GetBonus 
    you will need something like
    Code:
    case bo_Armor:
             //       SD_PlaySound (ARMOR); // if you have a sound for it uncomment this
     // GiveArmor (50); // I cant get that method to work!
             //    GetMessage("Armor Vest");// if you have the feature implemented you can use it here
                   gametate.ammo = 99; // how much?
     break;

    or 

    Code:
    case bo_Armor:
                           if(buttonstate[bt_use])
    {
                if (gamestate.armor == 99) // or whatever your max is
                    return;
                //   GiveArmor (99); // I cant get that method to work!
                     gametate.ammo = 99; // how much?
           //     SD_PlaySound (ARMOR); // if you have a sound for it uncomment this

              //    GetMessage("Armor Vest"); // if you have the feature implemented you can use it here
               //   if (gamestate.mapon == )  // for level specific customizing {}
                   break;
                }

    These bonus item pickups may or may not work I'm only using interactive objects for the armor pickup,
     if you have issue chatgpt should be able to fix the pick up code, you may need the code 
    or if you want an interactive object do this 
    in WL_Def.h in your relevant section of the static sprites
    Code:
    // Armor
        Armor_Vest_Table,Table_No_Armor,

    and under type def enum 
    Code:
    zip_equip,



    and in the static objects area in WL_Act1,c

    Code:
    {Armor_Vest_Table,zip_equip},{Table_No_Armor,block},

    and add the blocking stuff

    Code:
    case zip_equip:
      actorat[tilex][tiley] = (objtype *)64; // consider it a blocking tile
        break;


    and in WL_Agent.cpp
    in your cmd_use
    Code:
        case Armor_Vest_Table: //Armor Vest Table
        // Give ? (Body_Armor_Vest);
        if (gamestate.armor <= 90) // Check if armor is less than or equal to 90
        {
        GetMessage("Body Armor Vest");//experimental Body Armor from Luftwaffe
        statptr->shapenum =  Table_No_Armor  ;
        //  GiveArmor(72);
          gamestate.armor = 72;
          StartBonusFlash ();
            }
        else
        {
            return; // Don't give armor if it's over 90, simply return from the function
        }
        break;

    of course you will need the interactive object cmd_use function implemented  found at link below 
    http://dhw.wolfenstein3d.com/viewtopic.php?p=73603

    In WL_Game.cpp you must add the case numbers for the objects to spawn in the ScanInfoPlane
    above one of those spawnstatic things, and don't ask me how those work I don't understand it. 
    ie 
    Code:
    case 398: // Table with Armor Vest
    and you could add the table without armor to add some anxiety to the game  ie   case 399: // Table No Armor MF
    remember to put it on the case number You Need. 
    And the relevant map editor definitions to your preferred editor(s).

    ____________________________________________________________________________

    Ok Now Back to the main part 
    Go Back and once again Search All Files for DrawHealth


    As a general rule Every Place you find it add below it, this is drawing the armor count numbers to the status bar 

    DrawArmor

    ie 
    Code:
           DrawWeapon ();
            DrawHealth ();
            DrawKeys ();
            DrawAmmo ();
            DrawArmor ();
            DrawScore ();

    This should be added to  The following :

    • DrawPlayScreens in WL_Game.cpp (and that list of status bar counts is in there twice)
    • Died in WL_Game.cpp (toward end of died code)
    • QuickLoad in WL_Menu.cpp
    • You may also want to add it to 
    • The main cheat code ie ILM or whatever you have changed it to. 
    • That is in WL_Play.cpp 
    • (We've already added what's needed in WL_Def.h)


    Now DrawHealth should yield a few more results that lead to places we need;
    The actual Draw Health routine in WL_Agent.cpp
    so in this area we need to add one for Draw Armor

    Code:
    /*
    ===============
    =
    = DrawArmor
    =
    ===============
    */

    void DrawArmor (void)
    {
        if(viewsize == 21 && ingame) return;
        LatchNumber (21,18,2,gamestate.armor);
    }

    This is telling the engine where on the status bar to display how much body armor the player has.
    Remember those LatchNumber positions I put here are just the ones I'm using, you will probably need to adjust them 
    The First set numbers (22,...) are the position on the horizontal axix, The Second set (..,18,..) are the position on the vertical axis, 
    The Third set (...,2) is how many digits the armor count has, if you want over 99 percent than you need a 3 not a 2,
     or if you want to be obnoxious 1   jocolor

    Now finally in WL_Agent.cpp 
    after the routine for   DrawHealth   we will add Brother Tanks special Armor using Take Damage Routine


    Code:
    /*
    ===============
    =
    = TakeDamage
    =
    ===============
    */
    // with BT's Armor-Damage System
    void TakeDamage (int points,objtype *attacker)
    {
      int hpoints;
      LastAttacker = attacker;
      if (gamestate.victoryflag) return;
      if (gamestate.difficulty==gd_baby) points>>=2;

      if (!godmode)
       {
          if (gamestate.armor >=1)
            {
               hpoints = (gamestate.armor * points) / 99;
               points -= hpoints;
               gamestate.armor -=hpoints;
               if (gamestate.armor < 0 ) gamestate.armor = 0;
            DrawArmor (); // Your routine to update armors value on status bar
            }
          gamestate.health -= points;
          StartDamageFlash (points);
       }

      if (gamestate.health<=0)
       {
          gamestate.health = 0;
          playstate = ex_died;
          killerobj = attacker;
       }
    //  gotgatgun=0; // idk what this is?
      DrawHealth ();
      DrawFace ();
    }

     gotagun is commented out, I don't know if that is vanilla dos code, or vanilla sdl code (I used WSJ's SDL Reloading tut), 
    or something custom. If you need it uncomment it. 
    Also you may want to draw the big smile face when the player equips the armor. 


    Well That's it, its not the best tutorial but I wanted to give something back to the community, as the community is always helping me, and this is something that was partly lost when older Wolf3D sites went down, and it can especially help those new to the code. 
    If you problems or solutions please share them here.



    SDL Tut Adding Body Armor  Right-arrow



    SDL Tut Adding Body Armor  Right-arrow farao "Call Pizza Hut and say Ardwolf"  SDL Tut Adding Body Armor  1f355

      Current date/time is Mon Jun 17, 2024 6:39 am