Code3Arena

PlanetQuake | Code3Arena | Tutorials | << Prev | Tutorial 4 | Next >>

menu

  • Home/News
  • ModSource
  • Compiling
  • Help!!!
  • Submission
  • Contributors
  • Staff
  • Downloads

    Tutorials
    < Index >
    1. Mod making 101
    2. Up 'n running
    3. Hello, QWorld!
    4. Infinite Haste
    5. Armor Piercing Rails
    6. Bouncing Rockets
    7. Cloaking
    8. Ladders
    9. Favourite Server
    10. Flame Thrower
    11. Vortex Grenades
    12. Grapple
    13. Lightning Discharge
    14. Locational Damage
    15. Leg Shots
    16. Weapon Switching
    17. Scoreboard frag-rate
    18. Vortex Grenades II
    19. Vulnerable Missiles
    20. Creating Classes
    21. Scrolling Credits
    22. Weapon Dropping
    23. Anti-Gravity Boots
    24. HUD scoreboard
    25. Flashlight and laser
    26. Weapon Positioning
    27. Weapon Reloading
    28. Progressive Zooming
    29. Rotating Doors
    30. Beheading (headshot!)
    31. Alt Weapon Fire
    32. Popup Menus I
    33. Popup Menus II
    34. Cluster Grenades
    35. Homing Rockets
    36. Spreadfire Powerup
    37. Instagib gameplay
    38. Accelerating rockets
    39. Server only Instagib
    40. Advanced Grapple Hook
    41. Unlagging your mod


    Articles
    < Index >
    1. Entities
    2. Vectors
    3. Good Coding
    4. Compilers I
    5. Compilers II
    6. UI Menu Primer I
    7. UI Menu Primer II
    8. UI Menu Primer III
    9. QVM Communication, Cvars, commands
    10. Metrowerks CodeWarrior
    11. 1.27g code, bugs, batch


    Links

  • Quake3 Files
  • Quake3 Forums
  • Q3A Editing Message Board
  • Quake3 Editing


    Feedback

  • SumFuka
  • Calrathan
  • HypoThermia
  • WarZone





    Site Design by:
    ICEmosis Design


  •  
    TUTORIAL 4 - Permanent Haste
    by SumFuka

    Ok, from now on we'll be learning more and more about the quake world. However you'll need some basic knowledge about coding in C. If you're a newbie C programmer, why not grab yourself a book on C programming ? Or even better, have a surf around - there are some great online resources available.

    As luck would have it, there are some C-coding tutorials at our 'predecessor' site for quake2 coding (thanks, Puke !). Cruise by QDeveLS and have a read for yourself. There are heaps of tutorials for quake2 coding there also. Whilst you can't follow those tutorials for quake3 mod making, you might get some neat ideas by browsing through them.

    Time to start coding again, "Innit".

    1. HOW DID THEY DO THAT ??

    (As always, I assume you're ready to rock in MSVC and you are working in the quake3\mymod directory.)

    Now, let's start with some Sherlock Holmes work... let's find out how a particular feature is implemented in the code base. Umm... erm... how about the Haste rune ? Ok. Let's do a "Find in Files" for 'Haste' (on the toolbar there is a little yellow folder icon with binoculars - use this if you like). The bottom pane of the screen will search thru all the source and header files for lines containing 'haste'. (you can enlarge this pane by dragging the top border upwards).

    Searching for 'Haste'...
    D:\q3\source\game\ai_chat.c(349):		bs->inventory[INVENTORY_HASTE] ||
    D:\q3\source\game\ai_dmq3.c(564):	bs->inventory[INVENTORY_HASTE] =
    bs->cur_ps.powerups[PW_HASTE] != 0;
    D:\q3\source\game\bg_misc.c(536):/*QUAKED item_haste (.3 .3 1) (-16 -16 -16) (16 16 16)
    suspended
    D:\q3\source\game\bg_misc.c(539):		"item_haste",
    D:\q3\source\game\bg_misc.c(540):		"sound/items/haste.wav",
    D:\q3\source\game\bg_misc.c(541):        { "models/powerups/instant/haste.md3", 
    D:\q3\source\game\bg_misc.c(542):		"models/powerups/instant/haste_ring.md3", 
    D:\q3\source\game\bg_misc.c(544):/* icon */		"icons/haste",
    D:\q3\source\game\bg_misc.c(548):		PW_HASTE,
    D:\q3\source\game\bg_pmove.c(1568):	if ( pm->ps->powerups[PW_HASTE] ) {
    D:\q3\source\game\bg_public.h(214):	PW_HASTE,
    D:\q3\source\game\g_active.c(604):	if ( client->ps.powerups[PW_HASTE] ) {
    D:\q3\source\game\inv.h(34):#define INVENTORY_HASTE				29
    D:\q3\source\game\inv.h(79):#define MODELINDEX_HASTE			30
    14 occurrence(s) have been found.
    
    Ok, there is some interesting stuff in here. The bit that says "item_haste" probably defines the attributes for the Haste icon. In fact, the "models/powerups/instant/haste.md3" defines which model represents the Haste icon. Let's keep looking down... there are two lines that say if ( blah blah [PW_HASTE]). That's interesting, because the if statement is probably saying "if the player has the Haste rune then do something, else if not, do something else". Double click on this line (in the 'Find in Files 1' pane) :
     D:\q3\source\game\g_active.c(604):	if ( client->ps.powerups[PW_HASTE] ) {
    
    Bang, g_active.c should open in your editor window and line 604 will have a little marker next to it. You should see this :
    	if ( client->ps.powerups[PW_HASTE] ) {
    		client->ps.speed *= 1.3;
    	}
    
    Some C programming knowledge is required here : An if statement is always in the form "if ( this_is_true) { then_do_this_stuff; }". The "*=" operator means to multiply the thing on the left by the thing on the right. In other words, "multiply client->ps.speed by 1.3".

    If we have a look up and down, we can see that this code segment is somewhere in the middle of the ClientThink_real function. We've just discovered the piece of code that makes you move faster when you have the haste rune! Additionally, we can see that you move exactly 30% faster than normal (they didn't tell us that in the manual). "Elementary, my dear Watson."

    2. LET'S MAKE A CHANGE

    Ok, let's give ourselves permanent haste. Modify the code at line 604 so that it looks like this :
    	if ( qtrue ) {
    		client->ps.speed *= 1.3;
    	}
    
    The bit that speeds us up (client->ps.speed *= 1.3;) is no longer executed 'only when the player has the Haste rune'. Because we have set the if condition to always be true (using the constant qtrue), the speedup is *always* executed, regardless of Haste runes. In other words : every player has permanent Haste. Compile it and have a bash with the bots !

    Hint: don't play this mod for too long... you might get a little dizzy.

    [ << Prev ] [ Home ] [ Next >> ]

    PlanetQuake | Code3Arena | Tutorials | << Prev | Tutorial 4 | Next >>