Nexgen Auto Team Balancer v0.33 (NexgenATB) for Nexgen112R
==================================================

Nexgen Auto Team Balancer (NexgenATB) is a rewritten version of nogginBasher's
AutoTeamBalance for the Nexgen Server Controller, originally by Sp0ngeb0b.
v0.33 is a revision by SC]-[LONG_{HoF}, 2026.
Built on Nexgen v112R.


What it does
------------
- Every player gets a "strength" value, learned from their scores over time.
- At game start all players are sorted by strength and split into two even teams.
- Players who join mid-game are placed on the weaker team (and may be swapped
  with the newest player of the other team if that balances better).
- If the team sizes drift more than 1 player apart, a player is moved to fix it.
- At the end of each game the strengths are updated and saved.

Works with Nexgen-supported team games with exactly 2 teams (e.g. CTF).
Nexgen's built-in team balancer is replaced by NexgenATB while it is active.


Installation
------------
This is a SERVER-SIDE ONLY plugin. Clients never download anything. The package
is always named NexgenATB.u; do not rename it.

Add the following line to your UnrealTournament.ini file:

    ServerActors=NexgenATB.NexgenATB

This line must be placed directly after the ServerActors=Nexgen112R.NexgenActor
line. If it is not, the log will warn you about the ServerActor order.

Do NOT add it as a ServerPackage!

Compile it against the Nexgen version you run; do not copy the .u between
different Nexgen versions.


Requirements
------------
- The Nexgen option "Let Nexgen handle the game start" (enableNexgenStartControl)
  must be enabled, otherwise NexgenATB stays inactive.
- The plugin is automatically disabled for the current game when Nexgen match
  mode or tournament mode is active.


Configuration
-------------
NexgenATB has deliberately few options to keep it easy to use. The settings are
stored in NexgenATB.ini (section [NexgenATB.NexgenATBConfigExt]) when Nexgen uses
external config files, otherwise in the server's main ini. Missing options are
added with their default values the first time v0.33 runs.

Variable                    Type   Default  Description
--------------------------  -----  -------  --------------------------------------------
defaultStrength             int    30       Strength new (unknown) players start with.
teamScoreBonus              int    10       Extra strength per team score point (e.g.
                                            per flag capture), so the team that is
                                            currently ahead counts as stronger.
winningTeamBonus            int    5        Extra score added to the strength calculation
                                            for players who finish on the winning team.
bFlashStrengthOnAssignment  bool   True     Shows players "<name>, your current strength
                                            is N." while they wait for a team.
bPreferNewestJoinerSwap     bool   True     When a single player joins mid-game, swap
                                            them with the newest player of the other
                                            team if that clearly improves the balance.
pruneDaysInactive           int    90       Players not seen for this many days are
                                            removed from the database at map start.
                                            0 = never remove anyone.
startSound, playSound,      string (empty)  Optional sounds (package.name) played when
teamSound[0], teamSound[1]                  teams are assigned / the game starts / a
                                            player is put on Red or Blue.

Do not change lastInstalledVersion; it is used for automatic updates.


Player database
---------------
Strengths are saved in the same ini as playerData[0..2047], one line per player:

    playerData[n]=<Nexgen ID>,<strength>,<seconds played>,<date last updated>

- Up to 2048 players are stored. Entries of players who have not played for
  pruneDaysInactive days are removed when a map starts, and the list is
  compacted. Entries of players who never stayed long enough to be rated
  (ID only, no stats) are removed too. The log shows how many entries are used.
- BACK UP THE INI BEFORE UPDATING: pruning cannot be undone.
- To reset a player's strength, edit the strength number in his line. Do not
  leave blank lines between entries; the lookup stops at the first empty slot.
- A player's strength is only updated after at least 90 seconds of play, the
  winning team bonus needs at least 180 seconds. Only roughly the last 4 hours of
  play count when old and new strength are blended, so strengths follow current
  form.
- Players are identified by their Nexgen ID. A player who resets his Nexgen ID
  starts again as a new player with the default strength.


Usage
-----
The following commands can be typed into chat by anyone (not case sensitive):

Command            Abbreviation  Description
-----------------  ------------  ----------------------------------------------
!teams             !team, !t     Shows the current accumulated team strengths,
                                 including the team score bonus.
!strengths         !str          Prints detailed strength info for each player.
!atb                             Shows whether mid-game balancing is ON or OFF.

Admin commands (need Moderator, Match Admin or Server Admin rights in Nexgen):

!atb off                         Pauses mid-game balancing for the rest of the map:
                                 no more size rebalancing and no joiner swaps.
                                 New players still get a team, and strengths are
                                 still tracked and saved at the end of the game.
!atb on                          Resumes balancing. If the teams are already more
                                 than 1 player apart it can rebalance at once.

Every !atb on/off is written to the server log (admin name and Nexgen ID) and
announced to the players. The setting is not saved; balancing is active again
on the next map.


Notes
-----
- The plugin cannot be disabled permanently mid-game other than with !atb off.
  To turn it off for good, disable "Let Nexgen handle the game start" in Nexgen;
  NexgenATB will then be disabled after the next map change.
- A player who disconnects keeps his team for a few seconds; teams are not
  rebalanced during that time in case he reconnects.


Credits
-------
Nexgen Auto Team Balancer: Patrick "Sp0ngeb0b" Peltzer (2020)
Based on AutoTeamBalance by nogginBasher
v0.33 revision: SC]-[LONG_{HoF} (2026)
Released under the Open Unreal Mod License version 1.1.
