Skip to content

Instantly share code, notes, and snippets.

@Slayer95
Created November 2, 2024 15:17
Show Gist options
  • Select an option

  • Save Slayer95/a15fc75f38d0b3fdf356613ede96cf7f to your computer and use it in GitHub Desktop.

Select an option

Save Slayer95/a15fc75f38d0b3fdf356613ede96cf7f to your computer and use it in GitHub Desktop.
HCL vJASS Library
// Starting from version 14.0, GHost++ supports transfer of a limited amount of data to a map that supports the HCL standard.
//
//The transferred data is used differently in each map and, in principle, should not have the same meaning for different maps. Maps are supposed to use the HCL system to allow the bot to install mods or other "start" information that should not be specified by players. For example, when automatically creating DotA games, it is desirable that the mod be installed on the bot and not specified by the players.
//
// Now let's see how it works:
// Find a map that supports the HCL standard.
// At the time of writing this, no maps support the HCL standard although DotA will support this standard in the future.
// Set the "HCL Command Line" (information sent to the map) using the !hcl command in the game lobby.
// The HCL command line can only contain one value per player and/or computer when the game starts.
// It can also contain a limited set of characters (lowercase letters, numbers, and a small number of special characters).
// For example, with 4 players (or 3 players and 1 computer, etc.) the HCL command line can be 4 characters long.
// The HCL command line has different meaning for different maps so you need to know which HCL data for which map means what before using it.
// Use !clearhcl to clear the HCL Command Line if you specified data and change your mind.
// Start the game.
//
//The HCL system works through the player's handicap information in such a way that after loading the map they are restored. This means that if you try to install HCL command line on a map that does not support the standard, the bot will radically change the players' handicaps. In any case, a map that does not support the standard will not restore the original handicaps and the game will be ruined. Therefore, do not even try to install HCL command line on a map that does not support the HCL standard.
//
// If you want to install HCL for each game automatically (for example, when you use autohosting):
// Create a map configuration file for the map you want to use.
// Set "map_defaulthcl=<anything>" in your map config file.
// Load it using the !load command.
// Start autohosting using the !autohost command. The bot will use the default HCL value specified in your map configuration file.
// Note that this method of installing HCL is rather clunky and may be changed in future versions of GHost++.
//
// Tip: You may want to include the HCL system in your map, even if you do not intend to use the HCL Command Line anywhere. This is because enabling the HCL system will protect your map from accidental violation of player handicaps by installing HCL Command Line on an unsupported map.
///////////////////////////////////////////
/// HostBot Command Library
/// Last Modified: September 14, 2009
/// Authors: Strilanc,
/// v1.01
///////////////////////////////////////////
/// Reads a command string transparently encoded into player handicaps by hostbots.
/// Allows at most one character from "abcdefghijklmnopqrstuvwxyz0123456789 -=,." per player.
/// Empty slots don't count towards the player count, but computers do.
///////////////////////////////////////////
library HCL initializer init
globals
private string command = ""
endglobals
public function GetCommandString takes nothing returns string
return command
endfunction
private function init takes nothing returns nothing
local integer i
local integer j
local integer h
local integer v
local string chars = "abcdefghijklmnopqrstuvwxyz0123456789 -=,."
local integer array map
local boolean array blocked
//precompute mapping [have to avoid invalid and normal handicaps]
set blocked[0] = true
set blocked[50] = true
set blocked[60] = true
set blocked[70] = true
set blocked[80] = true
set blocked[90] = true
set blocked[100] = true
set i = 0
set j = 0
loop
if blocked[j] then
set j = j + 1
endif
exitwhen j >= 256
set map[j] = i
set i = i + 1
set j = j + 1
endloop
//Extract command string from player handicaps
set i = 0
loop
exitwhen i >= 12
set h = R2I(100*GetPlayerHandicap(Player(i)) + 0.5)
if not blocked[h] then
set h = map[h]
set v = h/6
set h = h-v*6
call SetPlayerHandicap(Player(i), 0.5 + h/10.0)
set command = command + SubString(chars, v, v+1)
endif
set i = i + 1
endloop
endfunction
endlibrary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment