Quake3World.com Forums
     Programming Discussion
        Good tutorials to start with?


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Good tutorials to start with?

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-02-2010 07:25 AM           Profile   Send private message  E-mail  Edit post Reply with quote


I've downloaded the Quake 3 game sourcecode out of interest. I like messing around a bit with the sourcecode and see what I can come up with.

The problem is, I don't really know where to start. There's tons of tutorials out there are aimed at very specific things and so far I've been successful at making happy colored smoke trails and make people spawn with 999 bullets or spawn with a rocket launcher. However, this doesn't give me any insight into the larger scheme of things.

However, I'd like to see some more general info. Just some general guidelines that id Software themselves stuck to while implementing. For instance, how is the code set up in general? What's the general flow through the code? What do all the prefixes like ai_, g_ and bg_ mean for the source files? How can I output messages to the console (always handy for simple debugging)? Where are various constants/enums defined?

I hope to get a good enough understanding to implement a new version of the Weapons of Fury mod from the ground up. In this mod there were no weapon/ammo pickups, player started off with a Rocket Launcher and after a frag moved on to the SG, then to the next weapon, etc, etc until you hit the last weapon and scoring a frag with that rewards you 100 points. Getting killed resets you to the RL.

It was a fun mod but it's vanished off the face of the Internet. And I think it wasn't developed beyond the 1.27 codebase.

Shouldn't be too hard to implement I think, but some starter tutorials will help.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-02-2010 10:31 AM           Profile Send private message  E-mail  Edit post Reply with quote


Where to start, where to start...

The best tip I can give you is to install Eclipse with the C/C++ plugin (or Visual Studio, though I don't use that myself) and import the Q3A source into it. Pressing F3 to jump to the definition of a variable, struct or enum is an enormous time saver. 'Find references' and Ctrl+Shift-R (to find-as-you-type files and declarations) are two more killer features.

The general layout of the source is that cgame/ contains the client SDK and game/ the server-side. There are more but those are engine related and you won't need them right away.

ai_* files contain the bot logic, g_* the server code and bg_* is shared between client and server (stuff like prediction).

Com_Printf() will echo to the console. client_t and level_t are structs you will want to know by heart. g_active() contains a lot of the gameplay code so you'll probably be coming back to it a lot.

Hope this gives you something of a head start. Ask pointed questions if you get stuck. =)




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-02-2010 11:57 PM           Profile   Send private message  E-mail  Edit post Reply with quote


Yea thanks, info like this is useful. I'm using Visual Studio 2008, which seems to work well so far. I couldn't get it to build at first though, but then I read somewhere that I needed to unload the ui project. I think I'll just keep poking at it until I've got something useful out of it. Things like that take time (which I haven't got and will be having even less of soon I'm afraid).




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-03-2010 02:08 AM           Profile Send private message  E-mail  Edit post Reply with quote


Heh, the perils of parenthood. Fortunately, they do nothing but sleep for the first couple of months.




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-03-2010 03:36 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Heh, not a parent yet though. My gf was at 40 weeks last tuesday, so now the waiting game has started for real.

I've been poking a bit through the code and I must say that from what I've seen so far, it's not quite as hard to understand as I thought it would be. I'm full well aware that I've only scratched the surface. So far I've managed to make it so that you spawn with RL, get 999 ammo at spawn (temporary solution until I get to figuring out where the ammo is counted down), remove ammo model/amount from statusbar and stop weapons/ammo from spawning. Right now I'm hunting to see if there's a function triggered somewhere when a client makes a kill.

I think this Weapons of Fury clone is a really good way to get introduced to the code. I get to mess around with some really basic stuff and I don't need additional artwork or assets while it is a very well playable kind of mod.

edit:
dumb question maybe, but how do I turn the DLL files into qvm files? I reckon the q3asm tool is used for that?




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-03-2010 06:08 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Ahah, so far I've managed to implement all basic functions required for this mod:
  • You spawn with the rocket launcher and progress on to the next weapon for each frag you make.
  • You get 999 ammo of the weapon upon spawn or switch (temporary solution until I get to figuring out where the ammo is counted down).
  • I've removed the ammo model/amount from the statusbar.
  • Ammo and weapons no longer spawn in the world.
  • Players no longer drop their weapon when killed.
  • Players are awarded 10 points for a kill made with the last weapon (BFG) and then go back to the RL again.

Now I'm implementing (serverside) cvars so that the server admin can implement a custom weapon order (default is RL > PG > SG > LG > RG > GL > MG > BFG) and set the amount of points scored for fragging with the BFG.

I also noticed that switching to the next weapon isn't as smooth as I'd like it to be, so I gotta look into that a bit further.

Hey, making mods is really easy actually :clownboat:




Last edited by Eraser on 09-03-2010 06:34 AM, edited 1 time in total.

Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-03-2010 06:13 AM           Profile Send private message  E-mail  Edit post Reply with quote


Eraser wrote:
[*]You get 999 ammo of the weapon upon spawn or switch (temporary solution until I get to figuring out where the ammo is counted down).

Check out PM_Weapon() in bg_pmove.c.




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-06-2010 12:08 AM           Profile   Send private message  E-mail  Edit post Reply with quote


yay I found it thanks. Right now, basically the only thing I still need is that I want to broadcast a message to all the clients whenever a player gets the last weapon in the sequence. This message should be displayed in the center of the screen (like with the countdown until the match begins). I've found the methods like CG_DrawBigString in cg_drawtools.c and I've figured out that level.clients holds all clients in the game, so now I wonder how to notify each client of the message. Is this where the bg_*.c files come in handy?

I'm also trying to figure out how to compile qvm files. I've been dicking around with the bat files located in the cgame, game and q3_ui folders which call q3asm.exe but I continually get errors about it not finding q3cpp or other things. Is there a general purpose batch file or GUI somewhere that can do this for me the right way?




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-06-2010 01:58 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Ooh, I got the batch files to compile my qvm's finally :)




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-06-2010 02:43 AM           Profile Send private message  E-mail  Edit post Reply with quote


Eraser wrote:
yay I found it thanks. Right now, basically the only thing I still need is that I want to broadcast a message to all the clients whenever a player gets the last weapon in the sequence. This message should be displayed in the center of the screen (like with the countdown until the match begins). I've found the methods like CG_DrawBigString in cg_drawtools.c and I've figured out that level.clients holds all clients in the game, so now I wonder how to notify each client of the message. Is this where the bg_*.c files come in handy?

No, but it's pretty easy to do:
Code:
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " is owning you like mad.\n\"", client->pers.netname) );




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-07-2010 11:41 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Cool, that works :)
Sorry for asking so much stuff, but right now, whenever a bot gets into my field of view, the console is spammed with "ERROR: Weapon number out of range" messages. I'm guessing it's related to me stopping all weapons/ammo boxes from spawning. That, or it's because I'm forcing a weapon into the hands of players rather than what they've picked up, but I think it's odd that this would cause such errors.
Got any ideas what could cause this?




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-07-2010 12:31 PM           Profile Send private message  E-mail  Edit post Reply with quote


Hey, that's what the forum is for. Do you give players the grapple? You get that message when trap_BotGetWeaponInfo() is called (ai_dmq3.c, two places) and the bot has a weapon that is not defined in the bot's skill file (those faux C files in pak0.pk3).




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-20-2010 05:38 AM           Profile   Send private message  E-mail  Edit post Reply with quote


I've picked it up again for a bit and I think I've isolated the problem in BotChooseWeapon() in ai_dmq3.c

There's a line of code that always returns 0:

newweaponnum = trap_BotChooseBestFightWeapon(bs->ws, bs->inventory);

It then assigns the value of newweaponnum (which is always 0) to bs->weaponnum and then things turn south. The thing is, I'm not familiar yet with how these trap_ functions work. It looks like trap_BotChooseBestFightWeapon does some sort of system call that's handled in some piece of code I don't have access to?

edit:
well, I've come up with a quick workaround. It's not a really nice solution but I guess it does the trick for now. Since in my mod a player always carries only one weapon, I've replaced the line I posted above with the following code:

Code:
if (bs->inventory[INVENTORY_GAUNTLET] == 1)
    newweaponnum = WP_GAUNTLET;
if (bs->inventory[INVENTORY_MACHINEGUN] == 1)
    newweaponnum = WP_MACHINEGUN;
if (bs->inventory[INVENTORY_SHOTGUN] == 1)
    newweaponnum = WP_SHOTGUN;
if (bs->inventory[INVENTORY_GRENADELAUNCHER] == 1)
    newweaponnum = WP_GRENADE_LAUNCHER;
if (bs->inventory[INVENTORY_ROCKETLAUNCHER] == 1)
    newweaponnum = WP_ROCKET_LAUNCHER;
if (bs->inventory[INVENTORY_LIGHTNING] == 1)
    newweaponnum = WP_LIGHTNING;
if (bs->inventory[INVENTORY_RAILGUN] == 1)
    newweaponnum = WP_RAILGUN;
if (bs->inventory[INVENTORY_PLASMAGUN] == 1)
    newweaponnum = WP_PLASMAGUN;
if (bs->inventory[INVENTORY_BFG10K] == 1)
    newweaponnum = WP_BFG;


If the bot has a weapon in it's inventory, that weapon should be the weapon he chooses to use, so I assume this blunt-axe approach should do the trick.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-20-2010 08:25 AM           Profile Send private message  E-mail  Edit post Reply with quote


Eraser wrote:
It looks like trap_BotChooseBestFightWeapon does some sort of system call that's handled in some piece of code I don't have access to?

Correct. The trap is handled in server/sv_game.c, that delegates it to the code in botlib/ (probably be_ai_weap.c).




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-21-2010 04:26 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Well, all the features are in and I think there aren't any bugs left so I decided to really blow the lid off this thing and call it a 1.0 release. It's available from the website:

http://eoc.byethost5.com/index.php?p=misc/wofreloaded




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-21-2010 07:46 AM           Profile Send private message  E-mail  Edit post Reply with quote


Good for you, Eraser. Now tag that beast v1.0 in your repository!

On an unrelated note, have you tried git yet? All the cool kids are on GitHub these days, you know.




Top
                 

Immortal
Immortal
Joined: 12 Mar 2005
Posts: 2205
PostPosted: 09-21-2010 03:59 PM           Profile   Send private message  E-mail  Edit post Reply with quote


^misantropia^ wrote:
Good for you, Eraser. Now tag that beast v1.0 in your repository!

On an unrelated note, have you tried git yet? All the cool kids are on GitHub these days, you know.


This man speaks truth.

I <3 git




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-21-2010 11:20 PM           Profile   Send private message  E-mail  Edit post Reply with quote


Nope, never used Git before. Not sure if "the cool kids do it" is a really persuasive argument to move over to GitHub to be honest ;)

Does it really bring anything useful new features to the table for one-man projects?




Top
                 

Immortal
Immortal
Joined: 12 Mar 2005
Posts: 2205
PostPosted: 09-22-2010 12:55 AM           Profile   Send private message  E-mail  Edit post Reply with quote


One word - Branching.

If you don't love branching yet, that's because you haven't used git. ;)




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-22-2010 01:32 AM           Profile Send private message  E-mail  Edit post Reply with quote


Branching and forking. It makes it much, much easier for people to participate.




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-22-2010 02:56 AM           Profile   Send private message  E-mail  Edit post Reply with quote


But SVN does these things too...?




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-22-2010 09:33 AM           Profile Send private message  E-mail  Edit post Reply with quote


Not in the same way. You as the one with commit access can branch stuff but I can't. Forking your project without losing all history is a god-awful hassle. Merging changes from my fork is mostly an all-or-nothing thing, cherry picking in SVN is so limited you could call it non-existing and no one would disagree.

Enter git (and GitHub). Forking is a single-click operation. Pulling changes from my repo is a one-liner. Cherry picking is so powerful that when I have touched foo.c in five places, you can pick changes 1, 4 and 5 but not 2 and 3.

Try it out. git has a learning curve but once you get git, you'll never look back. And if you can't do away entirely with SVN, there's always git-svn, it's what I use at work.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-22-2010 09:39 AM           Profile Send private message  E-mail  Edit post Reply with quote


One more thing: I forgot to mention how much faster git is. It's not just the network overhead SVN has, things like merging are 20-100x as fast.

To illustrate how slow SVN really is: at my previous job I once had to merge two branches with roughly 250K lines added/removed/updated (about 2000 commits worth of changes). The merge took nearly *six hours* to complete. The same merge in git takes less than ten minutes.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-23-2010 08:37 AM           Profile Send private message  E-mail  Edit post Reply with quote


So, Eraser... I understand and appreciate my eloquent replies have left you speechless. But have you made the switch to git yet? If so, this is me: http://github.com/bnoordhuis - follow me for great justice!




Top
                 

Immortal
Immortal
Joined: 12 Mar 2005
Posts: 2205
PostPosted: 09-23-2010 04:37 PM           Profile   Send private message  E-mail  Edit post Reply with quote


misantropia - that infinite adaptive mario repo on your github page was originally done by a guy studying at the university in my hometown :)




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-23-2010 11:03 PM           Profile   Send private message  E-mail  Edit post Reply with quote


Nope haven't looked into it yet. I'll check it out whenever the opportunity arises. Right now I'm not really busy with any personal programming projects and the hassle of moving over the mod files from Google Code to Github doesn't seem worth it at this point.

I'm somewhat familiar with the web interface side of github though. It's where script.aculo.us host their files and wiki.




Last edited by Eraser on 09-24-2010 02:50 AM, edited 1 time in total.

Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-24-2010 02:16 AM           Profile Send private message  E-mail  Edit post Reply with quote


@SM: Did he write the original Infinite Mario or the adaptive version? I mavenized it because I had some ideas I wanted to hack onto it. But the code is of the "change one thing, break seven random other things" persuasion so I decided to waste my time on something more fruitful.




Top
                 

Immortal
Immortal
Joined: 12 Mar 2005
Posts: 2205
PostPosted: 09-24-2010 02:21 AM           Profile   Send private message  E-mail  Edit post Reply with quote


The adaptive version.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-24-2010 06:52 AM           Profile Send private message  E-mail  Edit post Reply with quote


Then I don't have to smash him, that was actually bolted on quite nicely.

Side note: are you user perfunction on GH?




Top
                 

god xor reason
god xor reason
Joined: 08 Dec 1999
Posts: 21100
PostPosted: 09-27-2010 09:15 AM           Profile   Send private message  E-mail  Edit post Reply with quote


That'd be me. I wish they let you have a private repo or two on the free account :(




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-27-2010 11:26 AM           Profile Send private message  E-mail  Edit post Reply with quote


Stalker. <3

I think Gitorious lets you host private repositories but it's not nearly as vibrant as GH. Unfuddle too, though it's targeted at team-based collaboration (but don't let that stop you).




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-27-2010 11:12 PM           Profile   Send private message  E-mail  Edit post Reply with quote


I got an Unfuddle account but it's set up as SVN repo. The free Unfuddle accounts only allow one user per repository though I think and it's not really fast.




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 09-28-2010 01:09 AM           Profile Send private message  E-mail  Edit post Reply with quote


No, you can have multiple users (I use it for some collaborative freelance work) but you can only have one project.

As to speed, that's why you should use git!




Top
                 

Cool #9
Cool #9
Joined: 01 Dec 2000
Posts: 44138
PostPosted: 09-28-2010 01:48 AM           Profile   Send private message  E-mail  Edit post Reply with quote


lol in their case I think it's a network issue. Google Code is much faster.




Top
                 

god xor reason
god xor reason
Joined: 08 Dec 1999
Posts: 21100
PostPosted: 09-29-2010 06:47 AM           Profile   Send private message  E-mail  Edit post Reply with quote


Just found this. Trying it out.

https://bitbucket.org/




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.