Good tutorials to start with?
Good tutorials to start with?
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.
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.
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
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. =)
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. =)
Re: Good tutorials to start with?
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).
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
Heh, the perils of parenthood. Fortunately, they do nothing but sleep for the first couple of months.
Re: Good tutorials to start with?
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?
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?
Re: Good tutorials to start with?
Ahah, so far I've managed to implement all basic functions required for this mod:
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
- 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.
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

Last edited by Eraser on Fri Sep 03, 2010 2:34 pm, edited 1 time in total.
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
Check out PM_Weapon() in bg_pmove.c.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).
Re: Good tutorials to start with?
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?
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?
Re: Good tutorials to start with?
Ooh, I got the batch files to compile my qvm's finally 

-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
No, but it's pretty easy to do: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?
Code: Select all
trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " is owning you like mad.\n\"", client->pers.netname) );
Re: Good tutorials to start with?
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?

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?
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
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).
Re: Good tutorials to start with?
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:
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.
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: Select all
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;
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
Correct. The trap is handled in server/sv_game.c, that delegates it to the code in botlib/ (probably be_ai_weap.c).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?
Re: Good tutorials to start with?
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
http://eoc.byethost5.com/index.php?p=misc/wofreloaded
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
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.
On an unrelated note, have you tried git yet? All the cool kids are on GitHub these days, you know.
-
- Posts: 2237
- Joined: Sat Mar 12, 2005 10:49 pm
Re: Good tutorials to start with?
This man speaks truth.^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.
I

Re: Good tutorials to start with?
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?

Does it really bring anything useful new features to the table for one-man projects?
-
- Posts: 2237
- Joined: Sat Mar 12, 2005 10:49 pm
Re: Good tutorials to start with?
One word - Branching.
If you don't love branching yet, that's because you haven't used git.
If you don't love branching yet, that's because you haven't used git.

-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
Branching and forking. It makes it much, much easier for people to participate.
Re: Good tutorials to start with?
But SVN does these things too...?
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
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.
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.
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
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.
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.
-
- Posts: 4022
- Joined: Sat Mar 12, 2005 6:24 pm
Re: Good tutorials to start with?
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!
-
- Posts: 2237
- Joined: Sat Mar 12, 2005 10:49 pm
Re: Good tutorials to start with?
misantropia - that infinite adaptive mario repo on your github page was originally done by a guy studying at the university in my hometown 
