Documentation for WGMap

class WGLib.WGMap

load, save, store and access a WarGear map The map state is represented internally by an XML DOM.

addBorder(fromIdentifier, toIdentifier, direction='Two-way', type='Default', ftattackmod='0', ftdefendmod='0', tfattackmod='0', tfdefendmod='0', ftattackmin='0', ftdefendmin='0', tfattackmin='0', tfdefendmin='0')

Adds borders based upon names or territory IDs. Arguments correspond to attributes of the new border element.

Args:
from/to Identifiers: can be a Name or territory ID, but both must be the same

Note

a “borders” element is created if it does not already exist

Warning

If your territory names are integers, they will get treated as tid attributes, so don’t do this!!

addBorders(fromRegex, toRegex, direction='Two-way', type='Default', ftattackmod='0', ftdefendmod='0', tfattackmod='0', tfdefendmod='0', ftattackmin='0', ftdefendmin='0', tfattackmin='0', tfdefendmin='0')
Adds borders between every country that matches the fromRegex to every country that matches the toRegex.
addContinent(continentName, memberIDsString, bonus=1)

Adds a continent. Arguments correspond to attributes of the new continent element.

Note

a “continents” element is created if it does not already exist

addContinentFromElements(continentName, territoryElementList, bonus=1)

Adds a continent. Arguments correspond to attributes of the new continent element.

Note

a “continents” element is created if it does not already exist

addTerritory(name, xpos, ypos, maxUnits='')

Adds a territory. Arguments correspond to attributes of the new territory element.

Note

a “territories” element is created if it does not already exist

calculateTotalBoardBonus()
calculateTotalBoardBonus
calculateTotalContinentBonus()
calculateTotalContinentBonus
calculateTotalTerritoryBonus()
calculateTotalTerritoryBonus
checkOneTerritoryCanReachAll(territoryID=None)

Test if the specified territory can reach all other territories.

Args: territoryID (int): The territory ID for testing. If no territory ID is given, the first territory in the DOM is used.

countContinentsWithBonus(numBonus)
countTerritoriesWithBorders(numBorders, direction='Two-way')
createBoard(boardName, versionMaj='1', versionMin='0', minPlayers='2', maxPlayers='16', availablePlayers='2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 16', gameplayType='Turn Based')

Add a <board> element to the DOM.

note: all arguments are strings note: some problems? Better to create a new board on wargear.net, export the XML, and use loadMapFromFile()

deleteEmptyContinents()
Find all continents with no members
deleteTerritory(identifier)

Delete a territory.

Args:
identifier can be a Name or ID
doTheyBorder(ID1, ID2)
Return true if the territories identified by ID1 & ID2 share a border. False otherwise
getBorderCount(territoryID)
returns the # of borders that a territory identified by territoryID has
getBorderCounts(direction='Two-way')
Returns:
dictionary w/ key=territoryName & value=count of their borders
Args:
direction (int): A string describing the type of neighbor to find. Valid values:
“to” “from” “either”

Warning

direction is currently ignored

getContinentFromMembers(neighborElementList)
Args:
neigbhorElementList (list): A list of neighbor elements to compare against.
Returns:
The first continentElement that has the same neighbors as the neighborElementList (or None)
getContinentsWithTerritory(territoryID)
Args:
territoryID (int): A territory ID to look for.
Returns:
A set of all continentElements that have territoryID as a member.
getLargestBonusContinent()
Returns:
continentName with the largest bonus & that bonus

Note

In the case of a tie, one of the winners will be returned arbitrarily

getMinContinentSize(territoryName)

Find the smallest continent that territoryName is a member of.

Args:
territoryName (str): The territory name to look for.
getMostBorderedTerritory(direction='Two-way')
Returns:
territoryName with the most borders & number of borders
Args:
direction (int): A string describing the type of neighbor to find. Valid values::
“to” “from” “either”

Note

In the case of a tie, one of the winners will be returned arbitrarily

Warning

direction is currently ignored

getNeighborIDsFromID(territoryID, direction='either', neighborRegex='.*')

Given territoryID return all IDs of all other territories that share a border with it.

Args:
territoryID (int): The ID for which neighbors are found. direction (int): A string describing the type of neighbor to find. Valid values: * to * from * either neighborRegex (str): Only include neighbors in the returned set if their name matches this regex.

Warning

direction is not working(?)

getNeighbors(territoryElement, direction='either', neighborRegex='.*')

Get a list of the IDs of the neighbors of a territory that match the neigborRegex.

Args:
territoryElement (DOMElement): The territory to find neighbors for. direction (string): valid values: “to”, “from”, or “either” neigborRegex (str): neigbors that do not match this are not added to the list.
getNeighborsFromID(territoryID, direction='either', neighborRegex='.*')

Given territoryID return all IDs of all other territories that share a border with it.

Args:
territoryID (int): The ID for which neighbors are found. direction (int): A string describing the type of neighbor to find. Valid values: * to * from * either neighborRegex (str): Only include neighbors in the returned set if their name matches this regex.

Warning

direction is currently ignored

getTerritoryBorders(territoryElement)

Get a collection of borders for this territory. Args:

Identifier: can be a Name or territory ID
getTerritoryElement(identifier)

Get the territory Element based upon a name or territory ID. Args:

Identifier: can be a Name or territory ID
getTerritoryIDFromName(territoryName)

Given a territory name find the ID for that territory (or None if not found) Args:

territoryName (str): The name to look for.
getTerritoryNameFromID(territoryID)

Given a territory ID find the name for that territory (or None if not found)

Args:
territoryName (str): The name to look for.
hordify(bonus='1', continentNameSuffix='', baseRegex='.*', neighborRegex='.*', verificationMode=False)

Add continents in a “hordes” style. For all territories that match baseRegex, a continent is created whose members are the original territory and all of the neighbors who match neighborRegex.

Args:
bonus (int): The number of units a player will get for controlling this continent continentNameSuffix (str): This is added to the base territory name to get the continent name baseRegex (str): Only territorires that match this regex will have continents added. neighborRegex (str): Only neighbors that match this regex will be members of the new continents. verificationMode (bool): Verifies continent was added succesfully (for testing).
loadMapFromFile(filePath)

Loads the state of a map from an XML document.

Args: filePath (str):

printBorderDistributionTable()
Prints a table to show how many territories there are with N borders.
printContinentBonusDistributionTable()
Prints a table to show how many continents there are with a bonus of N.
printDOM()
Print the DOM to stdout in XML format.
printStatistics()
Print some statistics about a map.
saveMapToFile(filePath)

Save the XML.

Args:
filePath (str):
>>> saveMapToFile(//SERVER/path/to/map/MapName.xml)    
setAllSoleContinentTerritoriesToNeutral(neutralBase=3)
Find all continents that only have one member, and set that member to neutral Unit count is equal to the total continent bonus + neutralBase
setBoardName(boardName)
Sets the “boardname” attribute of the “board” element.
setNumAttacks(numAttacks)
Sets the ‘num_attacks’ attribute of the ‘rules’ element. numAttacks should be a number or ‘Unlimited’
setNumFortifies(numFortifies)
Sets the ‘num_fortifies’ attribute of the ‘rules’ element. numFortifies should be a number or ‘Unlimited’

Previous topic

Documentation for WGLib

Next topic

Documentation for SquareGridWGMap