Combat in Hugo Games: how to do it?

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

Frobozz

Combat in Hugo Games: how to do it?

Post by Frobozz »

Hi.
I've been programming with hugo for a few years (starting in 2010). I'm wondering how to implement combat in hugo games. Nothing tactical; just something other than "Attack x" or "attack x with y". I'm also wondering how to implement multiple weapons, for example: The player has a shotgun and a switchblade. An NPC breaks into his home and fires a shot with is 22. The player has the option to either shoot him with his shotgun or stab him with his switchblade. Any advice and/or information is appreciated.

Roody_Yogurt
Posts: 2179
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

Welcome to the forum, Frobozz.

There are several aspects to doing the type of combat you describe. I'll go over some of them.

First things first, you'll need to declare some grammar for your code. For instance, your "shoot" verb definition might look like this:

Code: Select all

verb "shoot"
*                                       DoVague
* object                             DoShoot
* object "with" held             DoShoot
Then, you might want to come up with some object classes (and maybe make up some new properties while you're at it), like:

Code: Select all

property ammo

class gun
{
    type gun
    ammo 0
}
(See also HbE's type entry)

Then you can make all of the guns in your game using that object class. Lastly, you'll want to make a verb routine:

Code: Select all

routine DoShoot
{
    ! first, check that the player has a gun
    local i , n

    if not xobject ! if the player didn't specify WHICH gun
    {
        for i in player
        {
             if i.type = gun
            {
                 xobject = i
                 n++  ! count how many guns we've found
             }
         }
         if n > 1 ! more than one gun
        {
            "You'll have to specify which gun to use."
            return false  ! don't use up a turn
        }
        elseif not n
        {
            "You don't have a gun."
            return false
         }
    }
    elseif xobject.type ~= gun
    {
         "That doesn't make any sense."
         return false
    }

    if not object.after
    {
         "Why would you shoot that?"
         return false
    }
    return true  ! take up a turn
}
Now, you could code your robber like such:

Code: Select all

property hit_points

character ruffian "ruffian"
{
    article "the"
    adjective 0
    noun "ruffian"
    is unfriendly
    hit_points 100
    after
    {
        object DoShoot
        {
            if self is not living
            {
                "The ruffian is already dead."
                 return true
            }
            elseif random(2) = 2  ! hit the robber half of the time
           {
               "You hit!"
               self.hit_points -= 50
               if self.hit_points < 1
               &#123;
                    "The ruffian dies!"
                    self is not living
                    self.name is "dead ruffian"
                    self.adjective is "dead"
                &#125;
           &#125;
           else
                "You miss!"
           return true
       &#125;
&#125;
Now, that doesn't cover everything and I'm sure there are some bugs there, and there are other ways you could do it. You can also do a system where you character has weapons equipped which are automatically used when the player attacks.

Still, I hope that gives you some ideas about how you'd like to handle it for your game.

User avatar
Tdarcos
Posts: 9333
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Post by Tdarcos »

I'd go a bit further than Roody. In the routine DoShoot I'd add a check to make sure you have ammo and that you shot at a person. I'd also do the check for living there to reduce having to include it in every character that can be shot. These three tests would be inserted right before the object.after test, like this:

Code: Select all


    if i.ammo < 1
   &#123;
       "You're out of ammo."
       return false
    &#125;

    if &#40;&#40;object.type ~= character&#41; and
       &#40;object.type ~= female_character&#41;&#41;
   &#123;
        "You can only shoot at people."
        return false
    &#125;

    if object is not living
    &#123;
         "The ruffian is already dead."
          return false
    &#125;

    if not object.after
    &#123;
         "Why would you shoot that?"
         return false
    &#125;

Doing it this way means you do not need to put the "self is not living" test in each character you could shoot at.

Or where I have the line that "you can only shoot at people." you could have the following:

Code: Select all

    if &#40;&#40;object.type ~= character&#41; and
       &#40;object.type ~= female_character&#41;&#41;
   &#123;
        i.ammo --
        "The weapon makes a loud noise as the gun discharges, but it has no effect on the target other than to use up one round."
        return true
    &#125;

Alan Francis wrote a book containing everything men understand about women. It consisted of 100 blank pages.

Frobozz

Re: Combat in hugo games: How to do it?

Post by Frobozz »

Thanks a lot.

Post Reply