Mindless Games Network
News & Community
Back to Raven-Games
Welcome!
News Archive
Messageboard
Essential Files
SoF 2 Info
SoF 2 Walkthrough
SoF 2 FAQ
SoF 2 Mapping
SoF 2 Cheats
SoF 2 Gallery
SoF 2 Bulletpoints
SoF 2 Cast
SoF 1 Info
SoF Walkthrough
SoF FAQ
Articles
John Mullins
Weapons
Characters
SoF Awards
Video Cards
What if?
SoF Mailbag
SoF Cheats
SoF Quick FAQ
SoF Reviews
SoF Links
Official Links
Raven Software
Activision
id Software
Keith's Got Code!


We’re back…with more SOF-coding fun than you can shake a stick at. Well, you probably could shake a stick at it, come to think of it, but I’d advise against it. Anyway, here are a few more questions and answers from the past week.

QUESTION 1: I’m currently working on a light-gun type mod ...  What I’m doing will be along the lines of the arcade game Silent Scope.  My questions are:
Is is possible to map joystick input to screen space and have the weapon system fire through that point?
For a scoped view I need to do the same thing but with a magnified view.  In unreal I do this by creating another viewport and moving it around the screen.  Can I do that in SOF?

I asked Pat Lipo, one of our more experienced Quake2-engine programmers, just what he thought about the idea of a light gun for SOF. Here are his responses to both parts of Question 1.

Pat Lipo:

1)     Yep, that’s pretty much it.  Although, I had to create a special userinfo packet to cover a screen position update, if you were to use the joystick as a data entry method, that would work too.  The only thing you’d have to make sure is that the joystick data wasn’t processed first...  In SOF and Q2 the joystick input is handled by in_win, where the “dead spot” in the center is applied to any joystick data.  If you want a free range of movement throughout the screen, you’ll have to be careful.

2)     I assume you mean a mini-view window on top of the main view...  Quake 3 has method for rendering additional views inside a smaller view segment (for reflections, same as Unreal), but Q2 and SOF do not.  It could be done, but I think it would require code that you don’t have access to in the mod.  I could be wrong, however.

Me:

You would probably need to talk to someone (like, say, Rick Johnson) about getting access to more than just the game code that was released in the SDK. I think you could get a light gun setup to work but you’d need to monkey with the client code, and that isn’t publicly available. As for the idea of moving a scoped-in view around on the screen, that would be fairly tricky and it wouldn’t be coded the same way as it would in Unreal (if I understand the question correctly).

QUESTION 2: How would I add zooming to new weapons then? Also wanted to add full screen fades and blends for some pain and damage effects, is this impossible? One of the neat things about Half-Life is customizing the HUD for your mod. Am I missing something, I did a pre-cursory look thru the player.dll and it did seem kinda sparse, what can we actually hope to accomplish with the player.dll?

a) For zooming, you can look at what’s happening with a little-known entity called func_snipercam_zoom. This is an invisible object we used in one of the first cinematics in the game to simulate the sniper scope. It manipulates the player’s field of view (or “fov” for short) so that the camera zooms in. That’ll get you the effect of scoping in and out. Now the question is, how do you get the fov to change based on player input? I would recommend doing something simple like binding two keys to commands like “weaponzoomin” and “weaponzoomout” and then checking for those commands in void ClientCommand (edict_t *ent) in gamecpp/g_cmds.cpp.

b) For fullscreen blending effects, try using void SV_AddBlend (float r, float g, float b, float a, float *v_blend), which is defined in gamecpp/p_view.cpp.

c) You can change the HUD like you did in Quake2 using svc_layout commands. Here are the main commands available to you:

"xl" – use this as an x-value on the screen to indicate the left/right position of text or a picture
“yt” – use this as a y-value on the screen to indicate the up/down position of text or a picture
"picn" – the name of the graphic you’d like displayed
"string" – the text you’d like displayed

So, for example, if you wanted to put the graphic for the nightvision goggles in the top left corner of the screen, you’d put something like this in your code:

                char buf[256];
                Com_sprintf(buf, 256, “xl 0 yt 0 picn pics/interface2/item_nightvision”);
                gi.WriteByte (svc_layout);
                gi.WriteString (buf);

d) I went over the player dll in last week’s list o’ answers, so hopefully it makes more sense now. Player.dll basically contains weapon and inventory related functionality that is run by the client and the server for the purpose of synchronizing information in an effort to combat lag. You should be able to add new weapons by just copying or using the existing code. If you want to add new items, you may want to look at how the itemInfo_c class is used for things like the nightvision goggles and c4.

QUESTION 3: Is there a way to not draw the hud parts?  Like in deathmatch you guys had it so that there is no noise meter, while in realistic mode there is(granted it's used for fatigue).  Is there a way to do this with all the hud pieces from the released code?

I haven’t tried this myself, but it looks doable…try going into void G_SetStats (edict_t *ent) in gamecpp/p_hud.cpp and changing the following line:

      ent->client->ps.stats[STAT_WEAPON] = (!level.intermissiontime)?ent->client->inv->getCurWeaponType():0;

…to this…

      ent->client->ps.stats[STAT_WEAPON] = 0;

I think that should effectively turn off the existing hud.

QUESTION 4: How can I modify the C4 so that it would be more like a proximity mine?  ie, throw the C4 but it doesn't do anything until someone walks near or over it?

This is a pretty simple modification, actually. Go into the c4’s think function, void c4Explode(edict_t *self) in gamecpp/w_equip.cpp. What’s in there now is the timer stuff from SOF. What you want to do is replace the current contents of the function with something that checks how far away the nearest player is and explode if they’re close enough. Try something like this:

void c4Explode(edict_t *self)
{
    vec3_t    vDist;
    float     explodeDist = 512, currentDist = 0;
    int      closestPlayer = 0;
    // loop through all existing players and find the closest one
    for (int i = 1; i <= game.maxclients; i++)
    {
        VectorSubtract(self->s.origin, g_edicts[i].s.origin, vDist);
        currentDist = VectorLength(vDist);
        if (currentDist < explodeDist)
        {
            // this player is close enough…BLAMMO!!!
        }
    }
}

This will cause the c4 to explode when someone gets within 512 units of it. Now, you probably want some sort of timer in there so it doesn’t activate immediately. Otherwise, it’ll blow up as soon as you place it because you’re close enough to it to cause it to detonate. Since the code that came in the SDK is a timer, I’m pretty sure you can figure out how to copy and paste it into the code I just provided.

That’s all for now. Keep at it, folks…

Keith Fuller
Programmer
Raven Software
kfuller@ravensoft.com

[Previous Keith's Got Code!]

© 1998-2007 Mindless Games & Entertainment. All Rights Reserved.
Soldier of Fortune™ and any associated characters are ® ™ Raven Software &/or Activision, Inc. All Rights Reserved.