CTF 4.2 Randomize Levels Mod
============================

This mod to CTF is given freely to the Quake community.  It isn't really
CTF specific, but that's all my server runs.  Feel free to port this
code to 'normal' QuakeWorld, or any of your other mods.

This is a 'randomize' mod.  The server ops decide which groups of maps
to run on their servers, by episode or (roughly) by size.  This mod then
takes care of all the work, picking a level by random, never choosing the
same level twice in a row.

An example of how this can be used is for a server op who only wants to
run normal CTF maps, and none of the converted id levels.  (and thus be
able to reclaim about 40 Meg of space back for your hard drive!)

As a bonus, this mod is 100% backward compatible with normal CTF.  If
you want to allow episode voting for a while, you can, and without having
to mess around with extra copies of 'qwprogs.dat' hanging around.


Features
========
As an added bonus, in addition to randomized maps, this mod to CTF gives
both QuakeWorld and normal Quake a minor bugfix, and some new features.

1) The bugfix: In the current CTF 4.2, and all previous versions,
   whenever a player captures the flag the server cycles through every
   player in the world three times quickly in a row.  Once to give
   bonus points, once to add up the team scores, and once to inform
   everybody about the capture.  If your server is really busy, this can
   cause it to stop responding to all events.

   This mod combines all three loops into one bigger loop.  My server
   has now been running continuously without crashing or locking up for
   10 days, a new record!

2) A new map has been modified for CTF support, namely Shub Niggurath's
   Pit.  It's a little weird, with the blue flag sitting underwater, but
   it is still a hell of a lot of fun.

3) If a player dies before their Quad damage or Ring of invisibility is
   completely used up, you can set up your server to drop the item with
   the remaining time.

4) The new QuakeWorld 2.0+ has some new features that I've ported back
   to CTF.  Players with the Quad/666 powerups now glow blue/red if you
   have GL quakeworld.  The flags, when not being carried, also glow
   their respective colors.  (If they glowed while the player was carrying
   them, this could easily be confused with quad/666 powerups, so I didn't
   do it.)  A new 'localinfo' feature allows server ops to pick a map
   cycle, to (say) skip over unwanted maps.  The 'rj' variable can be
   used to adjust rocket jumping height.  Deathmatch 4 rules have been
   implemented.

5) Gravity works right again with QuakeWorld 2+, and I've reinserted
   map e1m8 into the map cycle.

6) Server admins can now opt to allow rune dropping (with impulse 181),
   ban runes, or have the original runes from CTF 4.2.


New Feature
===========
I have undertaken the task of trying to eliminate the server lockups
that occasionally happen when a player captures the flag.  To this end,
I have much reduced the CPU usage of the server, and eliminated many of
the redundant status bar updates.

If you examine carefully the differences between ctf-rand.zip and
ctfrand2.zip, you'll find this trend:

  * procedures exiting sooner, with most common possibilities first
  * non-critical procedures being called less often
  * some sprint messages removed, some loops removed

And as a bonus, not a single change affects the actual gameplay.  Other
than perhaps helping to improve response time to the players.

Unfortunately, most of these changes couldn't also be implemented in
normal Quake CTF, so only the QuakeWorld CTF has been updated.  Sorry.

A 10-player game on map ctf2m1, on my Pentium-100, now only takes up
30%-40% of the CPU.  So far so good..


Setup
=====
First you'll need to put in the entities for two maps:  end and e4m8.
The first one is a mod to Shub's Pit, recently converted.  The other
map, e4m8, had a tendency to crash on my own server because of one of
the teleporters.

If your server will only be running normal CTF maps, then you can skip
this section altogether.  Everybody else will have already followed
Zoid's instructions to modify all the other maps.

Full instructions for extracting the *.bsp files and modifying the
entities for CTF support are in Zoid's original distribution for CTF, in
the file called 'server.txt'.

Essentially, just copy the end.ent file and the new e4m8.ent file into
your quake\ctf\maps directory, and re-run the dobsp.sh file.


Usage
=====
You control the sets of levels to run entirely with the 'samelevel'
variable.  If you leave it set at 0, 1, 2, or 3, then it behaves exactly
the same as vanilla CTF.  (ie. either stay at the same level forever, or
else cycle through maps in the episodes and then go back to voting.)

I have implemented 4 different methods of random map picking:

value  method
-----  ------
0      Choose by episode.
1      Choose by episode, double the probability for CTF maps.  This
       brings the probability of a native CTF map up to nearly 50%, when
       all episodes are selected.
2      Choose episodes of roughly the same map size.
3      A custom mapset

Episodes are chosen bit-wise as follows.  For methods 0,1:

value  episode
-----  -------
4      Episode 1 (plus the 'end' map)
8      Episode 2
16     Episode 3
32     Episode 4
64     Deathmatch levels
128    CTF1 to CTF8
256    CTF2M1 to CTF2M8


For method 2, I sorted the maps by actual size of the bsp.  Along with
the advice of Dr.DooM, some of them were moved around a little bit.

value  maps
-----  ----
4      tiny maps:     dm1 dm2 dm4 end e3m3 ctf2
8      mini maps:     dm6 e1m6 e3m2 e3m7 ctf4 ctf7 ctf8
16     small maps:    dm3 e1m3 e2m6 e4m6 e4m8 ctf1 ctf2m2 ctf2m3
32     medium maps:   e1m2 e1m5 e2m2 e2m3 e2m4 e4m3 e4m4 e4m5
64     big maps:      e1m1 e2m1 e2m5 e2m7 e3m1 e3m4 e3m6 ctf3
128    huge maps:     e1m4 e3m5 e4m7 ctf5 ctf6 ctf2m1 ctf2m7 ctf2m8
256    gigantic maps: e4m1 e4m2 ctf2m4 ctf2m5 ctf2m6


To pick the maps you want, add up the values for both the method and the
episodes you want to include.  Use that number for the samelevel
variable.

Example:

    Episode 2, the Deathmatch levels, and the old CTF maps, with twice
    the probability for CTF maps.  This works out to:

      1  - pick by episode, CTF with 2X probability
      8  - episode 2
     64  - deathmatch
    128  - old CTF
    ===
    201  total
      
So you would set your server up with 'samelevel 201'.


I also included a fourth set of maps to randomize:  all of the old CTF1
to CTF8 maps, all the new CTF2 maps except the three gigantic ones, and
the end map.  You can pick this mapset by setting 'samelevel 7'.

Unfortunately, if you want to change this custom mapset, you have to
roll up your sleeves and dig into the QuakeC code.  Sorry, nothing I
could do to help you on that one..


Quad/Ring Dropping
==================
In QuakeWorld, setting up your server to allow the dropping of these
items is easy.  To allow quad dropping use 'serverinfo dq 1', and to
allow ring dropping use 'serverinfo dr 1'.

In normal Quake, it is a little more complicated, since you can only set
one extra variable called 'temp1'.  To allow the dropping of both items,
use 'temp1 24'.  To allow just quad dropping, use 'temp1 8'.  To allow
just ring dropping, use 'temp1 16'.  And to allow neither, use 'temp1 0'.


Map Cycling
===========
Server ops now have the ability to pick a set of maps to cycle through,
independent of any other map mods, such as my own random maps.  You do
this by using a series of commands 'localinfo currentmap nextmap'.

The appropriate lines from my own server.cfg file look like this:

samelevel "0"
localinfo  ctf2m1  ctf6
localinfo  ctf6    ctf2m3
localinfo  ctf2m3  ctf3
localinfo  ctf3    ctf2m8
localinfo  ctf2m8  ctf1
localinfo  ctf1    end
localinfo  end     ctf8
localinfo  ctf8    ctf2m2
localinfo  ctf2m2  ctf5
localinfo  ctf5    ctf2m7
localinfo  ctf2m7  ctf7
localinfo  ctf7    ctf4
localinfo  ctf4    ctf2m1

You have to make sure that the set of maps form a complete loop, or else
the server will revert back to normal map cycling.  But you can use this
to your own advantage to, for example, skip over certain maps that you
don't want to run on your server.

For example, you could use these lines:

samelevel 0
localinfo ctf1 ctf3
localinfo ctf2m3 ctf2m7

to skip over maps ctf2, ctf2m4, ctf2m5, and ctf2m6.  Map ctf2 has a bug
in it, only showing up in quakeworld, where players keep respawning into
points where they are stuck in the floor unable to move.  And the other
three maps are often way too large to work well on low-powered CPU's
like my own Pentium-100.


Rocket Jumping
==============
The serverinfo variable 'rj' is used to adjust the height attained by
rocket jumping.  By default this value is zero, and has no effect.  To
double the height, for example, use 'serverinfo rj 1'.


Deathmatch 4 Rules
==================
Personally, I don't really think these rules work well with CTF.  But
you might have a different opinion, or maybe just want to play with them
for a while.  In any case, you can enable DM4 rules with the command:

    deathmatch 4

One issue at dispute in DM4 rules is the inclusion/exclusion of the
Grenade Launcher.  By default in the original DM4 rules released with
QW2+, players don't even get the GL.  And if by some miracle the player
manages to get a GL, the quakec code gives the player 10 points of
damage for every grenade shot.

They removed it because they feel the GL is a "wuss's camping weapon".
But as all of us Capture The Flag players know, the idea of 'camping'
goes out the window and into the backyard of 'strategy'.

So I've made a compromise.  You can disable the GL entirely in DM4 if
you want, or you can enable it with any of 3 modes

    localinfo use_grenades 0  - no GL in DM4 mode
    localinfo use_grenades 1  - GL, but player takes 10 points of damage
                                per grenade shot
    localinfo use_grenades 2  - GL, but player takes 1 point of damage
                                per grenade shot
    localinfo use_grenades 3  - GL, no damage to player

By default, if you don't define the 'use_grenades' variable, then there
will be no GL in the DM4 mode.

Server admins who want the GL without causing damage, but want to
improve the idea of 'teamplay' and of 'strategy' can always turn on
damage to team members.  (Docs for that are all in the original CTF doc
file 'server.txt'.)


Rune Dropping
=============
There are now three modes for the server admin to choose from:

    localinfo rune_mode 0  - normal runes.  This is the original rune mode
                             from Zoid's CTF 4.2.
    localinfo rune_mode 1  - rune dropping.  Players can use 'impulse 181'
                             to drop their current rune.  The rune is
                             respawned randomly into the map.
    localinfo rune_mode 2  - no runes

By default, if the 'rune_mode' variable is not defined, the original CTF
mode with runes but not allowing rune dropping is used.

You can switch between modes '0' and '1' on the fly.  But in order to
switch between rune and runeless modes, you need to switch levels once.


Porting
=======
If you want to port my randomize code into your own mod, or into vanilla
QuakeWorld, all of the necessary changes are in the 'client.qc' file.

There was also a minor change in the GotoNextMap function, to allow for the
'end' map.  Everything else is in the NextLevel function.

I also made a minor change to the 'status.qc' file and the 'teamplay.qc'
file.  For some reason, whenever the flag was captured, the server would
cycle through all the players in the game three times in a row:  once to
give players bonus points (ie. assists), once to add up all the team
scores, and once to inform the players about the capture.  I put all of
those functions into one single loop, which will hopefully help to
prevent a server lockup in a busy game when somebody captures the flag.


Updates
=======
Current versions, if I need to change anything, will be available at

      my randomize page.

Other ports of this code should be available at:

      the MidNight CTF page.