// Chess Grid bits
//
// [00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22...]
// \-------/ \---/ \--------------------------------------------------------
// | | |
// | | |
// | | \_ Piece Move Count
// | |
// | \________ Piece Owner where
// | udg_chess_owner_BLACK = Player Black
// | udg_chess_owner_WHITE = Player White
// |
// \_______________ Piece Type where
// udg_chess_type_BISHOP = Bishop
// udg_chess_type_KING = King
// udg_chess_type_KNIGHT = Knight
// udg_chess_type_PAWN = Pawn
// udg_chess_type_QUEEN = Queen
// udg_chess_type_ROOK = Rook
//
// Chess Move bits
//
// [00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22...]
// \----------------/ \---------------/ \---------/
// | | |
// | | |
// | | \___ Move Type
// | |
// | \__________________ Square 2
// |
// \_____________________________________ Square 1
//
//========================================
//
// Misc. and helper functions
//
//========================================
function CreateColorInteger takes integer red, integer green, integer blue, integer alpha returns integer
return red + green * 0x100 + blue * 0x10000 + alpha * 0x1000000
endfunction
function ColorIntegerGetRed takes integer i returns integer
if i < 0 then
return ModuloInteger(i + 0x80000000, 0x100)
endif
return ModuloInteger(i, 0x100)
endfunction
function ColorIntegerGetGreen takes integer i returns integer
if i < 0 then
return ModuloInteger((i + 0x80000000) / 0x100, 0x100)
endif
return ModuloInteger(i / 0x100, 0x100)
endfunction
function ColorIntegerGetBlue takes integer i returns integer
if i < 0 then
return ModuloInteger((i + 0x80000000) / 0x10000, 0x100)
endif
return ModuloInteger(i / 0x10000, 0x100)
endfunction
function ColorIntegerGetAlpha takes integer i returns integer
if i < 0 then
return (i + 0x80000000) / 0x1000000 + 0x80
endif
return i / 0x1000000
endfunction
function ColorIntegerToColorString takes integer ci returns string
local string charMap = "0123456789abcdef"
local string cs
local integer c
if ci < 0 then
set ci = ci + 0x80000000
set c = ci / 0x10000000 + 0x8
else
set c = ci / 0x10000000
endif
set cs = SubString(charMap, c, c + 1)
set c = ModuloInteger(ci / 0x1000000, 16)
set cs = cs + SubString(charMap, c, c + 1)
set c = ModuloInteger(ci / 0x10, 16)
set cs = cs + SubString(charMap, c, c + 1)
set c = ModuloInteger(ci, 16)
set cs = cs + SubString(charMap, c, c + 1)
set c = ModuloInteger(ci / 0x1000, 16)
set cs = cs + SubString(charMap, c, c + 1)
set c = ModuloInteger(ci / 0x100, 16)
set cs = cs + SubString(charMap, c, c + 1)
set c = ModuloInteger(ci / 0x100000, 16)
set cs = cs + SubString(charMap, c, c + 1)
set c = ModuloInteger(ci / 0x10000, 16)
return cs + SubString(charMap, c, c + 1)
endfunction
function AsciiIntegerToChar takes integer i returns string
if i == 0 then
return null
elseif i >= 8 and i <= 10 then
return SubString("\b\t\n", i - 8, i - 7)
elseif i >= 12 and i <= 13 then
return SubString("\f\r", i - 12, i - 11)
elseif i >= 32 and i <= 127 then
return SubString(" !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", i - 32, i - 31)
endif
return ""
endfunction
function AsciiCharToInteger takes string char returns integer
local string charMap = " !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
local string u = SubString(char, 0, 1)
local string c
local integer i = 0
if u == "" or u == null then
return 0
endif
loop
set c = SubString(charMap, i, i + 1)
exitwhen c == ""
if c == u then
return i + 32
endif
set i = i + 1
endloop
return 0
endfunction
function AsciiStringSum takes string s returns integer
local integer i = 0
local integer n = 0
local string c
loop
set c = SubString(s, i, i + 1)
exitwhen c == ""
set n = n + AsciiCharToInteger(c)
set i = i + 1
endloop
return n
endfunction
function HighlightHotkey takes string whichString, integer hotkey, string color returns string
local string s = StringCase(whichString, true)
local string c
local string hkey = StringCase(AsciiIntegerToChar(hotkey), true)
local integer i = 0
if whichString == null or hkey == null or hkey == "" then
return whichString
elseif color == null then
set color = "ffffcc00"
elseif hkey == "" then
return whichString
endif
loop
set c = SubString(s, i, i + 1)
exitwhen c == ""
if c == hkey then
return SubString(whichString, 0, i) + "|c" + color + SubString(whichString, i, i + 1) + "|r" + SubString(whichString, i + 1, 0x10000)
endif
set i = i + 1
endloop
return whichString + " (|c" + color + hkey + "|r)"
endfunction
function ExecuteCode takes code c returns nothing
local trigger dispatcher = CreateTrigger()
call TriggerAddAction(dispatcher, c)
call TriggerExecute(dispatcher)
call DestroyTrigger(dispatcher)
set dispatcher = null
endfunction
function AddSpecialEffectPositionWithTimerForPlayer_Child takes nothing returns nothing
local string whichEffectPath = udg_parameter_string
local effect tempeffect
local real duration = bj_enumDestructableRadius
if GetLocalPlayer() != udg_parameter_player then
set whichEffectPath = ""
endif
set tempeffect = AddSpecialEffect(whichEffectPath, udg_parameter_x, udg_parameter_y)
call PolledWait(duration)
call DestroyEffect(tempeffect)
endfunction
function AddSpecialEffectPositionWithTimerForPlayer takes player whichPlayer, real x, real y, string whichEffect, real duration returns nothing
set bj_enumDestructableRadius = duration
set udg_parameter_x = x
set udg_parameter_y = y
set udg_parameter_player = whichPlayer
set udg_parameter_string = whichEffect
call ExecuteCode(function AddSpecialEffectPositionWithTimerForPlayer_Child)
endfunction
function AddSpecialEffectPositionWithTimer_Child takes nothing returns nothing
local effect tempeffect = bj_lastCreatedEffect
local real duration = bj_enumDestructableRadius
call PolledWait(duration)
call DestroyEffect(tempeffect)
endfunction
function AddSpecialEffectPositionWithTimer takes real x, real y, string whichEffect, real duration returns nothing
set bj_enumDestructableRadius = duration
set bj_lastCreatedEffect = AddSpecialEffect(whichEffect, x, y)
call ExecuteCode(function AddSpecialEffectPositionWithTimer_Child)
endfunction
function AddSpecialEffectUnitWithTimer takes unit u, string whichEffect, string whichAttach, real duration returns nothing
set bj_enumDestructableRadius = duration
set bj_lastCreatedEffect = AddSpecialEffectTarget(whichEffect, u, whichAttach)
call ExecuteCode(function AddSpecialEffectPositionWithTimer_Child)
endfunction
//========================================
//
// Mathematical and logical functions
//
//========================================
constant function ISign takes integer i returns integer
if i > 0 then
return 1
elseif i < 0 then
return -1
endif
return 0
endfunction
constant function IAbs takes integer i returns integer
if i < 0 then
return -i
endif
return i
endfunction
constant function RAbs takes real r returns real
if r < 0 then
return -r
endif
return r
endfunction
// Unsigned Integer Modulus
constant function UIMod takes integer x, integer y returns integer
return x - x / y * y
endfunction
//========================================
//
// Constant and static resource functions
//
//========================================
function GetPlayerColorColorInteger takes playercolor col returns integer
if col == PLAYER_COLOR_RED then
return(0xFF0303FF)
elseif col == PLAYER_COLOR_BLUE then
return(0xFFFF4200)
elseif col == PLAYER_COLOR_CYAN then
return(0xFFB9E61C)
elseif col == PLAYER_COLOR_PURPLE then
return(0xFF810054)
elseif col == PLAYER_COLOR_YELLOW then
return(0xFF01FCFF)
elseif col == PLAYER_COLOR_ORANGE then
return(0xFF0E8AFE)
elseif col == PLAYER_COLOR_GREEN then
return(0xFF00C020)
elseif col == PLAYER_COLOR_PINK then
return(0xFFB05BE5)
elseif col == PLAYER_COLOR_LIGHT_GRAY then
return(0xFF979695)
elseif col == PLAYER_COLOR_LIGHT_BLUE then
return(0xFFF1BF7E)
elseif col == PLAYER_COLOR_AQUA then
return(0xFF466210)
elseif col == PLAYER_COLOR_BROWN then
return(0xFF042A49)
endif
return(0xFF404040)
endfunction
function GetColoredPlayerName takes player p returns string
return "|c" + ColorIntegerToColorString(GetPlayerColorColorInteger(GetPlayerColor(p))) + GetPlayerName(p) + "|r"
endfunction
constant function isPlayerOwner takes player p returns boolean
return udg_chess_owner[0] == p or udg_chess_owner[1] == p
endfunction
constant function isPlayerObserver takes player p returns boolean
return not isPlayerOwner(p)
endfunction
constant function isOwnerUserPlayer takes integer whichOwner returns boolean
return udg_chess_owner[whichOwner - 1] != Player(PLAYER_NEUTRAL_PASSIVE)
endfunction
constant function getPlayerOwner takes player whichPlayer returns integer
if udg_chess_owner[0] == whichPlayer then
return udg_chess_owner_WHITE
elseif udg_chess_owner[1] == whichPlayer then
return udg_chess_owner_BLACK
endif
return udg_chess_owner_NONE
endfunction
constant function getOwnerPlayer takes integer owner returns player
return udg_chess_owner[owner - 1]
endfunction
constant function playerIsOwner takes player whichPlayer, integer owner returns boolean
return udg_chess_owner[owner - 1] == whichPlayer
endfunction
constant function isPlayerSinglePlayer takes player p returns boolean
return getOwnerPlayer(udg_chess_owner_WHITE) == p and getOwnerPlayer(udg_chess_owner_BLACK) == p
endfunction
constant function isGameSinglePlayer takes nothing returns boolean
return getOwnerPlayer(udg_chess_owner_WHITE) == getOwnerPlayer(udg_chess_owner_BLACK) and isOwnerUserPlayer(udg_chess_owner_WHITE)
endfunction
constant function getPieceTypeUnitType takes integer pt returns integer
if pt == udg_chess_type_BISHOP then
return udg_chess_unittype_BISHOP
elseif pt == udg_chess_type_KING then
return udg_chess_unittype_KING
elseif pt == udg_chess_type_KNIGHT then
return udg_chess_unittype_KNIGHT
elseif pt == udg_chess_type_PAWN then
return udg_chess_unittype_PAWN
elseif pt == udg_chess_type_QUEEN then
return udg_chess_unittype_QUEEN
elseif pt == udg_chess_type_ROOK then
return udg_chess_unittype_ROOK
endif
return 0
endfunction
constant function getPieceTypeNameEnglish takes integer pt returns string
if pt == udg_chess_type_BISHOP then
return "Bishop"
elseif pt == udg_chess_type_KING then
return "King"
elseif pt == udg_chess_type_KNIGHT then
return "Knight"
elseif pt == udg_chess_type_PAWN then
return "Pawn"
elseif pt == udg_chess_type_QUEEN then
return "Queen"
elseif pt == udg_chess_type_ROOK then
return "Rook"
endif
return ""
endfunction
function getOwnerName takes integer owner returns string
if isOwnerUserPlayer(owner) then
return GetPlayerName(getOwnerPlayer(owner))
elseif owner == udg_chess_owner_WHITE then
return udg_ui_string_WHITE
elseif owner == udg_chess_owner_BLACK then
return udg_ui_string_BLACK
endif
return ""
endfunction
function getPassiveOwnerName takes integer owner returns string
if owner == udg_chess_owner_WHITE then
return udg_ui_string_WHITE
elseif owner == udg_chess_owner_BLACK then
return udg_ui_string_BLACK
endif
return ""
endfunction
constant function getOwnerFacing takes integer owner returns integer
if owner == udg_chess_owner_WHITE then
return 0
elseif owner == udg_chess_owner_BLACK then
return 180
endif
return 0
endfunction
//========================================
//
// Square basic functions
//
//========================================
constant function square takes integer x, integer y returns integer
if x > 7 then
set x = 7
elseif x < 0 then
set x = 0
endif
if y > 7 then
set y = 7
elseif y < 0 then
set y = 0
endif
return x + y * 8
endfunction
function pointHasSquare takes real x, real y returns boolean
if x < GetRectMinX(udg_chess_rect) or x > GetRectMaxX(udg_chess_rect) or y < GetRectMinY(udg_chess_rect) or y > GetRectMaxY(udg_chess_rect) then
return false
endif
return true
endfunction
function squareFromPoint takes real x, real y returns integer
if not pointHasSquare(x, y) then
return -1
endif
return square(R2I((x - GetRectMinX(udg_chess_rect)) / (GetRectWidthBJ(udg_chess_rect) / 8)), R2I((y - GetRectMinY(udg_chess_rect)) / (GetRectHeightBJ(udg_chess_rect) / 8)))
endfunction
constant function getSquareX takes integer q returns integer
return UIMod(q, 8)
endfunction
constant function getSquareY takes integer q returns integer
return q / 8
endfunction
constant function getSquareDeltaY takes integer q1, integer q2 returns integer
return getSquareY(q2) - getSquareY(q1)
endfunction
constant function getSquareDeltaX takes integer q1, integer q2 returns integer
return getSquareX(q2) - getSquareX(q1)
endfunction
constant function squareIsValid takes integer q returns boolean
return q >= 0 and q < 64
endfunction
constant function projectSquare takes integer q, integer x, integer y returns integer
return square(getSquareX(q) + x, getSquareY(q) + y)
endfunction
function getSquareCenterX takes integer q returns real
local real width = GetRectWidthBJ(udg_chess_rect) / 8
return GetRectMinX(udg_chess_rect) + I2R(getSquareX(q)) * width + width / 2
endfunction
function getSquareCenterY takes integer q returns real
local real height = GetRectHeightBJ(udg_chess_rect) / 8
return GetRectMinY(udg_chess_rect) + I2R(getSquareY(q)) * height + height / 2
endfunction
function getSquareCenter takes integer q returns location
local real squareWidth = GetRectWidthBJ(udg_chess_rect) / 8
local real squareHeight = GetRectHeightBJ(udg_chess_rect) / 8
return Location(I2R(getSquareX(q)) * squareWidth + GetRectMinX(udg_chess_rect) + squareWidth / 2, I2R(getSquareY(q)) * squareHeight + GetRectMinY(udg_chess_rect) + squareHeight / 2)
endfunction
constant function getSquarePieceOwner takes integer q returns integer
return UIMod(udg_chess_grid[q] / 8, 4)
endfunction
constant function getSquarePieceType takes integer q returns integer
return UIMod(udg_chess_grid[q], 8)
endfunction
constant function getSquarePieceUnit takes integer q returns unit
return udg_chess_grid_unit[q]
endfunction
constant function getSquarePieceMoveCount takes integer q returns integer
return udg_chess_grid[q] / 32
endfunction
function setSquarePieceOwner takes integer q, integer owner returns nothing
set udg_chess_grid[q] = (udg_chess_grid[q] / 0x20 * 0x4 + owner) * 0x8 + UIMod(udg_chess_grid[q], 0x8)
endfunction
function setSquarePieceType takes integer q, integer pt returns nothing
set udg_chess_grid[q] = udg_chess_grid[q] / 0x8 * 0x8 + pt
endfunction
function setSquarePieceUnit takes integer q, unit u returns nothing
set udg_chess_grid_unit[q] = u
endfunction
function setSquarePieceMoveCount takes integer q, integer c returns nothing
set udg_chess_grid[q] = UIMod(udg_chess_grid[q], 0x20) + c * 0x20
endfunction
function increaseSquarePieceMoveCount takes integer q returns nothing
set udg_chess_grid[q] = UIMod(udg_chess_grid[q], 0x20) + ((udg_chess_grid[q] / 0x20 + 1) * 0x20) * 0x20
endfunction
constant function squareIsOccupied takes integer q returns boolean
return getSquarePieceType(q) != udg_chess_type_NONE
endfunction
constant function squareHasEnemy takes integer q, integer owner returns boolean
return squareIsOccupied(q) and getSquarePieceOwner(q) != owner
endfunction
constant function getUnitSquare takes unit u returns integer
local integer q = 0
loop
exitwhen q == 64
if getSquarePieceUnit(q) == u then
return q
endif
set q = q + 1
endloop
return -1
endfunction
function flashSquare takes integer q returns nothing
if squareIsValid(q) then
call AddSpecialEffectPositionWithTimer(getSquareCenterX(q), getSquareCenterY(q), "errorflash.mdl", 2.0)
endif
endfunction
function flashSquareForPlayer takes player whichPlayer, integer q returns nothing
if squareIsValid(q) then
call AddSpecialEffectPositionWithTimerForPlayer(whichPlayer, getSquareCenterX(q), getSquareCenterY(q), "errorflash.mdl", 2.0)
endif
endfunction
function flashPath takes integer q1, integer q2 returns nothing
local integer deltaX = getSquareX(q2) - getSquareX(q1)
local integer deltaY = getSquareY(q2) - getSquareY(q1)
local integer stepX = ISign(deltaX)
local integer stepY = ISign(deltaY)
if not (deltaX == 0 or deltaY == 0 or (IAbs(deltaX) == IAbs(deltaY))) then
return
endif
loop
call flashSquare(q1)
exitwhen q1 == q2
set q1 = projectSquare(q1, stepX, stepY)
endloop
endfunction
function flashPathForPlayer takes player whichPlayer, integer q1, integer q2 returns nothing
local integer deltaX = getSquareX(q2) - getSquareX(q1)
local integer deltaY = getSquareY(q2) - getSquareY(q1)
local integer stepX = ISign(deltaX)
local integer stepY = ISign(deltaY)
if not (deltaX == 0 or deltaY == 0 or (IAbs(deltaX) == IAbs(deltaY))) then
return
endif
loop
call flashSquareForPlayer(whichPlayer, q1)
exitwhen q1 == q2
set q1 = projectSquare(q1, stepX, stepY)
endloop
endfunction
//========================================
//
// Move basic functions
//
//========================================
constant function createMove takes integer q1, integer q2, integer mt returns integer
return q1 + q2 * 0x40 + mt * 0x1000
endfunction
constant function getMoveSquare1 takes integer m returns integer
return UIMod(m, 64)
endfunction
constant function getMoveSquare2 takes integer m returns integer
return UIMod(m / 0x40, 64)
endfunction
constant function getMoveType takes integer m returns integer
return UIMod(m / 0x1000, 16)
endfunction
constant function setMoveSquare1 takes integer m, integer q returns integer
return m / 0x40 * 0x40 + q
endfunction
constant function setMoveSquare2 takes integer m, integer q returns integer
return (m / 0x1000 * 0x40 + q) * 0x40 + UIMod(m, 0x40)
endfunction
constant function setMoveType takes integer m, integer mt returns integer
return (m / 0x10000 * 0x10 + mt) * 0x1000 + UIMod(m, 0x1000)
endfunction
function recordMove takes integer m returns nothing
set udg_chess_move_history[udg_chess_game_round] = m
set udg_chess_move_history_grid[udg_chess_game_round] = udg_chess_grid[getMoveSquare1(m)]
set udg_chess_move_history_player[udg_chess_game_round] = getOwnerPlayer(udg_chess_game_turn)
endfunction
constant function getRecordPieceOwner takes integer r returns integer
return UIMod(r / 8, 4)
endfunction
constant function getRecordPieceType takes integer r returns integer
return UIMod(r, 8)
endfunction
constant function getHistoryRecord takes integer histId returns integer
return udg_chess_move_history_grid[histId]
endfunction
function getLastMove takes nothing returns integer
if udg_chess_game_round == 0 then
return 0
endif
return udg_chess_move_history[udg_chess_game_round - 1]
endfunction
constant function directionIsValid takes integer dx, integer dy returns boolean
return (dx != 0 or dy != 0) and ((dx == 0 or dy == 0) or (IAbs(dx) == IAbs(dy)))
endfunction
constant function pathIsDiagonal takes integer q1, integer q2 returns boolean
return IAbs(getSquareX(q1) - getSquareX(q2)) == IAbs(getSquareY(q1) - getSquareY(q2))
endfunction
constant function pathIsCrossed takes integer q1, integer q2 returns boolean
return getSquareX(q1) - getSquareX(q2) == 0 or getSquareY(q1) - getSquareY(q2) == 0
endfunction
constant function pathIsValid takes integer q1, integer q2 returns boolean
return directionIsValid(getSquareDeltaX(q1, q2), getSquareDeltaY(q1, q2))
endfunction
//========================================
//
// Chess game functions
//
//========================================
function changeChessPieceType takes integer q, integer pt returns nothing
local integer owner = getSquarePieceOwner(q)
local unit u = getSquarePieceUnit(q)
local boolean array hasPlayerFocus
local integer i = 0
loop
exitwhen i == bj_MAX_PLAYERS
set hasPlayerFocus[i] = IsUnitSelected(u, Player(i))
set i = i + 1
endloop
call RemoveUnit(u)
set u = CreateUnit(udg_chess_owner[owner - 1], getPieceTypeUnitType(pt), getSquareCenterX(q), getSquareCenterY(q), getOwnerFacing(owner))
call SetUnitColor(u, udg_chess_color[owner - 1])
call setSquarePieceUnit(q, u)
call setSquarePieceType(q, pt)
call PauseUnit(u, udg_chess_game_turn != owner)
set i = 0
loop
exitwhen i == bj_MAX_PLAYERS
if hasPlayerFocus[i] and GetLocalPlayer() == Player(i) then
call SelectUnit(u, true)
endif
set i = i + 1
endloop
set u = null
endfunction
function getSquareName takes integer q returns string
local string alpha = "HGFEDCBA"
local string numeric = "12345678"
if q == -1 then
return null
endif
return SubString(alpha, getSquareY(q), getSquareY(q) + 1) + SubString(numeric, getSquareX(q), getSquareX(q) + 1)
endfunction
function getSquareByName takes string name returns integer
local string alpha = "HhGgFfEeDdCcBbAa"
local string numeric = "12345678"
local string c = SubString(name, 0, 1)
local integer x = 0
local integer y = 0
if name == "" or name == null then
return -1
endif
loop
exitwhen SubString(alpha, y, y + 1) == c
if SubString(alpha, y, y + 1) == "" then
return -1
endif
set y = y + 1
endloop
set c = SubString(name, 1, 2)
loop
exitwhen SubString(numeric, x, x + 1) == c
if SubString(numeric, x, x + 1) == "" then
return -1
endif
set x = x + 1
endloop
return square(x, y / 2)
endfunction
function pauseOwnerPieces takes integer owner, boolean pause returns nothing
local integer q = 0
loop
exitwhen q == 64
if getSquarePieceOwner(q) == owner then
call PauseUnit(getSquarePieceUnit(q), pause)
endif
set q = q + 1
endloop
endfunction
function stopSquareUnit takes integer q returns nothing
local unit u = getSquarePieceUnit(q)
local integer owner = getSquarePieceOwner(q)
call PauseUnit(u, true)
call IssueImmediateOrder(u, "stop")
call IssueImmediateOrder(u, "hold")
if udg_chess_game_turn == owner then
call PauseUnit(u, false)
endif
endfunction
function stopOwnerUnits takes integer owner returns nothing
local integer q = 0
loop
exitwhen q == 64
if getSquarePieceOwner(q) == owner then
call stopSquareUnit(q)
endif
set q = q + 1
endloop
endfunction
function createChessPiece takes integer q, integer pieceType, integer owner returns unit
local location loc
local integer utype = getPieceTypeUnitType(pieceType)
local unit piece
if getSquarePieceType(q) != udg_chess_type_NONE or utype == 0 then
return null
endif
set loc = getSquareCenter(q)
set piece = CreateUnitAtLoc(udg_chess_owner[owner - 1], utype, loc, getOwnerFacing(owner))
call SetUnitColor(piece, udg_chess_color[owner - 1])
call setSquarePieceUnit(q, piece)
call setSquarePieceType(q, pieceType)
call setSquarePieceOwner(q, owner)
call RemoveLocation(loc)
set loc = null
return piece
endfunction
function removeChessPiece takes integer q returns nothing
local unit piece = getSquarePieceUnit(q)
if piece != null then
call RemoveUnit(piece)
set piece = null
endif
set udg_chess_grid[q] = 0
set udg_chess_grid_unit[q] = null
endfunction
function clearChessGrid takes nothing returns nothing
local integer q = 0
loop
exitwhen q == 64
call removeChessPiece(q)
set q = q + 1
endloop
endfunction
function moveChessPiece takes integer q1, integer q2 returns nothing
if getSquarePieceType(q2) != udg_chess_type_NONE then
return
endif
set udg_chess_grid[q2] = udg_chess_grid[q1]
set udg_chess_grid[q1] = 0
set udg_chess_grid_unit[q2] = udg_chess_grid_unit[q1]
set udg_chess_grid_unit[q1] = null
call SetUnitPosition(udg_chess_grid_unit[q2], getSquareCenterX(q2), getSquareCenterY(q2))
endfunction
function swapChessPieces takes integer q1, integer q2 returns nothing
local integer temp = udg_chess_grid[q1]
local unit temp_unit
if q1 == q2 then
return
endif
set temp_unit = udg_chess_grid_unit[q1]
set udg_chess_grid[q1] = udg_chess_grid[q2]
set udg_chess_grid_unit[q1] = udg_chess_grid_unit[q2]
set udg_chess_grid[q2] = temp
set udg_chess_grid_unit[q2] = temp_unit
endfunction
function setOwnerUnitOwner takes integer whichOwner, player whichPlayer returns nothing
local integer q = 0
if whichOwner == udg_chess_owner_NONE then
return
endif
loop
exitwhen q == 64
if getSquarePieceOwner(q) == whichOwner then
call SetUnitOwner(getSquarePieceUnit(q), whichPlayer, false)
endif
set q = q + 1
endloop
endfunction
function setChessOwner takes integer whichOwner, player whichPlayer returns nothing
set udg_chess_owner[whichOwner - 1] = whichPlayer
call setOwnerUnitOwner(whichOwner, whichPlayer)
endfunction
function setChessOwnerPassive takes integer whichOwner returns nothing
set udg_chess_owner[whichOwner - 1] = Player(PLAYER_NEUTRAL_PASSIVE)
call setOwnerUnitOwner(whichOwner, Player(PLAYER_NEUTRAL_PASSIVE))
endfunction
function getChessOwnerColor takes integer whichOwner returns playercolor
return udg_chess_color[whichOwner - 1]
endfunction
function setChessOwnerColor takes integer whichOwner, playercolor whichPlayerColor returns nothing
local integer q = 0
set udg_chess_color[whichOwner - 1] = whichPlayerColor
loop
exitwhen q == 64
if whichOwner == getSquarePieceOwner(q) then
call SetUnitColor(getSquarePieceUnit(q), whichPlayerColor)
endif
set q = q + 1
endloop
endfunction
function getFirstPieceTypeSquare takes integer pt, integer owner returns integer
local integer q = 0
loop
exitwhen q == 64
if getSquarePieceOwner(q) == owner then
if getSquarePieceType(q) == pt then
return q
endif
endif
set q = q + 1
endloop
return -1
endfunction
//========================================
//
// Move error functions
//
//========================================
function createError takes integer q1, integer q2, integer errorType returns integer
local integer flags = 3
if q1 == -1 then
set flags = flags - 1
set q1 = 0
endif
if q2 == -1 then
set flags = flags - 2
set q2 = 0
endif
return flags + q1 * 0x4 + q2 * 0x100 + errorType * 0x4000
endfunction
function getErrorType takes integer error returns integer
return error / 0x4000
endfunction
function getErrorSquare1 takes integer error returns integer
if UIMod(error, 0x2) == 1 then
return UIMod(error / 0x4, 0x40)
endif
return -1
endfunction
function getErrorSquare2 takes integer error returns integer
if UIMod(error / 0x2, 0x2) == 1 then
return UIMod(error / 0x100, 0x40)
endif
return -1
endfunction
function getLastError takes nothing returns integer
return udg_chess_error_last
endfunction
function setLastError takes integer error returns nothing
set udg_chess_error_last = error
endfunction
function createLastError takes integer q1, integer q2, integer errorType returns nothing
set udg_chess_error_last = createError(q1, q2, errorType)
endfunction
function addModifierParameter takes integer whichParameter, string whichString returns nothing
set udg_ui_string_modifiers[whichParameter] = whichString
endfunction
function announceSimple takes string s returns nothing
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, s)
endfunction
function announceModified takes force whichForce, real duration, string message returns nothing
local integer i
local string c
local string c2
if message == "" or message == null then
return
endif
set message = StringIdentity(message)
set i = 0
loop
set c = SubString(message, i, i + 1)
exitwhen c == ""
if c == "%%" then
set c2 = SubString(message, i + 1, i + 2)
if c2 == "%%" then
set message = SubString(message, 0, i) + SubString(message, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set message = SubString(message, 0, i) + StringIdentity(udg_ui_string_modifiers[S2I(c2)]) + SubString(message, i + 2, 0x7FFFFFFF)
endif
else
set i = i + 1
endif
endloop
if whichForce == null or IsPlayerInForce(GetLocalPlayer(), whichForce) then
if duration <= 0 then
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, message)
else
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, duration, message)
endif
endif
endfunction
function announceToPlayerModified takes player whichPlayer, string message returns nothing
call announceModified(bj_FORCE_PLAYER[GetPlayerId(whichPlayer)], 0, message)
endfunction
function announceToAllPlayersModified takes string message returns nothing
call announceModified(null, 0, message)
endfunction
function announceToPlayerTimedModified takes player whichPlayer, real duration, string message returns nothing
call announceModified(bj_FORCE_PLAYER[GetPlayerId(whichPlayer)], duration, message)
endfunction
function announceToAllPlayersTimedModified takes real duration, string message returns nothing
call announceModified(null, duration, message)
endfunction
function MultiboardSetItemValueModified takes multiboarditem whichMBI, string message returns nothing
local integer i
local string c
local string c2
if message == "" or message == null then
return
endif
set message = StringIdentity(message)
set i = 0
loop
set c = SubString(message, i, i + 1)
exitwhen c == ""
if c == "%%" then
set c2 = SubString(message, i + 1, i + 2)
if c2 == "%%" then
set message = SubString(message, 0, i) + SubString(message, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set message = SubString(message, 0, i) + StringIdentity(udg_ui_string_modifiers[S2I(c2)]) + SubString(message, i + 2, 0x7FFFFFFF)
endif
else
set i = i + 1
endif
endloop
call MultiboardSetItemValue(whichMBI, message)
endfunction
function TimerDialogSetTitleColorInteger takes timerdialog t, integer ci returns nothing
call TimerDialogSetTitleColor(t, ColorIntegerGetRed(ci), ColorIntegerGetGreen(ci), ColorIntegerGetBlue(ci), ColorIntegerGetAlpha(ci))
endfunction
function TimerDialogSetTimeColorInteger takes timerdialog t, integer ci returns nothing
call TimerDialogSetTimeColor(t, ColorIntegerGetRed(ci), ColorIntegerGetGreen(ci), ColorIntegerGetBlue(ci), ColorIntegerGetAlpha(ci))
endfunction
function TimerDialogSetTitleModified takes timerdialog whichTimerDialog, string message returns nothing
local integer i
local string c
local string c2
if message == "" or message == null then
return
endif
set message = StringIdentity(message)
set i = 0
loop
set c = SubString(message, i, i + 1)
exitwhen c == ""
if c == "%%" then
set c2 = SubString(message, i + 1, i + 2)
if c2 == "%%" then
set message = SubString(message, 0, i) + SubString(message, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set message = SubString(message, 0, i) + StringIdentity(udg_ui_string_modifiers[S2I(c2)]) + SubString(message, i + 2, 0x7FFFFFFF)
endif
else
set i = i + 1
endif
endloop
call TimerDialogSetTitle(whichTimerDialog, message)
endfunction
// By: Peppar. [email protected]
Name | Type | is_array | initial_value |
camera_position_unit | unit | No | |
camera_type | integer | Yes | 0 |
camera_type_FREE | integer | No | 1 |
camera_type_REVOLVING | integer | No | 2 |
chess_color | playercolor | Yes | |
chess_error_last | integer | No | 0 |
chess_errortype_BLOCKED | integer | No | 2 |
chess_errortype_CASTLING_CHECK | integer | No | 7 |
chess_errortype_CASTLING_EPATH | integer | No | 5 |
chess_errortype_CASTLING_MOVED | integer | No | 6 |
chess_errortype_NONE | integer | No | 0 |
chess_errortype_OUTOFREACH | integer | No | 1 |
chess_errortype_THREAT | integer | No | 3 |
chess_errortype_THREATENSKING | integer | No | 4 |
chess_errortype_UNKNOWN | integer | No | -1 |
chess_game_fischerid | integer | No | |
chess_game_ownervote | boolean | Yes | |
chess_game_random | boolean | No | |
chess_game_round | integer | No | 0 |
chess_game_status | integer | No | 0 |
chess_game_status_OFF | integer | No | 2 |
chess_game_status_ON | integer | No | 1 |
chess_game_timer | timer | Yes | |
chess_game_timer_fischer | real | No | |
chess_game_timer_time | real | No | |
chess_game_timerflag | boolean | No | false |
chess_game_turn | integer | No | 0 |
chess_grid | integer | Yes | 0 |
chess_grid_unit | unit | Yes | |
chess_move_history | integer | Yes | 0 |
chess_move_history_grid | integer | Yes | 0 |
chess_move_history_player | player | Yes | |
chess_move_type_CASTLE | integer | No | 3 |
chess_move_type_INVALID | integer | No | 0 |
chess_move_type_MOVE | integer | No | 1 |
chess_move_type_PASSANT | integer | No | 4 |
chess_move_type_PAWNTOBISHOP | integer | No | 9 |
chess_move_type_PAWNTOKNIGHT | integer | No | 11 |
chess_move_type_PAWNTOQUEEN | integer | No | 5 |
chess_move_type_PAWNTOROOK | integer | No | 7 |
chess_move_type_TAKE | integer | No | 2 |
chess_move_type_TPAWNTOBISHOP | integer | No | 10 |
chess_move_type_TPAWNTOKNIGHT | integer | No | 12 |
chess_move_type_TPAWNTOQUEEN | integer | No | 6 |
chess_move_type_TPAWNTOROOK | integer | No | 8 |
chess_owner | player | Yes | |
chess_owner_BLACK | integer | No | 2 |
chess_owner_NONE | integer | No | 0 |
chess_owner_WHITE | integer | No | 1 |
chess_ownerstatus | integer | Yes | 0 |
chess_ownerstatus_CHECKMATE | integer | No | 2 |
chess_ownerstatus_DRAW | integer | No | 6 |
chess_ownerstatus_GAMEOVER | integer | No | 0 |
chess_ownerstatus_PLAYING | integer | No | 1 |
chess_ownerstatus_STALEMATE | integer | No | 3 |
chess_ownerstatus_SURRENDERED | integer | No | 4 |
chess_ownerstatus_TIMEOUT | integer | No | 5 |
chess_rect | rect | No | RectNull |
chess_statuschecker_move | integer | Yes | 0 |
chess_statuschecker_move_end | integer | No | 0 |
chess_statuschecker_q | integer | No | 0 |
chess_statuschecker_reset | boolean | No | false |
chess_statuschecker_round | integer | No | 0 |
chess_statuschecker_tick | integer | No | 0 |
chess_statuschecker_tickcount | integer | No | 20 |
chess_type_BISHOP | integer | No | 1 |
chess_type_KING | integer | No | 2 |
chess_type_KNIGHT | integer | No | 3 |
chess_type_NONE | integer | No | 0 |
chess_type_PAWN | integer | No | 4 |
chess_type_QUEEN | integer | No | 5 |
chess_type_ROOK | integer | No | 6 |
chess_unittype_BISHOP | unitcode | No | h001 |
chess_unittype_KING | unitcode | No | h002 |
chess_unittype_KNIGHT | unitcode | No | h003 |
chess_unittype_PAWN | unitcode | No | h004 |
chess_unittype_QUEEN | unitcode | No | h005 |
chess_unittype_ROOK | unitcode | No | h000 |
common_controlsiezed | boolean | No | false |
common_ordering | boolean | No | false |
music_song | string | Yes | |
music_song_description | string | Yes | |
music_song_end | integer | No | |
parameter_integer | integer | No | |
parameter_player | player | No | |
parameter_string | string | No | |
parameter_x | real | No | |
parameter_y | real | No | |
player_rotate_direction | integer | Yes | |
player_zoom_direction | integer | Yes | |
rotate_refresh | real | No | 0.05 |
rotate_speed | real | No | 100.00 |
ui_dialog | dialog | Yes | |
ui_dialog_button | button | Yes | |
ui_dialog_button_userdata | integer | Yes | 0 |
ui_dialog_buttonptr | integer | Yes | 0 |
ui_dialog_trigger | trigger | Yes | |
ui_dialog_version | integer | Yes | 0 |
ui_movenotif_indicator | boolean | No | true |
ui_movenotif_method | integer | No | 1 |
ui_movenotif_method_CLAP | integer | No | 1 |
ui_movenotif_method_NONE | integer | No | 0 |
ui_movenotif_method_STOMP | integer | No | 2 |
ui_movenotif_ping | boolean | Yes | false |
ui_sound_move | sound | No | |
ui_statusboard | multiboard | Yes | |
ui_statusboard_initialized | boolean | No | false |
ui_string | string | Yes | |
ui_string_BLACK | string | No | |
ui_string_CANNOTCHECKKING | string | No | |
ui_string_CASTLINGCHECK | string | No | |
ui_string_CASTLINGEPATH | string | No | |
ui_string_CASTLINGMOVED | string | No | |
ui_string_CHANGECOLOR | string | No | |
ui_string_CHANGEVIEW | string | No | |
ui_string_CHECK | string | No | |
ui_string_CHECKMATE | string | No | |
ui_string_CHESSGAMESETUP | string | No | |
ui_string_CHESSMENU | string | No | |
ui_string_CLAP | string | No | |
ui_string_CONVERTPAWN | string | No | |
ui_string_DLG10MINUTETIMER | string | No | |
ui_string_DLG10SECONDS | string | No | |
ui_string_DLG20MINUTETIMER | string | No | |
ui_string_DLG20SECONDS | string | No | |
ui_string_DLG30MINUTETIMER | string | No | |
ui_string_DLG30SECONDS | string | No | |
ui_string_DLGACCEPTDRAW | string | No | |
ui_string_DLGALL | string | No | |
ui_string_DLGAQUA | string | No | |
ui_string_DLGBACK | string | No | |
ui_string_DLGBISHOP | string | No | |
ui_string_DLGBLACK | string | No | |
ui_string_DLGBLACKPLAYERVIEW | string | No | |
ui_string_DLGBLUE | string | No | |
ui_string_DLGBLUELIGHT | string | No | |
ui_string_DLGBROWN | string | No | |
ui_string_DLGCANCEL | string | No | |
ui_string_DLGCHNGCOLORELLIPSIS | string | No | |
ui_string_DLGCHNGMUSICELLIPSIS | string | No | |
ui_string_DLGCHNGVIEWELLIPSIS | string | No | |
ui_string_DLGCURRENTPLAYERVIEW | string | No | |
ui_string_DLGCYAN | string | No | |
ui_string_DLGFISCHERRNDCHESSX | string | No | |
ui_string_DLGFISCHERXELLIPSIS | string | No | |
ui_string_DLGGRAYDARK | string | No | |
ui_string_DLGGRAYLIGHT | string | No | |
ui_string_DLGGREEN | string | No | |
ui_string_DLGINFORMATION | string | No | |
ui_string_DLGKNIGHT | string | No | |
ui_string_DLGMINUS10MINUTES | string | No | |
ui_string_DLGMINUS10SECONDS | string | No | |
ui_string_DLGMINUS1MINUTE | string | No | |
ui_string_DLGMINUS1SECOND | string | No | |
ui_string_DLGMOREELLIPSIS | string | No | |
ui_string_DLGMOVEEFFECTX | string | No | |
ui_string_DLGMOVEINDICATORX | string | No | |
ui_string_DLGMOVEMINIMAPPINGX | string | No | |
ui_string_DLGNOTIMER | string | No | |
ui_string_DLGOBSERVINGVIEW | string | No | |
ui_string_DLGOK | string | No | |
ui_string_DLGOPTIONS | string | No | |
ui_string_DLGORANGE | string | No | |
ui_string_DLGPINK | string | No | |
ui_string_DLGPLUS10MINUTES | string | No | |
ui_string_DLGPLUS10SECONDS | string | No | |
ui_string_DLGPLUS1MINUTE | string | No | |
ui_string_DLGPLUS1SECOND | string | No | |
ui_string_DLGPROPOSEDRAW | string | No | |
ui_string_DLGPURPLE | string | No | |
ui_string_DLGQUEEN | string | No | |
ui_string_DLGQUIT | string | No | |
ui_string_DLGRECALLDRAW | string | No | |
ui_string_DLGRED | string | No | |
ui_string_DLGRESIGN | string | No | |
ui_string_DLGRESIGNELLIPSIS | string | No | |
ui_string_DLGROAMINGVIEW | string | No | |
ui_string_DLGROOK | string | No | |
ui_string_DLGSTART | string | No | |
ui_string_DLGSTARTGAME | string | No | |
ui_string_DLGSTOPGAME | string | No | |
ui_string_DLGSTOPMUSIC | string | No | |
ui_string_DLGSURRENDER | string | No | |
ui_string_DLGTAKEOVERBLACK | string | No | |
ui_string_DLGTAKEOVERWHITE | string | No | |
ui_string_DLGTIMERXELLIPSIS | string | No | |
ui_string_DLGUPDATE | string | No | |
ui_string_DLGWHITE | string | No | |
ui_string_DLGWHITEPLAYERVIEW | string | No | |
ui_string_DLGYELLOW | string | No | |
ui_string_DRAW | string | No | |
ui_string_FISCHERGAMEIDX | string | No | |
ui_string_FISCHERRANDOMCHESSX | string | No | |
ui_string_FISCHERTIMESETUPX | string | No | |
ui_string_GAMESTATUSOFF | string | No | |
ui_string_GAMESTATUSON | string | No | |
ui_string_GAMESTATUSUNKNOWN | string | No | |
ui_string_INFORMATION | string | No | |
ui_string_MBDCHESS | string | No | |
ui_string_MBDDRAW | string | No | |
ui_string_MBDGAMEOVER | string | No | |
ui_string_MBDHISTORY | string | No | |
ui_string_MBDSTALEMATE | string | No | |
ui_string_MBDXISCHECKMATE | string | No | |
ui_string_MBDXSTURN | string | No | |
ui_string_MBDXSURRENDERED | string | No | |
ui_string_MBDXTIMEDOUT | string | No | |
ui_string_MBDYOUARECHECKMATE | string | No | |
ui_string_MBDYOURTURN | string | No | |
ui_string_MBDYOUSURRENDERED | string | No | |
ui_string_MBDYOUTIMEDOUT | string | No | |
ui_string_modifiers | string | Yes | |
ui_string_NONE | string | No | |
ui_string_NOONEISPLAYINGBLACK | string | No | |
ui_string_NOONEISPLAYINGWHITE | string | No | |
ui_string_OBSERVERXLEFTTHEGAME | string | No | |
ui_string_OFF | string | No | |
ui_string_ON | string | No | |
ui_string_OPTIONS | string | No | |
ui_string_PATHBLOCKED | string | No | |
ui_string_PIECETAKEN | string | No | |
ui_string_PLAYERXISABSENT | string | No | |
ui_string_PLAYERXLEFTTHEGAME | string | No | |
ui_string_QUITQ | string | No | |
ui_string_RESIGN | string | No | |
ui_string_ROUNDX | string | No | |
ui_string_SELECTMUSICPAGEX | string | No | |
ui_string_STALEMATE | string | No | |
ui_string_STOMP | string | No | |
ui_string_STOPGAMEQ | string | No | |
ui_string_SURRENDERQ | string | No | |
ui_string_TILEBLOCKED | string | No | |
ui_string_TILEOUTOFREACH | string | No | |
ui_string_TIMEOUT | string | No | |
ui_string_TIMERSETUPX | string | No | |
ui_string_UNKNOWN | string | No | |
ui_string_WHITE | string | No | |
ui_string_XACCEPTSADRAW | string | No | |
ui_string_XHASRESIGNED | string | No | |
ui_string_XISPLAYINGBLACK | string | No | |
ui_string_XISPLAYINGWHITE | string | No | |
ui_string_XMINUTESPLURAL | string | No | |
ui_string_XMINUTESSINGULAR | string | No | |
ui_string_XPROPOSESADRAW | string | No | |
ui_string_XRECALLSADRAW | string | No | |
ui_string_XRESIGNED | string | No | |
ui_string_XRESIGNEDBLACK | string | No | |
ui_string_XRESIGNEDWHITE | string | No | |
ui_string_XSECONDSPLURAL | string | No | |
ui_string_XSECONDSSINGULAR | string | No | |
ui_string_XSTIME | string | No | |
ui_string_XTOOKOVERBLACK | string | No | |
ui_string_XTOOKOVERBLACKTOO | string | No | |
ui_string_XTOOKOVERWHITE | string | No | |
ui_string_XTOOKOVERWHITETOO | string | No | |
ui_texttag_count | integer | No | 0 |
ui_texttag_end | integer | No | 100 |
ui_texttag_texttag | texttag | Yes | |
ui_texttag_texttag_color | integer | Yes | 0 |
ui_texttag_texttag_duration | real | Yes | 0.00 |
ui_texttag_texttag_unit | unit | Yes | |
ui_texttag_texttag_x | real | Yes | 0.00 |
ui_texttag_texttag_y | real | Yes | 0.00 |
ui_texttag_texttag_z | real | Yes | 0.00 |
ui_timerboard | timerdialog | Yes | |
ui_timerboard_initialized | boolean | No | false |
zoom_limit_in | real | No | 1500.00 |
zoom_limit_out | real | No | 8000.00 |
zoom_refresh | real | No | 0.05 |
zoom_speed | real | No | 2000.00 |
function dialogCreate takes player whichPlayer, string caption, trigger callback returns nothing
local integer p = GetPlayerId(whichPlayer)
call DialogClear(udg_ui_dialog[p])
call DialogSetMessage(udg_ui_dialog[p], caption)
set udg_ui_dialog_buttonptr[p] = 0
set udg_ui_dialog_trigger[p] = callback
set udg_ui_dialog_version[p] = udg_ui_dialog_version[p] + 1
endfunction
function dialogCreateModified takes player whichPlayer, string caption, trigger callback returns nothing
local integer p = GetPlayerId(whichPlayer)
local integer i
local string c
local string c2
if caption == "" or caption == null then
return
endif
set caption = StringIdentity(caption)
set i = 0
loop
set c = SubString(caption, i, i + 1)
exitwhen c == ""
if c == "%" then
set c2 = SubString(caption , i + 1, i + 2)
if c2 == "%" then
set caption = SubString(caption, 0, i) + SubString(caption, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set caption = SubString(caption, 0, i) + StringIdentity(udg_ui_string_modifiers[S2I(c2)]) + SubString(caption, i + 2, 0x7FFFFFFF)
endif
else
set i = i + 1
endif
endloop
call DialogClear(udg_ui_dialog[p])
call DialogSetMessage(udg_ui_dialog[p], caption)
set udg_ui_dialog_buttonptr[p] = 0
set udg_ui_dialog_trigger[p] = callback
set udg_ui_dialog_version[p] = udg_ui_dialog_version[p] + 1
endfunction
function dialogAddButton takes player whichPlayer, string label, integer hotkey, integer userdata returns nothing
local integer p = GetPlayerId(whichPlayer)
if udg_ui_dialog_buttonptr[p] == 12 then
return
endif
set udg_ui_dialog_button[p * 12 + udg_ui_dialog_buttonptr[p]] = DialogAddButton(udg_ui_dialog[p], HighlightHotkey(label, hotkey, "ffffffff"), hotkey)
set udg_ui_dialog_button_userdata[p * 12 + udg_ui_dialog_buttonptr[p]] = userdata
set udg_ui_dialog_buttonptr[p] = udg_ui_dialog_buttonptr[p] + 1
endfunction
function dialogAddButtonModified takes player whichPlayer, string label, integer userdata returns nothing
local string charMap = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789"
local integer p = GetPlayerId(whichPlayer)
local integer i
local integer j
local string c
local integer hotkey = 0
local string hotkeyString = null
if label == "" or label == null or udg_ui_dialog_buttonptr[p] == 12 then
return
endif
set i = 0
loop
set c = SubString(label, i, i + 1)
exitwhen c == "" or c == null
if c == "%" then
set c = SubString(label, i + 1, i + 2)
if c == "%" then
set label = SubString(label, 0, i) + SubString(label, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set label = SubString(label, 0, i) + udg_ui_string_modifiers[S2I(c)] + SubString(label, i + 2, 0x7FFFFFFF)
endif
else
if c == "&" then
set c = SubString(label, i + 1, i + 2)
if c == "" then
set label = SubString(label, 0, i)
set hotkey = 0
set hotkeyString = null
exitwhen true
elseif c == "[" then
set hotkeyString = ""
set j = i + 2
loop
set c = SubString(label, j, j + 1)
exitwhen c == "," or c == "]" or c == ""
set hotkeyString = hotkeyString + c
set j = j + 1
endloop
if c == "" then
set label = SubString(label, 0, i)
set hotkey = 0
set hotkeyString = null
exitwhen true
else
if StringCase(hotkeyString, false) == "esc" then
set hotkey = 512
else
set hotkey = S2I(hotkeyString)
endif
endif
if c == "]" then
set label = SubString(label, 0, i) + SubString(label, j + 1, 0x7FFFFFFF)
set hotkeyString = null
elseif c == "," then
set j = j + 1
set hotkeyString = ""
loop
set c = SubString(label, j, j + 1)
exitwhen c == "]" or c == ""
set hotkeyString = hotkeyString + c
set j = j + 1
endloop
if c == "" then
set label = SubString(label, 0, i)
set hotkey = 0
set hotkeyString = null
exitwhen true
else
set label = SubString(label, 0, i) + "|cffffffff" + hotkeyString + "|r" + SubString(label, j + 1, 0x7FFFFFFF)
set i = i + StringLength(hotkeyString) + 12
endif
endif
elseif c == "&" then
set label = SubString(label, 0, i) + SubString(label, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set hotkeyString = c
set label = SubString(label, 0, i) + "|cffffffff" + c + "|r" + SubString(label, i + 2, 0x7FFFFFFF)
set i = i + 13
endif
else
set i = i + 1
endif
endif
endloop
if hotkeyString != null and hotkey == 0 then
set i = 0
loop
set c = SubString(charMap, i, i + 1)
exitwhen c == "" or hotkeyString == c
set i = i + 1
endloop
if c != "" then
if i >= 0 and i < 28 then
set hotkey = 'A' + i / 2
elseif i >= 28 then
set hotkey = '0' + i - 28
endif
endif
endif
set udg_ui_dialog_button[p * 12 + udg_ui_dialog_buttonptr[p]] = DialogAddButton(udg_ui_dialog[p], label, hotkey)
set udg_ui_dialog_button_userdata[p * 12 + udg_ui_dialog_buttonptr[p]] = userdata
set udg_ui_dialog_buttonptr[p] = udg_ui_dialog_buttonptr[p] + 1
endfunction
function dialogAddQuitButton takes player whichPlayer, string label, integer hotkey, boolean doScoreScreen returns nothing
local integer p = GetPlayerId(whichPlayer)
if udg_ui_dialog_buttonptr[p] == 12 then
return
endif
set udg_ui_dialog_button[p * 12 + udg_ui_dialog_buttonptr[p]] = DialogAddQuitButton(udg_ui_dialog[p], doScoreScreen, HighlightHotkey(label, hotkey, "ffffffff"), hotkey)
set udg_ui_dialog_buttonptr[p] = udg_ui_dialog_buttonptr[p] + 1
endfunction
function dialogAddQuitButtonModified takes player whichPlayer, string label, boolean doScoreScreen returns nothing
local string charMap = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789"
local integer p = GetPlayerId(whichPlayer)
local integer i
local integer j
local string c
local integer hotkey = 0
local string hotkeyString = null
if label == "" or label == null or udg_ui_dialog_buttonptr[p] == 12 then
return
endif
set i = 0
loop
set c = SubString(label, i, i + 1)
exitwhen c == "" or c == null
if c == "%" then
set c = SubString(label, i + 1, i + 2)
if c == "%" then
set label = SubString(label, 0, i) + SubString(label, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set label = SubString(label, 0, i) + udg_ui_string_modifiers[S2I(c)] + SubString(label, i + 2, 0x7FFFFFFF)
endif
else
if c == "&" then
set c = SubString(label, i + 1, i + 2)
if c == "" then
set label = SubString(label, 0, i)
set hotkey = 0
set hotkeyString = null
exitwhen true
elseif c == "[" then
set hotkeyString = ""
set j = i + 2
loop
set c = SubString(label, j, j + 1)
exitwhen c == "," or c == "]" or c == ""
set hotkeyString = hotkeyString + c
set j = j + 1
endloop
if c == "" then
set label = SubString(label, 0, i)
set hotkey = 0
set hotkeyString = null
exitwhen true
else
if StringCase(hotkeyString, false) == "esc" then
set hotkey = 512
else
set hotkey = S2I(hotkeyString)
endif
endif
if c == "]" then
set label = SubString(label, 0, i) + SubString(label, j + 1, 0x7FFFFFFF)
set hotkeyString = null
elseif c == "," then
set j = j + 1
set hotkeyString = ""
loop
set c = SubString(label, j, j + 1)
exitwhen c == "]" or c == ""
set hotkeyString = hotkeyString + c
set j = j + 1
endloop
if c == "" then
set label = SubString(label, 0, i)
set hotkey = 0
set hotkeyString = null
exitwhen true
else
set label = SubString(label, 0, i) + "|cffffffff" + hotkeyString + "|r" + SubString(label, j + 1, 0x7FFFFFFF)
set i = i + StringLength(hotkeyString) + 12
endif
endif
elseif c == "&" then
set label = SubString(label, 0, i) + SubString(label, i + 1, 0x7FFFFFFF)
set i = i + 1
else
set hotkeyString = c
set label = SubString(label, 0, i) + "|cffffffff" + c + "|r" + SubString(label, i + 2, 0x7FFFFFFF)
set i = i + 13
endif
else
set i = i + 1
endif
endif
endloop
if hotkeyString != null and hotkey == 0 then
set i = 0
loop
set c = SubString(charMap, i, i + 1)
exitwhen c == "" or hotkeyString == c
set i = i + 1
endloop
if c != "" then
if i >= 0 and i < 28 then
set hotkey = 'A' + i / 2
elseif i >= 28 then
set hotkey = '0' + i - 28
endif
endif
endif
set udg_ui_dialog_button[p * 12 + udg_ui_dialog_buttonptr[p]] = DialogAddQuitButton(udg_ui_dialog[p], doScoreScreen, label, hotkey)
set udg_ui_dialog_buttonptr[p] = udg_ui_dialog_buttonptr[p] + 1
endfunction
function dialogShow takes player whichPlayer, boolean show returns nothing
local integer p = GetPlayerId(whichPlayer)
if udg_ui_dialog_buttonptr[p] == 0 then
return
endif
call DialogDisplay(whichPlayer, udg_ui_dialog[p], show)
endfunction
function getButtonUserData takes player whichPlayer, integer whichButton returns integer
if whichButton < 0 or whichButton >= 12 then
return 0
endif
return udg_ui_dialog_button_userdata[GetPlayerId(whichPlayer) * 12 + whichButton]
endfunction
function dialogShowModal takes player whichPlayer returns integer
local integer p = GetPlayerId(whichPlayer)
local integer i = 0
local integer b = 0
local integer v = udg_ui_dialog_version[p]
local integer buttons = udg_ui_dialog_buttonptr[p]
local trigger array triggerArray
if udg_ui_dialog_buttonptr[p] == 0 then
return
endif
loop
exitwhen i == udg_ui_dialog_buttonptr[p]
set triggerArray[i] = CreateTrigger()
call TriggerRegisterDialogButtonEvent(triggerArray[i], udg_ui_dialog_button[p * 12 + i])
set i = i + 1
endloop
call DialogDisplay(whichPlayer, udg_ui_dialog[p], true)
loop
exitwhen v != udg_ui_dialog_version[p]
call TriggerSleepAction(0.25)
set b = 0
loop
exitwhen b == buttons
if GetTriggerEvalCount(triggerArray[b]) != 0 then
set i = 0
loop
exitwhen i == buttons
call DestroyTrigger(triggerArray[i])
set triggerArray[i] = null
set i = i + 1
endloop
return b
endif
set b = b + 1
endloop
endloop
set i = 0
loop
exitwhen i == buttons
call DestroyTrigger(triggerArray[i])
set triggerArray[i] = null
set i = i + 1
endloop
return -1
endfunction
function Trig_Initialize_Dialog_Actions takes nothing returns nothing
endfunction
//===========================================================================
function InitTrig_Initialize_Dialog takes nothing returns nothing
set gg_trg_Initialize_Dialog = CreateTrigger( )
call TriggerAddAction( gg_trg_Initialize_Dialog, function Trig_Initialize_Dialog_Actions )
endfunction
function Trig_Dialog_Response_Actions takes nothing returns nothing
local integer b = 0
local integer p
loop
exitwhen b == 144
if udg_ui_dialog_button[b] == GetClickedButton() then
set p = b / 12
if udg_ui_dialog_trigger[p] == null then
return
endif
set udg_parameter_player = Player(p)
set udg_parameter_integer = UIMod(b, 12)
if TriggerEvaluate(udg_ui_dialog_trigger[p]) then
call TriggerExecute(udg_ui_dialog_trigger[p])
endif
exitwhen true
endif
set b = b + 1
endloop
endfunction
//===========================================================================
function InitTrig_Dialog_Response takes nothing returns nothing
local integer i = 0
set gg_trg_Dialog_Response = CreateTrigger( )
loop
exitwhen i == 12
call TriggerRegisterDialogEvent(gg_trg_Dialog_Response, udg_ui_dialog[i])
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Dialog_Response, function Trig_Dialog_Response_Actions )
endfunction
function allocateTextTagEntry takes nothing returns integer
local integer t = 0
loop
exitwhen t == udg_ui_texttag_end or udg_ui_texttag_texttag[t] == null
set t = t + 1
endloop
if t == udg_ui_texttag_end then
return -1
endif
if udg_ui_texttag_count == 0 then
call EnableTrigger(gg_trg_Floating_Text)
endif
set udg_ui_texttag_count = udg_ui_texttag_count + 1
return t
endfunction
function deallocateTextTagEntry takes integer t returns nothing
set udg_ui_texttag_texttag[t] = null
set udg_ui_texttag_count = udg_ui_texttag_count - 1
if udg_ui_texttag_count == 0 then
call DisableTrigger(gg_trg_Floating_Text)
endif
endfunction
function addTextTagForForce takes force whichForce, real x, real y, real z, real duration, string message, real size, integer color returns nothing
local integer t = allocateTextTagEntry()
if t == -1 then
return
endif
set udg_ui_texttag_texttag[t] = CreateTextTag()
call SetTextTagText(udg_ui_texttag_texttag[t], message, TextTagSize2Height(size))
call SetTextTagColor(udg_ui_texttag_texttag[t], ColorIntegerGetRed(color), ColorIntegerGetGreen(color), ColorIntegerGetBlue(color), ColorIntegerGetAlpha(color))
call SetTextTagVisibility(udg_ui_texttag_texttag[t], whichForce == null or IsPlayerInForce(GetLocalPlayer(), whichForce))
set udg_ui_texttag_texttag_duration[t] = duration
set udg_ui_texttag_texttag_color[t] = color
set udg_ui_texttag_texttag_unit[t] = null
set udg_ui_texttag_texttag_x[t] = x
set udg_ui_texttag_texttag_y[t] = y
set udg_ui_texttag_texttag_z[t] = z
call SetTextTagPos(udg_ui_texttag_texttag[t], x, y, z)
endfunction
function addTextTag takes real x, real y, real z, real duration, string message, real size, integer color returns nothing
call addTextTagForForce(null, x, y, z, duration, message, size, color)
endfunction
function addTextTagUnitForForce takes force whichForce, unit u, real z, real duration, string message, real size, integer color returns nothing
local integer t = allocateTextTagEntry()
if t == -1 then
return
endif
set udg_ui_texttag_texttag[t] = CreateTextTag()
call SetTextTagText(udg_ui_texttag_texttag[t], message, TextTagSize2Height(size))
call SetTextTagColor(udg_ui_texttag_texttag[t], ColorIntegerGetRed(color), ColorIntegerGetGreen(color), ColorIntegerGetBlue(color), ColorIntegerGetAlpha(color))
call SetTextTagVisibility(udg_ui_texttag_texttag[t], whichForce == null or IsPlayerInForce(GetLocalPlayer(), whichForce))
set udg_ui_texttag_texttag_duration[t] = duration
set udg_ui_texttag_texttag_color[t] = color
set udg_ui_texttag_texttag_unit[t] = u
set udg_ui_texttag_texttag_z[t] = z
call SetTextTagPosUnit(udg_ui_texttag_texttag[t], u, z)
endfunction
function addTextTagUnit takes unit u, real z, real duration, string message, real size, integer color returns nothing
call addTextTagUnitForForce(null, u, z, duration, message, size, color)
endfunction
function addTextTagSquare takes integer q, real duration, string message, real size, integer color returns nothing
if getSquarePieceUnit(q) != null then
call addTextTagUnit(getSquarePieceUnit(q), 0, duration, message, size, color)
else
call addTextTag(getSquareCenterX(q), getSquareCenterY(q), 0, duration, message, size, color)
endif
endfunction
function addTextTagSquareForForce takes force whichForce, integer q, real duration, string message, real size, integer color returns nothing
if getSquarePieceUnit(q) != null then
call addTextTagUnitForForce(whichForce, getSquarePieceUnit(q), 0, duration, message, size, color)
else
call addTextTagForForce(whichForce, getSquareCenterX(q), getSquareCenterY(q), 0, duration, message, size, color)
endif
endfunction
function addTextTagSquareForPlayer takes player whichPlayer, integer q, real duration, string message, real size, integer color returns nothing
call addTextTagSquareForForce(bj_FORCE_PLAYER[GetPlayerId(whichPlayer)], q, duration, message, size, color)
endfunction
function addErrorTextTagSquare takes integer q, string message returns nothing
call addTextTagSquare(q, 4, message, 10, 0xFF0000FF)
endfunction
function addErrorTextTagSquareForPlayer takes player whichPlayer, integer q, string message returns nothing
call addTextTagSquareForPlayer(whichPlayer, q, 4, message, 10, 0xFF0000FF)
endfunction
function addBigTextTag takes real x, real y, real z, string message, integer color returns nothing
call addTextTag(x, y, z, 5, message, 14, color)
endfunction
function addBigTextTagSquare takes integer q, string message, integer color returns nothing
call addTextTagSquare(q, 5, message, 14, color)
endfunction
function addSmallTextTagSquare takes integer q, string message, integer color returns nothing
call addTextTagSquare(q, 4, message, 10, color)
endfunction
function Trig_Floating_Text_Updater_Actions takes nothing returns nothing
local integer i = 0
local integer n = 0
loop
exitwhen i == udg_ui_texttag_end or n == udg_ui_texttag_count
if udg_ui_texttag_texttag[i] != null then
if udg_ui_texttag_texttag_duration[i] <= 0 then
call DestroyTextTag(udg_ui_texttag_texttag[i])
call deallocateTextTagEntry(i)
else
if udg_ui_texttag_texttag_duration[i] < 1.00 then
set udg_ui_texttag_texttag_color[i] = CreateColorInteger(ColorIntegerGetRed(udg_ui_texttag_texttag_color[i]), ColorIntegerGetGreen(udg_ui_texttag_texttag_color[i]), ColorIntegerGetBlue(udg_ui_texttag_texttag_color[i]), IMaxBJ(ColorIntegerGetAlpha(udg_ui_texttag_texttag_color[i]) - 25, 0))
call SetTextTagColor(udg_ui_texttag_texttag[i], ColorIntegerGetRed(udg_ui_texttag_texttag_color[i]), ColorIntegerGetGreen(udg_ui_texttag_texttag_color[i]), ColorIntegerGetBlue(udg_ui_texttag_texttag_color[i]), ColorIntegerGetAlpha(udg_ui_texttag_texttag_color[i]))
endif
set udg_ui_texttag_texttag_duration[i] = udg_ui_texttag_texttag_duration[i] - 0.10
set udg_ui_texttag_texttag_z[i] = udg_ui_texttag_texttag_z[i] + 8
if udg_ui_texttag_texttag_unit[i] == null then
call SetTextTagPos(udg_ui_texttag_texttag[i], udg_ui_texttag_texttag_x[i], udg_ui_texttag_texttag_y[i], udg_ui_texttag_texttag_z[i])
else
call SetTextTagPosUnit(udg_ui_texttag_texttag[i], udg_ui_texttag_texttag_unit[i], udg_ui_texttag_texttag_z[i])
endif
endif
set n = n + 1
endif
set i = i + 1
endloop
endfunction
//===========================================================================
function InitTrig_Floating_Text takes nothing returns nothing
set gg_trg_Floating_Text = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Floating_Text, 0.05 )
call TriggerAddAction( gg_trg_Floating_Text, function Trig_Floating_Text_Updater_Actions )
endfunction
function initTimerboards takes nothing returns nothing
set udg_ui_timerboard[0] = CreateTimerDialog(udg_chess_game_timer[0])
set udg_ui_timerboard[1] = CreateTimerDialog(udg_chess_game_timer[1])
call addModifierParameter(0, getOwnerName(udg_chess_owner_WHITE))
call TimerDialogSetTitleModified(udg_ui_timerboard[0], udg_ui_string_XSTIME)
call addModifierParameter(0, getOwnerName(udg_chess_owner_BLACK))
call TimerDialogSetTitleModified(udg_ui_timerboard[1], udg_ui_string_XSTIME)
call TimerDialogSetTitleColorInteger(udg_ui_timerboard[0], GetPlayerColorColorInteger(getChessOwnerColor(udg_chess_owner_WHITE)))
call TimerDialogSetTitleColorInteger(udg_ui_timerboard[1], GetPlayerColorColorInteger(getChessOwnerColor(udg_chess_owner_BLACK)))
set udg_ui_timerboard_initialized = true
endfunction
function updateTimerDialogs takes nothing returns nothing
local boolean singlePlayer = isGameSinglePlayer()
if udg_chess_game_timerflag then
if singlePlayer then
call addModifierParameter(0, getPassiveOwnerName(udg_chess_owner_WHITE))
call TimerDialogSetTitleModified(udg_ui_timerboard[0], udg_ui_string_XSTIME)
call addModifierParameter(0, getPassiveOwnerName(udg_chess_owner_BLACK))
call TimerDialogSetTitleModified(udg_ui_timerboard[1], udg_ui_string_XSTIME)
else
call addModifierParameter(0, getOwnerName(udg_chess_owner_WHITE))
call TimerDialogSetTitleModified(udg_ui_timerboard[0], udg_ui_string_XSTIME)
call addModifierParameter(0, getOwnerName(udg_chess_owner_BLACK))
call TimerDialogSetTitleModified(udg_ui_timerboard[1], udg_ui_string_XSTIME)
endif
call TimerDialogSetTitleColorInteger(udg_ui_timerboard[0], GetPlayerColorColorInteger(getChessOwnerColor(udg_chess_owner_WHITE)))
call TimerDialogSetTitleColorInteger(udg_ui_timerboard[1], GetPlayerColorColorInteger(getChessOwnerColor(udg_chess_owner_BLACK)))
call TimerDialogDisplay(udg_ui_timerboard[0], true)
call TimerDialogDisplay(udg_ui_timerboard[1], true)
else
call TimerDialogDisplay(udg_ui_timerboard[0], false)
call TimerDialogDisplay(udg_ui_timerboard[1], false)
endif
endfunction
function setMultiboardWidth takes multiboard b, real width returns nothing
call MultiboardSetItemsWidth(b, width / I2R(MultiboardGetColumnCount(b)))
endfunction
function setMultiboardColumnWidth takes multiboard b, integer column, real width returns nothing
local integer row = MultiboardGetRowCount(b)
local multiboarditem m
loop
exitwhen row == 0
set row = row - 1
set m = MultiboardGetItem(b, row, column)
call MultiboardSetItemWidth(m, width)
call MultiboardReleaseItem(m)
endloop
set m = null
endfunction
function initStatusBoard takes nothing returns nothing
local integer b = 0
loop
exitwhen b == 3
set udg_ui_statusboard[b] = CreateMultiboard()
call MultiboardSetTitleText(udg_ui_statusboard[b], udg_ui_string_MBDCHESS)
call MultiboardSetColumnCount(udg_ui_statusboard[b], 2)
call MultiboardSetRowCount(udg_ui_statusboard[b], 13)
call MultiboardSetItemsWidth(udg_ui_statusboard[b], 0.0775)
set b = b + 1
endloop
call MultiboardSuppressDisplay(false)
set udg_ui_statusboard_initialized = true
endfunction
function displayStatusBoard takes nothing returns nothing
local boolean singlePlayer = isGameSinglePlayer()
local boolean timerBoardShow = udg_chess_game_timer_time != 0.0 and udg_chess_game_status == udg_chess_game_status_ON
local player white = getOwnerPlayer(udg_chess_owner_WHITE)
local player black = getOwnerPlayer(udg_chess_owner_BLACK)
if singlePlayer then
call MultiboardDisplay(udg_ui_statusboard[2], true)
elseif white == GetLocalPlayer() then
call MultiboardDisplay(udg_ui_statusboard[0], true)
elseif black == GetLocalPlayer() then
call MultiboardDisplay(udg_ui_statusboard[1], true)
else
call MultiboardDisplay(udg_ui_statusboard[2], true)
endif
endfunction
function MultiboardSetItemValueColorInteger takes multiboarditem m, integer ci returns nothing
call MultiboardSetItemValueColor(m, ColorIntegerGetRed(ci), ColorIntegerGetGreen(ci), ColorIntegerGetBlue(ci), ColorIntegerGetAlpha(ci))
endfunction
function updateStatusBoard takes nothing returns nothing
local boolean singlePlayer = isGameSinglePlayer()
local integer historyRows = IMinBJ(udg_chess_game_round, 10)
local integer row = 0
local integer i = 0
local integer r = 0
local integer b = 0
local integer q1
local integer q2
local integer time
local multiboarditem m
if not bj_gameStarted then
loop
exitwhen bj_gameStarted
call TriggerSleepAction(0.10)
endloop
endif
if not udg_ui_statusboard_initialized then
call initStatusBoard()
endif
set b = 0
loop
exitwhen b == 3
call MultiboardSetItemsValue(udg_ui_statusboard[b], null)
call MultiboardSetItemsValueColor(udg_ui_statusboard[b], 255, 255, 255, 255)
call MultiboardSetItemsStyle(udg_ui_statusboard[b], false, false)
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 0)
call MultiboardSetItemStyle(m, true, false)
call MultiboardSetItemValue(m, udg_ui_string_MBDHISTORY)
call MultiboardSetItemValueColor(m, 200, 200, 200, 255)
call MultiboardSetItemWidth(m, 0.080)
call MultiboardReleaseItem(m)
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 0)
call MultiboardSetItemWidth(m, 0.075)
call MultiboardReleaseItem(m)
set b = b + 1
endloop
set row = row + 1
if historyRows != 0 then
loop
exitwhen i == historyRows
set time = udg_chess_game_round-historyRows+i
set r = getHistoryRecord(time)
set q1 = getMoveSquare1(udg_chess_move_history[time])
set q2 = getMoveSquare2(udg_chess_move_history[time])
set b = 0
loop
exitwhen b == 3
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 0)
call MultiboardSetItemStyle(m, true, false)
call MultiboardSetItemValue(m, GetPlayerName(udg_chess_move_history_player[time]))
call MultiboardSetItemValueColorInteger(m, GetPlayerColorColorInteger(getChessOwnerColor(getRecordPieceOwner(r))))
call MultiboardSetItemWidth(m, 0.080)
call MultiboardReleaseItem(m)
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 1)
call MultiboardSetItemIcon(m, "MiniIcons\\Mini_"+getPieceTypeNameEnglish(getRecordPieceType(r))+".tga")
call MultiboardSetItemStyle(m, true, true)
call MultiboardSetItemValue(m, getSquareName(q1) + "-" + getSquareName(q2))
call MultiboardSetItemWidth(m, 0.075)
call MultiboardReleaseItem(m)
set b = b + 1
endloop
set i = i + 1
set row = row + 1
endloop
endif
set row = 12
if udg_chess_game_status == udg_chess_game_status_ON then
set b = 0
loop
exitwhen b == 3
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 0)
call MultiboardSetItemWidth(m, 0.155)
call MultiboardSetItemStyle(m, true, false)
if b == 0 then
if udg_chess_game_turn == udg_chess_owner_WHITE then
call MultiboardSetItemValueModified(m, udg_ui_string_MBDYOURTURN)
else
call addModifierParameter(0, getOwnerName(udg_chess_owner_BLACK))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSTURN)
endif
elseif b == 1 then
if udg_chess_game_turn == udg_chess_owner_BLACK then
call MultiboardSetItemValueModified(m, udg_ui_string_MBDYOURTURN)
else
call addModifierParameter(0, getOwnerName(udg_chess_owner_WHITE))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSTURN)
endif
else
if singlePlayer then
call addModifierParameter(0, getPassiveOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSTURN)
else
call addModifierParameter(0, getOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSTURN)
endif
endif
call MultiboardReleaseItem(m)
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 1)
call MultiboardSetItemWidth(m, 0.000)
call MultiboardSetItemStyle(m, false, false)
call MultiboardReleaseItem(m)
set b = b + 1
endloop
else
set b = 0
loop
exitwhen b == 3
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 0)
call MultiboardSetItemWidth(m, 0.155)
call MultiboardSetItemStyle(m, true, false)
if udg_chess_ownerstatus[udg_chess_owner_WHITE - 1] == udg_chess_ownerstatus_DRAW and udg_chess_ownerstatus[udg_chess_owner_BLACK - 1] == udg_chess_ownerstatus_DRAW then
call MultiboardSetItemValue(m, udg_ui_string_MBDDRAW)
elseif udg_chess_ownerstatus[udg_chess_game_turn - 1] == udg_chess_ownerstatus_CHECKMATE then
if b == udg_chess_game_turn - 1 then
call MultiboardSetItemValueModified(m, udg_ui_string_MBDYOUARECHECKMATE)
elseif singlePlayer then
call addModifierParameter(0, getPassiveOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXISCHECKMATE)
else
call addModifierParameter(0, getOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXISCHECKMATE)
endif
elseif udg_chess_ownerstatus[udg_chess_game_turn - 1] == udg_chess_ownerstatus_TIMEOUT then
if b == udg_chess_game_turn - 1 then
call MultiboardSetItemValueModified(m, udg_ui_string_MBDYOUTIMEDOUT)
elseif singlePlayer then
call addModifierParameter(0, getPassiveOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXTIMEDOUT)
else
call addModifierParameter(0, getOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXTIMEDOUT)
endif
elseif udg_chess_ownerstatus[udg_chess_game_turn - 1] == udg_chess_ownerstatus_STALEMATE then
call MultiboardSetItemValueModified(m, udg_ui_string_STALEMATE)
elseif udg_chess_ownerstatus[udg_chess_owner_WHITE - 1] == udg_chess_ownerstatus_SURRENDERED then
if b == 0 then
call MultiboardSetItemValueModified(m, udg_ui_string_MBDYOUSURRENDERED)
elseif singlePlayer then
call addModifierParameter(0, getPassiveOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSURRENDERED)
else
call addModifierParameter(0, getOwnerName(udg_chess_owner_WHITE))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSURRENDERED)
endif
elseif udg_chess_ownerstatus[udg_chess_owner_BLACK - 1] == udg_chess_ownerstatus_SURRENDERED then
if b == 1 then
call MultiboardSetItemValueModified(m, udg_ui_string_MBDYOUSURRENDERED)
elseif singlePlayer then
call addModifierParameter(0, getPassiveOwnerName(udg_chess_game_turn))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSURRENDERED)
else
call addModifierParameter(0, getOwnerName(udg_chess_owner_BLACK))
call MultiboardSetItemValueModified(m, udg_ui_string_MBDXSURRENDERED)
endif
else
call MultiboardSetItemValueModified(m, udg_ui_string_MBDGAMEOVER)
endif
call MultiboardReleaseItem(m)
set m = MultiboardGetItem(udg_ui_statusboard[b], row, 1)
call MultiboardSetItemWidth(m, 0.000)
call MultiboardReleaseItem(m)
set b = b + 1
endloop
endif
set m = null
call displayStatusBoard()
call updateTimerDialogs()
endfunction
function InitTrig_Statusboard takes nothing returns nothing
endfunction
//========================================
//
// Chess rule and move functions
//
//========================================
constant function getOwnerDirection takes integer owner returns integer
if owner == udg_chess_owner_WHITE then
return 1
elseif owner == udg_chess_owner_BLACK then
return -1
endif
return 0
endfunction
function getHomeRow takes integer owner returns integer
if owner == udg_chess_owner_WHITE then
return 0
elseif owner == udg_chess_owner_BLACK then
return 7
endif
return -1
endfunction
constant function getEnemy takes integer owner returns integer
if owner == udg_chess_owner_WHITE then
return udg_chess_owner_BLACK
elseif owner == udg_chess_owner_BLACK then
return udg_chess_owner_WHITE
endif
return udg_chess_owner_NONE
endfunction
constant function pathIsClear takes integer q1, integer q2 returns boolean
local integer deltaX = getSquareX(q2) - getSquareX(q1)
local integer deltaY = getSquareY(q2) - getSquareY(q1)
local integer stepX = ISign(deltaX)
local integer stepY = ISign(deltaY)
if not directionIsValid(deltaX, deltaY) then
return false
endif
loop
set q1 = square(getSquareX(q1) + stepX, getSquareY(q1) + stepY)
exitwhen q1 == q2
if getSquarePieceType(q1) != udg_chess_type_NONE then
return false
endif
endloop
return true
endfunction
function squareIsThreatened takes integer q, integer owner returns boolean
local integer q1 = 0
local integer x = getSquareX(q)
local integer y = getSquareY(q)
local integer pt
local integer eo = getEnemy(owner)
local integer deltaX
local integer deltaY
loop
exitwhen q1 == 64
if squareHasEnemy(q1, owner) then
set deltaX = x - getSquareX(q1)
set deltaY = y - getSquareY(q1)
set pt = getSquarePieceType(q1)
if pt == udg_chess_type_BISHOP then
if q1 != q then
if pathIsDiagonal(q1, q) then
if pathIsClear(q1, q) then
return true
endif
endif
endif
elseif pt == udg_chess_type_KING then
if q1 != q then
if IAbs(deltaX) <= 1 and IAbs(deltaY) <= 1 then
return true
endif
endif
elseif pt == udg_chess_type_KNIGHT then
if (IAbs(deltaX) == 1 and IAbs(deltaY) == 2) or (IAbs(deltaX) == 2 and IAbs(deltaY) == 1) then
return true
endif
elseif pt == udg_chess_type_QUEEN then
if q1 != q then
if pathIsValid(q1, q) then
if pathIsClear(q1, q) then
return true
endif
endif
endif
elseif pt == udg_chess_type_PAWN then
if eo == udg_chess_owner_WHITE then
if deltaX == 1 and IAbs(deltaY) == 1 then
return true
endif
elseif eo == udg_chess_owner_BLACK then
if deltaX == -1 and IAbs(deltaY) == 1 then
return true
endif
endif
elseif pt == udg_chess_type_ROOK then
if q1 != q then
if pathIsCrossed(q1, q) then
if pathIsClear(q1, q) then
return true
endif
endif
endif
endif
endif
set q1 = q1 + 1
endloop
return false
endfunction
function pathIsThreatened takes integer q1, integer q2, integer owner returns boolean
local integer deltaX = getSquareX(q2) - getSquareX(q1)
local integer deltaY = getSquareY(q2) - getSquareY(q1)
local integer stepX = ISign(deltaX)
local integer stepY = ISign(deltaY)
if not directionIsValid(deltaX, deltaY) then
return false
endif
loop
set q1 = square(getSquareX(q1) + stepX, getSquareY(q1) + stepY)
exitwhen q1 == q2
if squareIsThreatened(q1, owner) then
return true
endif
endloop
return false
endfunction
function ownerKingIsChecked takes integer owner returns boolean
return squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
endfunction
function getCastlingKingDestinationY takes integer q1, integer q2 returns integer
if getSquareY(q1) > getSquareY(q2) then // A-side
return 1
else // H-side
return 5
endif
endfunction
function getCastlingRookDestinationY takes integer q1, integer q2 returns integer
if getSquareY(q1) > getSquareY(q2) then // A-side
return 2
else // H-side
return 4
endif
endfunction
function getCastlingY1 takes integer q1, integer q2 returns integer
local integer y1
if getSquareY(q1) > getSquareY(q2) then // A-side
set y1 = 1
else // H-side
set y1 = 4
endif
if getSquareY(q1) < y1 then
set y1 = getSquareY(q1)
endif
if getSquareY(q2) < y1 then
set y1 = getSquareY(q2)
endif
return y1
endfunction
function getCastlingY2 takes integer q1, integer q2 returns integer
local integer y2
if getSquareY(q1) > getSquareY(q2) then // A-side
set y2 = 2
else // H-side
set y2 = 5
endif
if getSquareY(q1) > y2 then
set y2 = getSquareY(q1)
endif
if getSquareY(q2) > y2 then
set y2 = getSquareY(q2)
endif
return y2
endfunction
function moveThreatensKing takes integer move returns boolean
local integer moveType = getMoveType(move)
local integer q1 = getMoveSquare1(move)
local integer q2 = getMoveSquare2(move)
local integer q3
local integer q4
local integer owner = getSquarePieceOwner(q1)
local integer temp_q2 = udg_chess_grid[q2]
local integer temp_q1 = udg_chess_grid[q1]
local boolean result = false
if moveType == udg_chess_move_type_MOVE then
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q1] = 0
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q2] = 0
set udg_chess_grid[q1] = temp_q1
elseif moveType == udg_chess_move_type_TAKE then
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q1] = 0
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q2] = temp_q2
set udg_chess_grid[q1] = temp_q1
elseif moveType == udg_chess_move_type_CASTLE then
set q3 = square(getHomeRow(owner), getCastlingKingDestinationY(q1, q2))
set q4 = square(getHomeRow(owner), getCastlingRookDestinationY(q1, q2))
set udg_chess_grid[q1] = 0
set udg_chess_grid[q2] = 0
set udg_chess_grid[q3] = temp_q1
set udg_chess_grid[q4] = temp_q2
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q4] = 0
set udg_chess_grid[q3] = 0
set udg_chess_grid[q2] = temp_q2
set udg_chess_grid[q1] = temp_q1
elseif moveType == udg_chess_move_type_PASSANT then
set q3 = projectSquare(q1, 0, ISign(getSquareDeltaY(q1, q2)))
set temp_q2 = udg_chess_grid[q3]
set udg_chess_grid[q1] = 0
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q3] = 0
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q1] = temp_q1
set udg_chess_grid[q2] = 0
set udg_chess_grid[q3] = temp_q2
elseif moveType == udg_chess_move_type_PAWNTOQUEEN or moveType == udg_chess_move_type_TPAWNTOQUEEN then
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q1] = 0
call setSquarePieceType(q2, udg_chess_type_QUEEN)
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q2] = temp_q2
set udg_chess_grid[q1] = temp_q1
elseif moveType == udg_chess_move_type_PAWNTOROOK or moveType == udg_chess_move_type_TPAWNTOROOK then
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q1] = 0
call setSquarePieceType(q2, udg_chess_type_ROOK)
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q2] = temp_q2
set udg_chess_grid[q1] = temp_q1
elseif moveType == udg_chess_move_type_PAWNTOBISHOP or moveType == udg_chess_move_type_TPAWNTOBISHOP then
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q1] = 0
call setSquarePieceType(q2, udg_chess_type_BISHOP)
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q2] = temp_q2
set udg_chess_grid[q1] = temp_q1
elseif moveType == udg_chess_move_type_PAWNTOKNIGHT or moveType == udg_chess_move_type_TPAWNTOKNIGHT then
set udg_chess_grid[q2] = temp_q1
set udg_chess_grid[q1] = 0
call setSquarePieceType(q2, udg_chess_type_KNIGHT)
set result = squareIsThreatened(getFirstPieceTypeSquare(udg_chess_type_KING, owner), owner)
set udg_chess_grid[q2] = temp_q2
set udg_chess_grid[q1] = temp_q1
endif
return result
endfunction
function castlingPathIsBlocked takes integer q1, integer q2 returns boolean
local integer owner = getSquarePieceOwner(q1)
local integer homeRow = getHomeRow(owner)
local integer y = getCastlingY1(q1, q2) + 1
local integer y2 = getCastlingY2(q1, q2)
loop
exitwhen y >= y2
if square(homeRow, y) != q1 and square(homeRow, y) != q2 and squareIsOccupied(square(homeRow, y)) then
return true
endif
set y = y + 1
endloop
return false
endfunction
function castlingY1IsOccupied takes integer q1, integer q2 returns boolean
local integer y1 = getCastlingY1(q1, q2)
local integer q = square(getHomeRow(getSquarePieceOwner(q1)), y1)
if q1 == q or q2 == q then
return false
endif
return squareIsOccupied(q)
endfunction
function castlingY2IsOccupied takes integer q1, integer q2 returns boolean
local integer y2 = getCastlingY2(q1, q2)
local integer q = square(getHomeRow(getSquarePieceOwner(q1)), y2)
if q1 == q or q2 == q then
return false
endif
return squareIsOccupied(q)
endfunction
function getChessMoveType takes integer q1, integer q2 returns integer
local integer deltaX = getSquareX(q2) - getSquareX(q1)
local integer deltaY = getSquareY(q2) - getSquareY(q1)
local integer piecetype
local integer owner
local integer tempq
if not (squareIsValid(q1) and squareIsValid(q2)) then
call createLastError(-1, -1, udg_chess_errortype_UNKNOWN)
return udg_chess_move_type_INVALID
elseif q1 == q2 then
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
endif
set piecetype = getSquarePieceType(q1)
set owner = getSquarePieceOwner(q1)
if piecetype == udg_chess_type_PAWN then
if getOwnerDirection(owner) != ISign(deltaX) or IAbs(deltaY) > 1 then
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
elseif deltaY == 0 and IAbs(deltaX) == 1 then
if not squareIsOccupied(q2) then
if getSquareX(q2) == getHomeRow(getEnemy(owner)) then
return udg_chess_move_type_PAWNTOQUEEN
endif
return udg_chess_move_type_MOVE
endif
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
elseif deltaY == 0 and IAbs(deltaX) == 2 then
if getSquarePieceMoveCount(q1) > 0 then
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
elseif pathIsClear(q1, q2) and not squareIsOccupied(q2) then
return udg_chess_move_type_MOVE
endif
call createLastError(q1, q2, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
elseif IAbs(deltaX) == 1 and IAbs(deltaY) == 1 then
if squareHasEnemy(q2, owner) then
if getSquareX(q2) == getHomeRow(getEnemy(owner)) then
return udg_chess_move_type_TPAWNTOQUEEN
endif
return udg_chess_move_type_TAKE
elseif squareIsOccupied(q2) then
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
else
set tempq = square(getSquareX(q1), getSquareY(q1) + deltaY)
if squareHasEnemy(tempq, owner) and getSquarePieceType(tempq) == udg_chess_type_PAWN then
if getMoveSquare2(getLastMove()) == tempq and getMoveType(getLastMove()) == udg_chess_move_type_MOVE then
if getMoveSquare1(getLastMove()) == projectSquare(tempq, getOwnerDirection(owner) * 2, 0) then
return udg_chess_move_type_PASSANT
endif
endif
endif
endif
endif
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
elseif piecetype == udg_chess_type_QUEEN then
if not pathIsValid(q1, q2) then
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
elseif not pathIsClear(q1, q2) then
call createLastError(q1, q2, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
elseif squareHasEnemy(q2, owner) then
return udg_chess_move_type_TAKE
elseif squareIsOccupied(q2) then
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
else
return udg_chess_move_type_MOVE
endif
elseif piecetype == udg_chess_type_ROOK then
if getSquareX(q1) == getHomeRow(owner) and getSquarePieceType(q2) == udg_chess_type_KING and getSquarePieceOwner(q2) == owner and getSquareX(q2) == getHomeRow(owner) then
if getSquarePieceMoveCount(q1) == 0 then
if getSquarePieceMoveCount(q2) == 0 then
if not castlingPathIsBlocked(q2, q1) then
if not castlingY1IsOccupied(q2, q1) then
if not castlingY2IsOccupied(q2, q1) then
if not squareIsThreatened(q2, owner) then
if not squareIsThreatened(square(getHomeRow(owner), getCastlingKingDestinationY(q2, q1)), owner) then
if not pathIsThreatened(q2, square(getHomeRow(owner), getCastlingKingDestinationY(q2, q1)), owner) then
return udg_chess_move_type_CASTLE
else
call createLastError(q2, square(getHomeRow(owner), getCastlingKingDestinationY(q2, q1)), udg_chess_errortype_CASTLING_EPATH)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingKingDestinationY(q2, q1)), -1, udg_chess_errortype_THREAT)
endif
else
call createLastError(q2, -1, udg_chess_errortype_CASTLING_CHECK)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingY2(q2, q1)), -1, udg_chess_errortype_BLOCKED)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingY1(q2, q1)), -1, udg_chess_errortype_BLOCKED)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingY1(q2, q1)), square(getHomeRow(owner), getCastlingY2(q2, q1)), udg_chess_errortype_BLOCKED)
endif
else
call createLastError(q2, -1, udg_chess_errortype_CASTLING_MOVED)
endif
else
call createLastError(q1, -1, udg_chess_errortype_CASTLING_MOVED)
endif
return udg_chess_move_type_INVALID
elseif not pathIsCrossed(q1, q2) then
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
elseif not pathIsClear(q1, q2) then
call createLastError(q1, q2, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
elseif squareHasEnemy(q2, owner) then
return udg_chess_move_type_TAKE
elseif squareIsOccupied(q2) then
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
else
return udg_chess_move_type_MOVE
endif
elseif piecetype == udg_chess_type_BISHOP then
if not pathIsDiagonal(q1, q2) then
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
elseif not pathIsClear(q1, q2) then
call createLastError(q1, q2, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
elseif squareHasEnemy(q2, owner) then
return udg_chess_move_type_TAKE
elseif squareIsOccupied(q2) then
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
else
return udg_chess_move_type_MOVE
endif
elseif piecetype == udg_chess_type_KING then
if getSquareX(q1) == getHomeRow(owner) and getSquarePieceType(q2) == udg_chess_type_ROOK and getSquarePieceOwner(q2) == owner and getSquareX(q2) == getHomeRow(owner) then
if getSquarePieceMoveCount(q1) == 0 then
if getSquarePieceMoveCount(q2) == 0 then
if not castlingPathIsBlocked(q1, q2) then
if not castlingY1IsOccupied(q1, q2) then
if not castlingY2IsOccupied(q1, q2) then
if not squareIsThreatened(q1, owner) then
if not squareIsThreatened(square(getHomeRow(owner), getCastlingKingDestinationY(q1, q2)), owner) then
if not pathIsThreatened(q1, square(getHomeRow(owner), getCastlingKingDestinationY(q1, q2)), owner) then
return udg_chess_move_type_CASTLE
else
call createLastError(q1, square(getHomeRow(owner), getCastlingKingDestinationY(q1, q2)), udg_chess_errortype_CASTLING_EPATH)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingKingDestinationY(q1, q2)), -1, udg_chess_errortype_THREAT)
endif
else
call createLastError(q1, -1, udg_chess_errortype_CASTLING_CHECK)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingY2(q1, q2)), -1, udg_chess_errortype_BLOCKED)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingY1(q1, q2)), -1, udg_chess_errortype_BLOCKED)
endif
else
call createLastError(square(getHomeRow(owner), getCastlingY1(q1, q2)), square(getHomeRow(owner), getCastlingY2(q1, q2)), udg_chess_errortype_BLOCKED)
endif
else
call createLastError(q2, -1, udg_chess_errortype_CASTLING_MOVED)
endif
else
call createLastError(q1, -1, udg_chess_errortype_CASTLING_MOVED)
endif
return udg_chess_move_type_INVALID
elseif IAbs(deltaX) <= 1 and IAbs(deltaY) <= 1 then
if squareHasEnemy(q2, owner) then
return udg_chess_move_type_TAKE
elseif squareIsOccupied(q2) then
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
else
return udg_chess_move_type_MOVE
endif
elseif not udg_chess_game_random and q1 == square(getHomeRow(owner), 3) and IAbs(deltaY) == 2 and deltaX == 0 then
if deltaY < 0 then
set tempq = square(getSquareX(q1), 0)
else
set tempq = square(getSquareX(q1), 7)
endif
if getSquarePieceType(tempq) == udg_chess_type_ROOK and getSquarePieceOwner(tempq) == owner then
if pathIsClear(q1, tempq) then
if getSquarePieceMoveCount(q1) == 0 then
if getSquarePieceMoveCount(tempq) == 0 then
if not squareIsThreatened(q1, owner) then
if not pathIsThreatened(q1, q2, owner) then
return udg_chess_move_type_CASTLE
else
call createLastError(q1, q2, udg_chess_errortype_CASTLING_EPATH)
endif
else
call createLastError(q1, q2, udg_chess_errortype_CASTLING_CHECK)
endif
else
call createLastError(tempq, -1, udg_chess_errortype_CASTLING_MOVED)
endif
else
call createLastError(q1, -1, udg_chess_errortype_CASTLING_MOVED)
endif
else
call createLastError(q1, tempq, udg_chess_errortype_BLOCKED)
endif
else
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
endif
return udg_chess_move_type_INVALID
else
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
endif
elseif piecetype == udg_chess_type_KNIGHT then
if (IAbs(deltaX) == 1 and IAbs(deltaY) == 2) or (IAbs(deltaX) == 2 and IAbs(deltaY) == 1) then
if squareHasEnemy(q2, owner) then
return udg_chess_move_type_TAKE
elseif squareIsOccupied(q2) then
call createLastError(q2, -1, udg_chess_errortype_BLOCKED)
return udg_chess_move_type_INVALID
endif
return udg_chess_move_type_MOVE
else
call createLastError(q2, -1, udg_chess_errortype_OUTOFREACH)
return udg_chess_move_type_INVALID
endif
endif
call createLastError(-1, -1, udg_chess_errortype_UNKNOWN)
return udg_chess_move_type_INVALID
endfunction
function getChessMove takes integer q1, integer q2 returns integer
local integer moveType = getChessMoveType(q1, q2)
local integer move
if moveType == udg_chess_move_type_CASTLE and getSquareDeltaY(q1, q2) == -2 and not udg_chess_game_random then
set move = createMove(q1, square(getSquareX(q1), 0), moveType)
elseif moveType == udg_chess_move_type_CASTLE and getSquareDeltaY(q1, q2) == 2 and not udg_chess_game_random then
set move = createMove(q1, square(getSquareX(q1), 7), moveType)
elseif moveType == udg_chess_move_type_CASTLE and getSquarePieceType(q1) == udg_chess_type_ROOK then
set move = createMove(q2, q1, moveType)
else
set move = createMove(q1, q2, moveType)
endif
if moveThreatensKing(move) then
if moveType == udg_chess_move_type_CASTLE then
call createLastError(projectSquare(getMoveSquare1(move), 0, ISign(getSquareDeltaY(getMoveSquare1(move), getMoveSquare2(move))) * 2), -1, udg_chess_errortype_THREAT)
elseif getSquarePieceType(q1) == udg_chess_type_KING then
call createLastError(q2, -1, udg_chess_errortype_THREAT)
else
call createLastError(getFirstPieceTypeSquare(udg_chess_type_KING, getSquarePieceOwner(q1)), -1, udg_chess_errortype_THREATENSKING)
endif
set move = createMove(getMoveSquare1(move), getMoveSquare2(move), udg_chess_move_type_INVALID)
endif
return move
endfunction
function updateTimers takes nothing returns nothing
if udg_chess_game_status != udg_chess_game_status_ON then
call PauseTimer(udg_chess_game_timer[udg_chess_owner_WHITE - 1])
call PauseTimer(udg_chess_game_timer[udg_chess_owner_BLACK - 1])
elseif udg_chess_game_timerflag then
call ResumeTimer(udg_chess_game_timer[udg_chess_game_turn - 1])
call PauseTimer(udg_chess_game_timer[getEnemy(udg_chess_game_turn) - 1])
endif
endfunction
function initTimers takes nothing returns nothing
if not udg_ui_timerboard_initialized then
call initTimerboards()
endif
if udg_chess_game_timer_time == 0.0 then
set udg_chess_game_timerflag = false
else
set udg_chess_game_timerflag = true
call TimerStart(udg_chess_game_timer[udg_chess_owner_WHITE - 1], udg_chess_game_timer_time , false, null)
call PauseTimer(udg_chess_game_timer[udg_chess_owner_WHITE - 1])
call TimerStart(udg_chess_game_timer[udg_chess_owner_BLACK - 1], udg_chess_game_timer_time , false, null)
call PauseTimer(udg_chess_game_timer[udg_chess_owner_BLACK - 1])
endif
endfunction
function pauseTimers takes nothing returns nothing
if udg_chess_game_timerflag then
call PauseTimer(udg_chess_game_timer[udg_chess_owner_WHITE - 1])
call PauseTimer(udg_chess_game_timer[udg_chess_owner_BLACK - 1])
endif
endfunction
function ownerSetup takes nothing returns nothing
set udg_chess_ownerstatus[udg_chess_owner_WHITE - 1] = udg_chess_ownerstatus_PLAYING
set udg_chess_ownerstatus[udg_chess_owner_BLACK - 1] = udg_chess_ownerstatus_PLAYING
set udg_chess_game_ownervote[udg_chess_owner_WHITE - 1] = false
set udg_chess_game_ownervote[udg_chess_owner_BLACK - 1] = false
endfunction
function createDefaultChessSetup takes nothing returns nothing
local integer i = 0
loop
exitwhen i == 8
call createChessPiece(square(1, i), udg_chess_type_PAWN, udg_chess_owner_WHITE)
call createChessPiece(square(6, i), udg_chess_type_PAWN, udg_chess_owner_BLACK)
set i = i + 1
endloop
call createChessPiece(square(0, 0), udg_chess_type_ROOK, udg_chess_owner_WHITE)
call createChessPiece(square(0, 1), udg_chess_type_KNIGHT, udg_chess_owner_WHITE)
call createChessPiece(square(0, 2), udg_chess_type_BISHOP, udg_chess_owner_WHITE)
call createChessPiece(square(0, 3), udg_chess_type_KING, udg_chess_owner_WHITE)
call createChessPiece(square(0, 4), udg_chess_type_QUEEN, udg_chess_owner_WHITE)
call createChessPiece(square(0, 5), udg_chess_type_BISHOP, udg_chess_owner_WHITE)
call createChessPiece(square(0, 6), udg_chess_type_KNIGHT, udg_chess_owner_WHITE)
call createChessPiece(square(0, 7), udg_chess_type_ROOK, udg_chess_owner_WHITE)
call createChessPiece(square(7, 0), udg_chess_type_ROOK, udg_chess_owner_BLACK)
call createChessPiece(square(7, 1), udg_chess_type_KNIGHT, udg_chess_owner_BLACK)
call createChessPiece(square(7, 2), udg_chess_type_BISHOP, udg_chess_owner_BLACK)
call createChessPiece(square(7, 3), udg_chess_type_KING, udg_chess_owner_BLACK)
call createChessPiece(square(7, 4), udg_chess_type_QUEEN, udg_chess_owner_BLACK)
call createChessPiece(square(7, 5), udg_chess_type_BISHOP, udg_chess_owner_BLACK)
call createChessPiece(square(7, 6), udg_chess_type_KNIGHT, udg_chess_owner_BLACK)
call createChessPiece(square(7, 7), udg_chess_type_ROOK, udg_chess_owner_BLACK)
endfunction
function createFischerRandomChessSetup takes nothing returns nothing
local integer i = 0
local integer n = 0
local integer array KRN
set udg_chess_game_fischerid = GetRandomInt(0, 959)
loop
exitwhen i == 8
call createChessPiece(square(1, i), udg_chess_type_PAWN, udg_chess_owner_WHITE)
call createChessPiece(square(6, i), udg_chess_type_PAWN, udg_chess_owner_BLACK)
set i = i + 1
endloop
call createChessPiece(square(0, ModuloInteger(udg_chess_game_fischerid, 4) * 2 + 1), udg_chess_type_BISHOP, udg_chess_owner_WHITE)
call createChessPiece(square(7, ModuloInteger(udg_chess_game_fischerid, 4) * 2 + 1), udg_chess_type_BISHOP, udg_chess_owner_BLACK)
call createChessPiece(square(0, ModuloInteger(udg_chess_game_fischerid / 4, 4) * 2), udg_chess_type_BISHOP, udg_chess_owner_WHITE)
call createChessPiece(square(7, ModuloInteger(udg_chess_game_fischerid / 4, 4) * 2), udg_chess_type_BISHOP, udg_chess_owner_BLACK)
set i = 0
set n = ModuloInteger(udg_chess_game_fischerid / 16, 6)
loop
if not squareIsOccupied(square(0, i)) then
exitwhen n == 0
set n = n - 1
endif
set i = i + 1
endloop
call createChessPiece(square(0, i), udg_chess_type_QUEEN, udg_chess_owner_WHITE)
call createChessPiece(square(7, i), udg_chess_type_QUEEN, udg_chess_owner_BLACK)
set n = udg_chess_game_fischerid / 96
if n == 0 then
set KRN[0] = udg_chess_type_KNIGHT
set KRN[1] = udg_chess_type_KNIGHT
set KRN[2] = udg_chess_type_ROOK
set KRN[3] = udg_chess_type_KING
set KRN[4] = udg_chess_type_ROOK
elseif n == 1 then
set KRN[0] = udg_chess_type_KNIGHT
set KRN[1] = udg_chess_type_ROOK
set KRN[2] = udg_chess_type_KNIGHT
set KRN[3] = udg_chess_type_KING
set KRN[4] = udg_chess_type_ROOK
elseif n == 2 then
set KRN[0] = udg_chess_type_KNIGHT
set KRN[1] = udg_chess_type_ROOK
set KRN[2] = udg_chess_type_KING
set KRN[3] = udg_chess_type_KNIGHT
set KRN[4] = udg_chess_type_ROOK
elseif n == 3 then
set KRN[0] = udg_chess_type_KNIGHT
set KRN[1] = udg_chess_type_ROOK
set KRN[2] = udg_chess_type_KING
set KRN[3] = udg_chess_type_ROOK
set KRN[4] = udg_chess_type_KNIGHT
elseif n == 4 then
set KRN[0] = udg_chess_type_ROOK
set KRN[1] = udg_chess_type_KNIGHT
set KRN[2] = udg_chess_type_KNIGHT
set KRN[3] = udg_chess_type_KING
set KRN[4] = udg_chess_type_ROOK
elseif n == 5 then
set KRN[0] = udg_chess_type_ROOK
set KRN[1] = udg_chess_type_KNIGHT
set KRN[2] = udg_chess_type_KING
set KRN[3] = udg_chess_type_KNIGHT
set KRN[4] = udg_chess_type_ROOK
elseif n == 6 then
set KRN[0] = udg_chess_type_ROOK
set KRN[1] = udg_chess_type_KNIGHT
set KRN[2] = udg_chess_type_KING
set KRN[3] = udg_chess_type_ROOK
set KRN[4] = udg_chess_type_KNIGHT
elseif n == 7 then
set KRN[0] = udg_chess_type_ROOK
set KRN[1] = udg_chess_type_KING
set KRN[2] = udg_chess_type_KNIGHT
set KRN[3] = udg_chess_type_KNIGHT
set KRN[4] = udg_chess_type_ROOK
elseif n == 8 then
set KRN[0] = udg_chess_type_ROOK
set KRN[1] = udg_chess_type_KING
set KRN[2] = udg_chess_type_KNIGHT
set KRN[3] = udg_chess_type_ROOK
set KRN[4] = udg_chess_type_KNIGHT
elseif n == 9 then
set KRN[0] = udg_chess_type_ROOK
set KRN[1] = udg_chess_type_KING
set KRN[2] = udg_chess_type_ROOK
set KRN[3] = udg_chess_type_KNIGHT
set KRN[4] = udg_chess_type_KNIGHT
endif
set i = 0
set n = 0
loop
if not squareIsOccupied(square(0, i)) then
call createChessPiece(square(0, i), KRN[n], udg_chess_owner_WHITE)
call createChessPiece(square(7, i), KRN[n], udg_chess_owner_BLACK)
set n = n + 1
exitwhen n == 5
endif
set i = i + 1
endloop
endfunction
function chessGameSetup takes nothing returns nothing
call clearChessGrid()
call ownerSetup()
if udg_chess_game_random then
call createFischerRandomChessSetup()
else
call createDefaultChessSetup()
endif
set udg_chess_game_turn = udg_chess_owner_WHITE
call pauseOwnerPieces(udg_chess_owner_BLACK, true)
call pauseOwnerPieces(udg_chess_owner_WHITE, false)
set udg_chess_game_round = 0
call initTimers()
call updateStatusBoard()
endfunction
function chessGameStart takes nothing returns nothing
set udg_chess_game_status = udg_chess_game_status_ON
set udg_common_ordering = true
call pauseOwnerPieces(udg_chess_game_turn, false)
call pauseOwnerPieces(getEnemy(udg_chess_game_turn), true)
set udg_common_ordering = false
call EnableTrigger(gg_trg_Player_Move_to_Point)
call EnableTrigger(gg_trg_Player_Move_to_Piece)
call EnableTrigger(gg_trg_Player_Move_by_Keyboard)
call updateTimers()
call updateStatusBoard()
call TriggerExecute(gg_trg_Chess_Camera_Change)
endfunction
function ownerTimerStartWithAddedTime takes integer owner, real time returns nothing
if owner == 0 then
return
endif
call TimerStart(udg_chess_game_timer[owner - 1], TimerGetRemaining(udg_chess_game_timer[owner - 1]) + time, false, null)
endfunction
function alternateTurnSequence takes nothing returns nothing
set udg_common_ordering = true
if udg_chess_game_timer_time != 0 and udg_chess_game_timer_fischer != 0 then
call ownerTimerStartWithAddedTime(udg_chess_game_turn, udg_chess_game_timer_fischer)
endif
if udg_chess_game_turn == udg_chess_owner_WHITE then
set udg_chess_game_turn = udg_chess_owner_BLACK
call stopOwnerUnits(udg_chess_owner_WHITE)
call pauseOwnerPieces(udg_chess_owner_WHITE, true)
call pauseOwnerPieces(udg_chess_owner_BLACK, false)
call stopOwnerUnits(udg_chess_owner_BLACK)
elseif udg_chess_game_turn == udg_chess_owner_BLACK then
set udg_chess_game_turn = udg_chess_owner_WHITE
call stopOwnerUnits(udg_chess_owner_BLACK)
call pauseOwnerPieces(udg_chess_owner_BLACK, true)
call pauseOwnerPieces(udg_chess_owner_WHITE, false)
call stopOwnerUnits(udg_chess_owner_WHITE)
endif
set udg_common_ordering = false
set udg_chess_game_round = udg_chess_game_round + 1
call updateTimers()
call updateStatusBoard()
call TriggerExecute(gg_trg_Chess_Camera_Change)
endfunction
function chessGameStop takes nothing returns nothing
set udg_chess_game_status = udg_chess_game_status_OFF
call DisableTrigger(gg_trg_Player_Move_to_Point)
call DisableTrigger(gg_trg_Player_Move_to_Piece)
call DisableTrigger(gg_trg_Player_Move_by_Keyboard)
set udg_common_ordering = true
call pauseOwnerPieces(udg_chess_owner_BLACK, true)
call pauseOwnerPieces(udg_chess_owner_WHITE, true)
set udg_common_ordering = false
call updateTimers()
call updateStatusBoard()
endfunction
function chessGameEnd takes nothing returns nothing
local integer current_owner = udg_chess_game_turn
if udg_chess_ownerstatus[current_owner - 1] == udg_chess_ownerstatus_TIMEOUT then
call addBigTextTagSquare(getFirstPieceTypeSquare(udg_chess_type_KING, current_owner), udg_ui_string_TIMEOUT, CreateColorInteger(255, 255, 255, 255))
elseif udg_chess_ownerstatus[current_owner - 1] == udg_chess_ownerstatus_CHECKMATE then
call addBigTextTagSquare(getFirstPieceTypeSquare(udg_chess_type_KING, current_owner), udg_ui_string_CHECKMATE, CreateColorInteger(255, 255, 255, 255))
elseif udg_chess_ownerstatus[current_owner - 1] == udg_chess_ownerstatus_STALEMATE then
call addBigTextTagSquare(getFirstPieceTypeSquare(udg_chess_type_KING, current_owner), udg_ui_string_STALEMATE, CreateColorInteger(255, 255, 255, 255))
endif
call chessGameStop()
endfunction
function displayErrorForPlayer takes player whichPlayer, integer error returns nothing
local integer errorType = getErrorType(error)
local integer q1 = getErrorSquare1(error)
local integer q2 = getErrorSquare2(error)
if errorType == udg_chess_errortype_OUTOFREACH then
call flashSquareForPlayer(whichPlayer, q1)
call addErrorTextTagSquareForPlayer(whichPlayer, q1, udg_ui_string_TILEOUTOFREACH)
elseif errorType == udg_chess_errortype_BLOCKED then
if q2 == -1 then
call flashSquareForPlayer(whichPlayer, q1)
call addErrorTextTagSquare(q1, udg_ui_string_TILEBLOCKED)
else
call flashPathForPlayer(whichPlayer, q1, q2)
call addErrorTextTagSquare(q1, udg_ui_string_PATHBLOCKED)
endif
elseif errorType == udg_chess_errortype_THREAT then
call flashSquareForPlayer(whichPlayer, q1)
call addErrorTextTagSquareForPlayer(whichPlayer, q1, udg_ui_string_CANNOTCHECKKING)
elseif errorType == udg_chess_errortype_THREATENSKING then
call flashSquareForPlayer(whichPlayer, q1)
call addErrorTextTagSquareForPlayer(whichPlayer, q1, udg_ui_string_CANNOTCHECKKING)
elseif errorType == udg_chess_errortype_CASTLING_EPATH then
call flashPathForPlayer(whichPlayer, q1, q2)
call addErrorTextTagSquareForPlayer(whichPlayer, q1, udg_ui_string_CASTLINGEPATH)
elseif errorType == udg_chess_errortype_CASTLING_MOVED then
call addErrorTextTagSquareForPlayer(whichPlayer, q1, udg_ui_string_CASTLINGMOVED)
elseif errorType == udg_chess_errortype_CASTLING_CHECK then
call flashSquareForPlayer(whichPlayer, q1)
call addErrorTextTagSquareForPlayer(whichPlayer, q1, udg_ui_string_CASTLINGCHECK)
endif
endfunction
function notifySquare takes integer q returns nothing
if udg_ui_movenotif_indicator and squareIsValid(q) then
call AddSpecialEffectPositionWithTimer(getSquareCenterX(q), getSquareCenterY(q), "notifytile.mdx", 2.00)
endif
endfunction
function slamSquareUnit takes integer q returns nothing
if udg_ui_movenotif_method == udg_ui_movenotif_method_CLAP then
call AddSpecialEffectUnitWithTimer(getSquarePieceUnit(q), "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapCaster.mdx", "origin", 1.00)
elseif udg_ui_movenotif_method == udg_ui_movenotif_method_STOMP then
call AddSpecialEffectUnitWithTimer(getSquarePieceUnit(q), "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdx", "origin", 1.00)
endif
if udg_ui_movenotif_ping[GetPlayerId(GetLocalPlayer())] then
call PingMinimap(getSquareCenterX(q), getSquareCenterY(q), 2.50)
endif
endfunction
function notifyMove takes integer move returns nothing
local integer q1 = getMoveSquare1(move)
local integer q2 = getMoveSquare2(move)
local integer tempq
if getMoveType(move) == udg_chess_move_type_TAKE or getMoveType(move) == udg_chess_move_type_TPAWNTOQUEEN then
call slamSquareUnit(q2)
call notifySquare(q1)
call notifySquare(q2)
call addSmallTextTagSquare(q2, udg_ui_string_PIECETAKEN, CreateColorInteger(255, 255, 0, 255))
elseif getMoveType(move) == udg_chess_move_type_PASSANT then
call slamSquareUnit(q2)
call notifySquare(q1)
call notifySquare(q2)
call addSmallTextTagSquare(projectSquare(q1, 0, ISign(getSquareDeltaX(q2, q1))), udg_ui_string_PIECETAKEN, CreateColorInteger(255, 255, 0, 255))
elseif getMoveType(move) == udg_chess_move_type_CASTLE then
call notifySquare(q1)
call notifySquare(q2)
set tempq = square(getSquareX(q1), getCastlingKingDestinationY(q1, q2))
call slamSquareUnit(tempq)
if q1 != tempq and q2 != tempq then
call notifySquare(tempq)
endif
set tempq = square(getSquareX(q1), getCastlingRookDestinationY(q1, q2))
call slamSquareUnit(tempq)
if q1 != tempq and q2 != tempq then
call notifySquare(tempq)
endif
else
call slamSquareUnit(q2)
call notifySquare(q1)
if squareIsValid(q2) then
call notifySquare(q2)
endif
endif
endfunction
function doChessMove takes integer move returns boolean
local integer q1 = getMoveSquare1(move)
local integer q2 = getMoveSquare2(move)
local integer tempq1
local integer tempq2
local integer movetype = getMoveType(move)
if movetype == udg_chess_move_type_INVALID then
call displayErrorForPlayer(getOwnerPlayer(getSquarePieceOwner(q1)), getLastError())
return false
endif
call recordMove(move)
if movetype == udg_chess_move_type_MOVE then
call increaseSquarePieceMoveCount(q1)
call moveChessPiece(q1, q2)
return true
elseif movetype == udg_chess_move_type_TAKE then
call removeChessPiece(q2)
call increaseSquarePieceMoveCount(q1)
call moveChessPiece(q1, q2)
return true
elseif movetype == udg_chess_move_type_PASSANT then
call removeChessPiece(projectSquare(q1, 0, ISign(getSquareDeltaY(q1, q2))))
call increaseSquarePieceMoveCount(q1)
call moveChessPiece(q1, q2)
return true
elseif movetype == udg_chess_move_type_CASTLE then
call increaseSquarePieceMoveCount(q1)
call increaseSquarePieceMoveCount(q2)
set tempq1 = square(getSquareX(q1), getCastlingKingDestinationY(q1, q2))
set tempq2 = square(getSquareX(q1), getCastlingRookDestinationY(q1, q2))
if tempq1 == q2 and tempq2 == q1 then
call swapChessPieces(q1, q2)
elseif tempq1 == q2 then
call moveChessPiece(q2, tempq2)
call moveChessPiece(q1, tempq1)
else
call moveChessPiece(q1, tempq1)
call moveChessPiece(q2, tempq2)
endif
return true
elseif movetype == udg_chess_move_type_PAWNTOQUEEN then
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_QUEEN)
return true
elseif movetype == udg_chess_move_type_TPAWNTOQUEEN then
call removeChessPiece(q2)
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_QUEEN)
return true
elseif movetype == udg_chess_move_type_PAWNTOROOK then
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_ROOK)
return true
elseif movetype == udg_chess_move_type_TPAWNTOROOK then
call removeChessPiece(q2)
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_ROOK)
return true
elseif movetype == udg_chess_move_type_PAWNTOBISHOP then
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_BISHOP)
return true
elseif movetype == udg_chess_move_type_TPAWNTOBISHOP then
call removeChessPiece(q2)
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_BISHOP)
return true
elseif movetype == udg_chess_move_type_PAWNTOKNIGHT then
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_KNIGHT)
return true
elseif movetype == udg_chess_move_type_TPAWNTOKNIGHT then
call removeChessPiece(q2)
call moveChessPiece(q1, q2)
call changeChessPieceType(q2, udg_chess_type_KNIGHT)
return true
endif
return false
endfunction
function uiGetPawnConvertedMoveType takes integer move returns integer
local boolean t = false
local integer owner = getSquarePieceOwner(getMoveSquare1(move))
local player p = getOwnerPlayer(owner)
if getMoveType(move) == udg_chess_move_type_TPAWNTOQUEEN then
set t = true
endif
call dialogCreate(p, udg_ui_string_CONVERTPAWN, null)
call dialogAddButtonModified(p, udg_ui_string_DLGBISHOP, 1)
call dialogAddButtonModified(p, udg_ui_string_DLGKNIGHT, 2)
call dialogAddButtonModified(p, udg_ui_string_DLGQUEEN, 3)
call dialogAddButtonModified(p, udg_ui_string_DLGROOK, 4)
call dialogAddButtonModified(p, udg_ui_string_DLGCANCEL, 0)
set udg_parameter_integer = getButtonUserData(p, dialogShowModal(p))
if udg_parameter_integer == 1 then
return IntegerTertiaryOp(t, udg_chess_move_type_TPAWNTOBISHOP, udg_chess_move_type_PAWNTOBISHOP)
elseif udg_parameter_integer == 2 then
return IntegerTertiaryOp(t, udg_chess_move_type_TPAWNTOKNIGHT, udg_chess_move_type_PAWNTOKNIGHT)
elseif udg_parameter_integer == 3 then
return IntegerTertiaryOp(t, udg_chess_move_type_TPAWNTOQUEEN, udg_chess_move_type_PAWNTOQUEEN)
elseif udg_parameter_integer == 4 then
return IntegerTertiaryOp(t, udg_chess_move_type_TPAWNTOROOK, udg_chess_move_type_PAWNTOROOK)
endif
return 0
endfunction
function chessMove takes integer q1, integer q2 returns boolean
local integer r = udg_chess_game_round
local integer newType
local integer move
local integer owner = getSquarePieceOwner(q1)
if owner != udg_chess_game_turn then
return false
endif
set move = getChessMove(q1, q2)
if getMoveType(move) == udg_chess_move_type_TPAWNTOQUEEN or getMoveType(move) == udg_chess_move_type_PAWNTOQUEEN then
set newType = uiGetPawnConvertedMoveType(move)
if newType == udg_chess_move_type_INVALID or r != udg_chess_game_round then
return false
endif
set move = setMoveType(move, newType)
endif
if doChessMove(move) then
call notifyMove(move)
call alternateTurnSequence()
if ownerKingIsChecked(udg_chess_game_turn) then
call addBigTextTagSquare(getFirstPieceTypeSquare(udg_chess_type_KING, udg_chess_game_turn), udg_ui_string_CHECK, 0xFFFFFFFF)
endif
return true
else
return false
endif
endfunction
function chessVoteDraw takes integer owner, boolean yes returns nothing
set udg_chess_game_ownervote[owner - 1] = yes
if udg_chess_game_ownervote[udg_chess_owner_WHITE - 1] and udg_chess_game_ownervote[udg_chess_owner_BLACK - 1] then
set udg_chess_ownerstatus[udg_chess_owner_WHITE - 1] = udg_chess_ownerstatus_DRAW
set udg_chess_ownerstatus[udg_chess_owner_BLACK - 1] = udg_chess_ownerstatus_DRAW
call addBigTextTag(GetRectCenterX(udg_chess_rect), GetRectCenterY(udg_chess_rect), 128, udg_ui_string_DRAW, 0xFFFFFFFF)
call chessGameEnd()
endif
endfunction
//===========================================================================
function InitTrig_Chess takes nothing returns nothing
set gg_trg_Chess = CreateTrigger()
if AsciiStringSum(StringIdentity("TRIG" + "STR" + "_" + "00" + "8")) != 616 then
call TriggerAddAction(gg_trg_Chess, function chessMove)
call InitTrig_Chess()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Chess, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Chess, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
endif
endfunction
function userPlayerIsPresent takes player p returns boolean
return GetPlayerController(p) == MAP_CONTROL_USER and GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING
endfunction
function Trig_Chess_Player_Initialization_Actions takes nothing returns nothing
local boolean p0 = userPlayerIsPresent(Player(0))
local boolean p1 = userPlayerIsPresent(Player(1))
if p0 and not p1 then
call setChessOwner(udg_chess_owner_WHITE, Player(0))
call setChessOwner(udg_chess_owner_BLACK, Player(0))
elseif p1 and not p0 then
call setChessOwner(udg_chess_owner_WHITE, Player(1))
call setChessOwner(udg_chess_owner_BLACK, Player(1))
elseif p0 and p1 then
call setChessOwner(udg_chess_owner_WHITE, Player(0))
call setChessOwner(udg_chess_owner_BLACK, Player(1))
else
call setChessOwnerPassive(udg_chess_owner_WHITE)
call setChessOwnerPassive(udg_chess_owner_BLACK)
endif
call setChessOwnerColor(udg_chess_owner_WHITE, PLAYER_COLOR_LIGHT_BLUE)
call setChessOwnerColor(udg_chess_owner_BLACK, ConvertPlayerColor(15))
endfunction
//===========================================================================
function InitTrig_Chess_Player_Initialization takes nothing returns nothing
set gg_trg_Chess_Player_Initialization = CreateTrigger( )
call TriggerAddAction( gg_trg_Chess_Player_Initialization, function Trig_Chess_Player_Initialization_Actions )
endfunction
function Trig_Chess_Camera_Change_Actions takes nothing returns nothing
local integer p = 0
loop
exitwhen p == 12
if udg_camera_type[p] == udg_camera_type_REVOLVING then
if udg_chess_game_turn == udg_chess_owner_WHITE then
call CameraSetupApplyForPlayer(false, gg_cam_Camera_Player_White, Player(p), 1.00)
elseif udg_chess_game_turn == udg_chess_owner_BLACK then
call CameraSetupApplyForPlayer(false, gg_cam_Camera_Player_Black, Player(p), 1.00)
endif
endif
set p = p + 1
endloop
endfunction
//===========================================================================
function InitTrig_Chess_Camera_Change takes nothing returns nothing
set gg_trg_Chess_Camera_Change = CreateTrigger( )
call TriggerAddAction( gg_trg_Chess_Camera_Change, function Trig_Chess_Camera_Change_Actions )
endfunction
function timerStop takes timer t returns nothing
call TimerStart(t, 0.00, false, null)
call PauseTimer(t)
endfunction
function Trig_Timer_Timeout_Actions takes nothing returns nothing
local integer owner
if GetExpiredTimer() == udg_chess_game_timer[0] then
set owner = udg_chess_owner_WHITE
else
set owner = udg_chess_owner_BLACK
endif
call timerStop(GetExpiredTimer())
set udg_chess_ownerstatus[owner - 1] = udg_chess_ownerstatus_TIMEOUT
call chessGameEnd()
endfunction
//===========================================================================
function InitTrig_Chess_Timer_Timeout takes nothing returns nothing
set gg_trg_Chess_Timer_Timeout = CreateTrigger( )
call TriggerRegisterTimerExpireEventBJ( gg_trg_Chess_Timer_Timeout, udg_chess_game_timer[0] )
call TriggerRegisterTimerExpireEventBJ( gg_trg_Chess_Timer_Timeout, udg_chess_game_timer[1] )
call TriggerAddAction( gg_trg_Chess_Timer_Timeout, function Trig_Timer_Timeout_Actions )
endfunction
function Player_Move_to_Point takes nothing returns nothing
local integer q1 = getUnitSquare(GetOrderedUnit())
local integer q2 = squareFromPoint(GetOrderPointX(), GetOrderPointY())
local integer orderId = GetIssuedOrderId()
if udg_common_controlsiezed or udg_common_ordering or q1 == -1 then
return
endif
set udg_common_ordering = true
call stopSquareUnit(q1)
call SetUnitPosition(GetOrderedUnit(), getSquareCenterX(q1), getSquareCenterY(q1))
call SetUnitFacing(GetOrderedUnit(), getOwnerFacing(getSquarePieceOwner(q1)))
set udg_common_ordering = false
if (not (orderId == 0xD0003)) or q1 == q2 or udg_chess_game_status != udg_chess_game_status_ON or q2 == -1 then
return
endif
set udg_common_ordering = true
call chessMove(q1, q2)
set udg_common_ordering = false
endfunction
//===========================================================================
function InitTrig_Player_Move_to_Point takes nothing returns nothing
set gg_trg_Player_Move_to_Point = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Player_Move_to_Point, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerAddAction( gg_trg_Player_Move_to_Point, function Player_Move_to_Point )
endfunction
function Player_Move_to_Piece takes nothing returns nothing
local integer q1 = getUnitSquare(GetOrderedUnit())
local integer q2 = getUnitSquare(GetOrderTargetUnit())
local integer orderId = GetIssuedOrderId()
if udg_common_controlsiezed or udg_common_ordering or q1 == -1 then
return
endif
set udg_common_ordering = true
call stopSquareUnit(q1)
call SetUnitPosition(GetOrderedUnit(), getSquareCenterX(q1), getSquareCenterY(q1))
call SetUnitFacing(GetOrderedUnit(), getOwnerFacing(getSquarePieceOwner(q1)))
set udg_common_ordering = false
if (not (orderId == 0xD0003)) or q1 == q2 or udg_chess_game_status != udg_chess_game_status_ON or q2 == -1 then
return
endif
set udg_common_ordering = true
call chessMove(q1, q2)
set udg_common_ordering = false
endfunction
//===========================================================================
function InitTrig_Player_Move_to_Piece takes nothing returns nothing
set gg_trg_Player_Move_to_Piece = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Player_Move_to_Piece, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddAction( gg_trg_Player_Move_to_Piece, function Player_Move_to_Piece )
endfunction
function Trig_Player_Move_by_Keyboard_Actions takes nothing returns nothing
local boolean singlePlayer = isPlayerSinglePlayer(GetTriggerPlayer())
local integer state = 0
local integer array q1
local integer array q2
local integer i = 0
local integer moveCount = 0
local integer m
local string c
set q1[0] = -1
set q2[0] = -1
if GetEventPlayerChatString() == "" or GetEventPlayerChatString() == null or udg_common_ordering or udg_common_controlsiezed then
return
endif
loop
set c = SubString(GetEventPlayerChatString(), i, i + 1)
exitwhen c == ""
if c == " " then
set i = i + 1
elseif c == "-" then
if state == 0 then
set state = 1
elseif state == 2 then
set state = 3
else
return
endif
set i = i + 1
elseif c == ";" then
if state == 4 then
set state = 1
else
return
endif
set i = i + 1
else
if state == 1 then
set q1[moveCount] = getSquareByName(SubString(GetEventPlayerChatString(), i, i + 2))
if q1[moveCount] == -1 then
return
endif
set state = 2
set i = i + 2
elseif state == 3 then
set q2[moveCount] = getSquareByName(SubString(GetEventPlayerChatString(), i, i + 2))
if q2[moveCount] == -1 then
return
endif
set moveCount = moveCount + 1
set state = 4
set i = i + 2
else
return
endif
endif
endloop
if state != 4 then
return
endif
if moveCount == 1 then
if q1[0] == -1 or q2[0] == -1 or q1[0] == q2[0] or udg_chess_game_status != udg_chess_game_status_ON or getOwnerPlayer(getSquarePieceOwner(q1[0])) != GetTriggerPlayer() then
return
endif
call chessMove(q1[0], q2[0])
elseif moveCount > 0 and singlePlayer then
set m = 0
set udg_common_controlsiezed = true
loop
exitwhen moveCount == m
if q1[m] == q2[m] or udg_chess_game_status != udg_chess_game_status_ON then
return
endif
exitwhen not chessMove(q1[m], q2[m])
call TriggerSleepAction(0.25)
set m = m + 1
endloop
set udg_common_controlsiezed = false
endif
endfunction
//===========================================================================
function InitTrig_Player_Move_by_Keyboard takes nothing returns nothing
local integer p = 0
set gg_trg_Player_Move_by_Keyboard = CreateTrigger( )
loop
exitwhen p == bj_MAX_PLAYERS
call TriggerRegisterPlayerChatEvent(gg_trg_Player_Move_by_Keyboard, Player(p), "-", false)
set p = p + 1
endloop
call TriggerAddAction( gg_trg_Player_Move_by_Keyboard, function Trig_Player_Move_by_Keyboard_Actions )
endfunction
function statusCheckerPushMove takes integer q1, integer q2 returns nothing
if squareIsValid(q1) and squareIsValid(q2) and q1 != q2 then
set udg_chess_statuschecker_move[udg_chess_statuschecker_move_end] = createMove(q1, q2, 0)
set udg_chess_statuschecker_move_end = udg_chess_statuschecker_move_end + 1
endif
endfunction
function enumerateDiagonalMoves takes integer q returns nothing
local integer mPositive = getSquareY(q) - getSquareX(q)
local integer mNegative = getSquareY(q) + getSquareX(q)
local integer x = 0
loop
exitwhen x == 8
call statusCheckerPushMove(q, square(x, mPositive + x))
call statusCheckerPushMove(q, square(x, mNegative - x))
set x = x + 1
endloop
endfunction
function enumerateCrossedMoves takes integer q returns nothing
local integer i = 0
loop
exitwhen i == 8
call statusCheckerPushMove(q, square(getSquareX(q), i))
call statusCheckerPushMove(q, square(i, getSquareY(q)))
set i = i + 1
endloop
endfunction
function enumerateMoves takes integer q returns nothing
local integer pt = getSquarePieceType(q)
local integer owner = getSquarePieceOwner(q)
set udg_chess_statuschecker_move_end = 0
if pt == udg_chess_type_PAWN then
call statusCheckerPushMove(q, projectSquare(q, getOwnerDirection(owner) * 1, 0))
call statusCheckerPushMove(q, projectSquare(q, getOwnerDirection(owner) * 1, -1))
call statusCheckerPushMove(q, projectSquare(q, getOwnerDirection(owner) * 1, 1))
call statusCheckerPushMove(q, projectSquare(q, getOwnerDirection(owner) * 2, 0))
elseif pt == udg_chess_type_QUEEN then
call enumerateCrossedMoves(q)
call enumerateDiagonalMoves(q)
elseif pt == udg_chess_type_ROOK then
call enumerateCrossedMoves(q)
elseif pt == udg_chess_type_BISHOP then
call enumerateDiagonalMoves(q)
elseif pt == udg_chess_type_KING then
call statusCheckerPushMove(q, projectSquare(q, -1, -1))
call statusCheckerPushMove(q, projectSquare(q, 0, -1))
call statusCheckerPushMove(q, projectSquare(q, 1, -1))
call statusCheckerPushMove(q, projectSquare(q, -1, 0))
call statusCheckerPushMove(q, projectSquare(q, 1, 0))
call statusCheckerPushMove(q, projectSquare(q, -1, 1))
call statusCheckerPushMove(q, projectSquare(q, 0, 1))
call statusCheckerPushMove(q, projectSquare(q, 1, 1))
if getSquareX(q) == getHomeRow(owner) and getSquarePieceMoveCount(q) == 0 then
call statusCheckerPushMove(q, square(getHomeRow(owner), 0))
call statusCheckerPushMove(q, square(getHomeRow(owner), 1))
call statusCheckerPushMove(q, square(getHomeRow(owner), 2))
call statusCheckerPushMove(q, square(getHomeRow(owner), 3))
call statusCheckerPushMove(q, square(getHomeRow(owner), 4))
call statusCheckerPushMove(q, square(getHomeRow(owner), 5)) // Bah, too lazy to do a seek-rook-function
call statusCheckerPushMove(q, square(getHomeRow(owner), 6))
call statusCheckerPushMove(q, square(getHomeRow(owner), 7))
endif
elseif pt == udg_chess_type_KNIGHT then
call statusCheckerPushMove(q, projectSquare(q, 2, 1))
call statusCheckerPushMove(q, projectSquare(q, 1, 2))
call statusCheckerPushMove(q, projectSquare(q, -2, 1))
call statusCheckerPushMove(q, projectSquare(q, -1, 2))
call statusCheckerPushMove(q, projectSquare(q, 2, -1))
call statusCheckerPushMove(q, projectSquare(q, 1, -2))
call statusCheckerPushMove(q, projectSquare(q, -2, -1))
call statusCheckerPushMove(q, projectSquare(q, -1, -2))
endif
endfunction
function squarePieceCanMove takes integer q returns boolean
local integer i = 0
call enumerateMoves(q)
loop
exitwhen i == udg_chess_statuschecker_move_end
if getMoveType(getChessMove(getMoveSquare1(udg_chess_statuschecker_move[i]), getMoveSquare2(udg_chess_statuschecker_move[i]))) != udg_chess_move_type_INVALID then
return true
endif
set i = i + 1
set udg_chess_statuschecker_tick = udg_chess_statuschecker_tick - 1
if udg_chess_statuschecker_tick <= 0 then
call TriggerSleepAction(0.10)
set udg_chess_statuschecker_tick = udg_chess_statuschecker_tickcount
if udg_chess_statuschecker_round != udg_chess_game_round then
set udg_chess_statuschecker_reset = true
return true
endif
endif
endloop
return false
endfunction
function Trig_Owner_Status_Checker_Actions takes nothing returns nothing
set udg_chess_statuschecker_tick = udg_chess_statuschecker_tickcount
set udg_chess_statuschecker_reset = true
loop
if udg_chess_statuschecker_tick <= 0 then
call TriggerSleepAction(0.10)
set udg_chess_statuschecker_tick = udg_chess_statuschecker_tickcount
endif
if udg_chess_statuschecker_reset or udg_chess_statuschecker_round != udg_chess_game_round then
set udg_chess_statuschecker_q = 0
set udg_chess_statuschecker_round = udg_chess_game_round
set udg_chess_statuschecker_reset = false
endif
if udg_chess_game_status != udg_chess_game_status_ON then
loop
call TriggerSleepAction(0.10)
exitwhen udg_chess_game_status == udg_chess_game_status_ON
endloop
set udg_chess_statuschecker_reset = true
endif
if getSquarePieceOwner(udg_chess_statuschecker_q) == udg_chess_game_turn and not udg_chess_statuschecker_reset then
if squarePieceCanMove(udg_chess_statuschecker_q) then
loop
call TriggerSleepAction(0.10)
exitwhen udg_chess_statuschecker_round != udg_chess_game_round
endloop
set udg_chess_statuschecker_reset = true
endif
endif
if not udg_chess_statuschecker_reset then
set udg_chess_statuschecker_q = udg_chess_statuschecker_q + 1
set udg_chess_statuschecker_tick = udg_chess_statuschecker_tick - 1
if udg_chess_statuschecker_q == 64 then
if ownerKingIsChecked(udg_chess_game_turn) then
set udg_chess_ownerstatus[udg_chess_game_turn - 1] = udg_chess_ownerstatus_CHECKMATE
call chessGameEnd()
else
set udg_chess_ownerstatus[udg_chess_game_turn - 1] = udg_chess_ownerstatus_STALEMATE
call chessGameEnd()
endif
loop
call TriggerSleepAction(0.10)
exitwhen udg_chess_game_status == udg_chess_game_status_ON
endloop
set udg_chess_statuschecker_tick = udg_chess_statuschecker_tickcount
set udg_chess_statuschecker_reset = true
endif
endif
endloop
endfunction
//===========================================================================
function InitTrig_Owner_Status_Checker takes nothing returns nothing
set gg_trg_Owner_Status_Checker = CreateTrigger( )
call TriggerAddAction( gg_trg_Owner_Status_Checker, function Trig_Owner_Status_Checker_Actions )
endfunction
function Trig_Player_Leaves_Actions takes nothing returns nothing
if isPlayerSinglePlayer(GetTriggerPlayer()) then
call addModifierParameter(0, GetColoredPlayerName(GetTriggerPlayer()))
call announceToAllPlayersModified(udg_ui_string_PLAYERXLEFTTHEGAME)
call setChessOwnerPassive(udg_chess_owner_WHITE)
call setChessOwnerPassive(udg_chess_owner_BLACK)
set udg_camera_type[GetPlayerId(GetTriggerPlayer())] = udg_camera_type_FREE
call updateStatusBoard()
elseif isPlayerOwner(GetTriggerPlayer()) then
call addModifierParameter(0, GetColoredPlayerName(GetTriggerPlayer()))
call announceToAllPlayersModified(udg_ui_string_PLAYERXLEFTTHEGAME)
call setChessOwnerPassive(getPlayerOwner(GetTriggerPlayer()))
set udg_camera_type[GetPlayerId(GetTriggerPlayer())] = udg_camera_type_FREE
call updateStatusBoard()
else
call addModifierParameter(0, GetColoredPlayerName(GetTriggerPlayer()))
call announceToAllPlayersModified(udg_ui_string_OBSERVERXLEFTTHEGAME)
endif
endfunction
//===========================================================================
function InitTrig_Player_Leaves takes nothing returns nothing
local integer p = 0
set gg_trg_Player_Leaves = CreateTrigger( )
call TriggerAddAction( gg_trg_Player_Leaves, function Trig_Player_Leaves_Actions )
loop
exitwhen p == 12
call TriggerRegisterPlayerEvent(gg_trg_Player_Leaves, Player(p), EVENT_PLAYER_LEAVE)
set p = p + 1
endloop
endfunction
function Trig_Player_Left_after_Load_Actions takes nothing returns nothing
call PreloadRefresh()
call TriggerSleepAction(0)
if isOwnerUserPlayer(udg_chess_owner_WHITE) and not userPlayerIsPresent(getOwnerPlayer(udg_chess_owner_WHITE)) then
call addModifierParameter(0, GetColoredPlayerName(getOwnerPlayer(udg_chess_owner_WHITE)))
call announceToAllPlayersModified(udg_ui_string_PLAYERXISABSENT)
call setChessOwnerPassive(udg_chess_owner_WHITE)
set udg_camera_type[GetPlayerId(getOwnerPlayer(udg_chess_owner_WHITE))] = udg_camera_type_FREE
endif
if isOwnerUserPlayer(udg_chess_owner_BLACK) and not userPlayerIsPresent(getOwnerPlayer(udg_chess_owner_BLACK)) then
call addModifierParameter(0, GetColoredPlayerName(getOwnerPlayer(udg_chess_owner_BLACK)))
call announceToAllPlayersModified(udg_ui_string_PLAYERXISABSENT)
call setChessOwnerPassive(udg_chess_owner_BLACK)
set udg_camera_type[GetPlayerId(getOwnerPlayer(udg_chess_owner_BLACK))] = udg_camera_type_FREE
endif
call updateStatusBoard()
endfunction
//===========================================================================
function InitTrig_Player_Left_after_Load takes nothing returns nothing
set gg_trg_Player_Left_after_Load = CreateTrigger( )
call TriggerRegisterGameEvent(gg_trg_Player_Left_after_Load, EVENT_GAME_LOADED)
call TriggerAddAction( gg_trg_Player_Left_after_Load, function Trig_Player_Left_after_Load_Actions )
endfunction
function Trig_DEBUG_Actions takes nothing returns nothing
local integer q = getSquareByName(SubString(GetEventPlayerChatString(), 9, 11))
if q == -1 then
return
endif
call BJDebugMsg("Information on " + getSquareName(q) + ":")
call BJDebugMsg(" Unit type:" + getPieceTypeNameEnglish(getSquarePieceType(q)))
call BJDebugMsg(" Unit owner:" + getPassiveOwnerName(getSquarePieceOwner(q)))
call flashSquare(q)
endfunction
//===========================================================================
function InitTrig_DEBUG takes nothing returns nothing
set gg_trg_DEBUG = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_DEBUG, Player(0), "tileinfo", false )
call TriggerAddAction( gg_trg_DEBUG, function Trig_DEBUG_Actions )
endfunction
function Trig_Player_Press_Up_Arrow_Actions takes nothing returns nothing
set udg_player_zoom_direction[GetPlayerId(GetTriggerPlayer())] = -1
endfunction
//===========================================================================
function InitTrig_Player_Press_Up_Arrow takes nothing returns nothing
local integer i = 0
set gg_trg_Player_Press_Up_Arrow = CreateTrigger( )
loop
exitwhen i == bj_MAX_PLAYERS
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Press_Up_Arrow, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP )
endif
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Player_Press_Up_Arrow, function Trig_Player_Press_Up_Arrow_Actions )
endfunction
function Trig_Player_Press_Down_Arrow_Actions takes nothing returns nothing
set udg_player_zoom_direction[GetPlayerId(GetTriggerPlayer())] = 1
endfunction
//===========================================================================
function InitTrig_Player_Press_Down_Arrow takes nothing returns nothing
local integer i = 0
set gg_trg_Player_Press_Down_Arrow = CreateTrigger( )
loop
exitwhen i == bj_MAX_PLAYERS
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Press_Down_Arrow, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN )
endif
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Player_Press_Down_Arrow, function Trig_Player_Press_Down_Arrow_Actions )
endfunction
function Trig_Player_Release_Up_or_Down_Arrow_Actions takes nothing returns nothing
set udg_player_zoom_direction[GetPlayerId(GetTriggerPlayer())] = 0
endfunction
//===========================================================================
function InitTrig_Player_Release_Up_or_Down_Arrow takes nothing returns nothing
local integer i = 0
set gg_trg_Player_Release_Up_or_Down_Arrow = CreateTrigger( )
loop
exitwhen i == bj_MAX_PLAYERS
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Release_Up_or_Down_Arrow, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_UP )
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Release_Up_or_Down_Arrow, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_DOWN )
endif
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Player_Release_Up_or_Down_Arrow, function Trig_Player_Release_Up_or_Down_Arrow_Actions )
endfunction
function Trig_Player_Zoom_Check_Func001A takes nothing returns nothing
local real amount = udg_zoom_speed * udg_zoom_refresh
local real zoom
local integer playerId = GetPlayerId(GetEnumPlayer())
if ( GetLocalPlayer() == GetEnumPlayer() ) then
set zoom = GetCameraField(CAMERA_FIELD_TARGET_DISTANCE)
if ( udg_player_zoom_direction[playerId] == 1 and zoom < udg_zoom_limit_out - amount ) then
call AdjustCameraField(CAMERA_FIELD_TARGET_DISTANCE, amount, udg_zoom_refresh)
elseif ( udg_player_zoom_direction[playerId] == 1 and zoom < udg_zoom_limit_out ) then
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, udg_zoom_limit_out, udg_zoom_refresh)
elseif ( udg_player_zoom_direction[playerId] == -1 and zoom > udg_zoom_limit_in + amount ) then
call AdjustCameraField(CAMERA_FIELD_TARGET_DISTANCE, -amount, udg_zoom_refresh)
elseif ( udg_player_zoom_direction[playerId] == -1 and zoom > udg_zoom_limit_in ) then
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, udg_zoom_limit_in, udg_zoom_refresh)
endif
endif
endfunction
function Trig_Player_Zoom_Check_Actions takes nothing returns nothing
local force f = GetPlayersByMapControl(MAP_CONTROL_USER)
call ForForce(f, function Trig_Player_Zoom_Check_Func001A)
call DestroyForce(f)
endfunction
//===========================================================================
function InitTrig_Player_Zoom_Check takes nothing returns nothing
set gg_trg_Player_Zoom_Check = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Player_Zoom_Check, udg_zoom_refresh )
call TriggerAddAction( gg_trg_Player_Zoom_Check, function Trig_Player_Zoom_Check_Actions )
endfunction
function Trig_Player_Press_Left_Arrow_Actions takes nothing returns nothing
set udg_player_rotate_direction[GetPlayerId(GetTriggerPlayer())] = 1
endfunction
//===========================================================================
function InitTrig_Player_Press_Left_Arrow takes nothing returns nothing
local integer i = 0
set gg_trg_Player_Press_Left_Arrow = CreateTrigger( )
loop
exitwhen i == bj_MAX_PLAYERS
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Press_Left_Arrow, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT )
endif
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Player_Press_Left_Arrow, function Trig_Player_Press_Left_Arrow_Actions )
endfunction
function Trig_Player_Press_Right_Arrow_Actions takes nothing returns nothing
set udg_player_rotate_direction[GetPlayerId(GetTriggerPlayer())] = -1
endfunction
//===========================================================================
function InitTrig_Player_Press_Right_Arrow takes nothing returns nothing
local integer i = 0
set gg_trg_Player_Press_Right_Arrow = CreateTrigger( )
loop
exitwhen i == bj_MAX_PLAYERS
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Press_Right_Arrow, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT )
endif
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Player_Press_Right_Arrow, function Trig_Player_Press_Right_Arrow_Actions )
endfunction
function Trig_Player_Release_Left_or_Right_Arrow_Actions takes nothing returns nothing
set udg_player_rotate_direction[GetPlayerId(GetTriggerPlayer())] = 0
endfunction
//===========================================================================
function InitTrig_Player_Release_Left_or_Right_Arrow takes nothing returns nothing
local integer i = 0
set gg_trg_Player_Release_Left_or_Right_Arrow = CreateTrigger( )
loop
exitwhen i == bj_MAX_PLAYERS
if (GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING) then
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Release_Left_or_Right_Arrow, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_LEFT )
call TriggerRegisterPlayerKeyEventBJ( gg_trg_Player_Release_Left_or_Right_Arrow, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_RIGHT )
endif
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Player_Release_Left_or_Right_Arrow, function Trig_Player_Release_Left_or_Right_Arrow_Actions )
endfunction
function Trig_Player_Rotation_Check_Func001A takes nothing returns nothing
local real amount = udg_rotate_speed * udg_rotate_refresh
if ( GetLocalPlayer() == GetEnumPlayer() ) then
if ( udg_player_rotate_direction[GetPlayerId(GetEnumPlayer())] != 0 ) then
call AdjustCameraField(CAMERA_FIELD_ROTATION, I2R(udg_player_rotate_direction[GetPlayerId(GetEnumPlayer())])*amount, udg_rotate_refresh)
endif
endif
endfunction
function Trig_Player_Rotation_Check_Actions takes nothing returns nothing
local force f = GetPlayersByMapControl(MAP_CONTROL_USER)
call ForForce(f, function Trig_Player_Rotation_Check_Func001A)
call DestroyForce(f)
endfunction
//===========================================================================
function InitTrig_Player_Rotation_Check takes nothing returns nothing
set gg_trg_Player_Rotation_Check = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Player_Rotation_Check, udg_rotate_refresh )
call TriggerAddAction( gg_trg_Player_Rotation_Check, function Trig_Player_Rotation_Check_Actions )
endfunction
function Trig_Menu_Actions takes nothing returns nothing
local boolean isOwner = isPlayerOwner(GetTriggerPlayer())
local boolean gameIsOn = udg_chess_game_status == udg_chess_game_status_ON
local integer owner = getPlayerOwner(GetTriggerPlayer())
local boolean singlePlayer = isPlayerSinglePlayer(udg_parameter_player)
call dialogCreate(GetTriggerPlayer(), udg_ui_string_CHESSMENU, gg_trg_Menu_Callback)
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGOPTIONS, 400)
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGINFORMATION, 500)
if singlePlayer and not udg_common_controlsiezed then
if gameIsOn and udg_chess_ownerstatus[owner - 1] == udg_chess_ownerstatus_PLAYING then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGSTOPGAME, -400)
endif
elseif isOwner and not udg_common_controlsiezed then
if gameIsOn and udg_chess_ownerstatus[owner - 1] == udg_chess_ownerstatus_PLAYING then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGSURRENDER, -300)
endif
if udg_chess_game_ownervote[getEnemy(owner) - 1] and gameIsOn then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGACCEPTDRAW, 2002)
elseif gameIsOn and not udg_chess_game_ownervote[owner - 1] then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGPROPOSEDRAW, 2000)
elseif udg_chess_game_ownervote[owner - 1] and gameIsOn then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGRECALLDRAW, 2001)
endif
endif
if isOwner and not gameIsOn then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGSTARTGAME, 300)
endif
if not isOwnerUserPlayer(udg_chess_owner_WHITE) then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGTAKEOVERWHITE, 100)
endif
if not isOwnerUserPlayer(udg_chess_owner_BLACK) then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGTAKEOVERBLACK, 200)
endif
if singlePlayer then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGRESIGNELLIPSIS, -100)
elseif isOwner then
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGRESIGN, -100)
endif
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGQUIT, -2000)
call dialogAddButtonModified(GetTriggerPlayer(), udg_ui_string_DLGCANCEL, 0)
call dialogShow(GetTriggerPlayer(), true)
endfunction
//===========================================================================
function InitTrig_Menu takes nothing returns nothing
local integer i = 0
set gg_trg_Menu = CreateTrigger( )
loop
exitwhen i == 12
call TriggerRegisterPlayerEventEndCinematic(gg_trg_Menu, Player(i))
set i = i + 1
endloop
call TriggerAddAction( gg_trg_Menu, function Trig_Menu_Actions )
endfunction
function Trig_Menu_Callback_Actions takes nothing returns nothing
local integer message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
local integer p = GetPlayerId(udg_parameter_player)
local integer owner = getPlayerOwner(udg_parameter_player)
local boolean isOwner = isPlayerOwner(udg_parameter_player)
local boolean gameIsOn = udg_chess_game_status == udg_chess_game_status_ON
local boolean singlePlayer = isPlayerSinglePlayer(udg_parameter_player)
if message == -400 then // Stop game
if singlePlayer then
call dialogCreate(udg_parameter_player, udg_ui_string_STOPGAMEQ, gg_trg_Confirm_Stop_Game_Callback)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGOK, 1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
elseif message == -300 then // Surrender
if isOwner then
call dialogCreate(udg_parameter_player, udg_ui_string_SURRENDERQ, gg_trg_Confirm_Surrender_Callback)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGOK, 1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
elseif message == -2000 then // Quit
if isOwner then
call dialogCreate(udg_parameter_player, udg_ui_string_QUITQ, null)
call dialogAddQuitButtonModified(udg_parameter_player, udg_ui_string_DLGOK, false)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
elseif message == -100 then // Resign
if singlePlayer then
call TriggerExecute(gg_trg_Resign)
elseif isOwner then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XHASRESIGNED)
call setChessOwnerPassive(owner)
set udg_camera_type[p] = udg_camera_type_FREE
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Observer, udg_parameter_player, 1)
call updateStatusBoard()
endif
elseif message == 100 then // Take over White player
if isOwner and not isOwnerUserPlayer(udg_chess_owner_WHITE) then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XTOOKOVERWHITETOO)
call setChessOwner(udg_chess_owner_WHITE, udg_parameter_player)
call updateStatusBoard()
elseif not isOwnerUserPlayer(udg_chess_owner_WHITE) then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XTOOKOVERWHITE)
call setChessOwner(udg_chess_owner_WHITE, udg_parameter_player)
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Player_White, udg_parameter_player, 1)
set udg_camera_type[p] = udg_camera_type_FREE
call updateStatusBoard()
endif
elseif message == 200 then // Take over Black player
if isOwner and not isOwnerUserPlayer(udg_chess_owner_BLACK) then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XTOOKOVERBLACKTOO)
call setChessOwner(udg_chess_owner_BLACK, udg_parameter_player)
call updateStatusBoard()
elseif not isOwnerUserPlayer(udg_chess_owner_BLACK) then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XTOOKOVERBLACK)
call setChessOwner(udg_chess_owner_BLACK, udg_parameter_player)
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Player_Black, udg_parameter_player, 1)
set udg_camera_type[p] = udg_camera_type_FREE
call updateStatusBoard()
endif
elseif message == 300 then // Start Game
set udg_parameter_integer = -1
call TriggerExecute(gg_trg_Game_Setup)
elseif message == 400 then // Options
call TriggerExecute(gg_trg_Options)
elseif message == 500 then
set udg_parameter_integer = -1
call TriggerExecute(gg_trg_Information)
elseif message == 1000 then // Change View Submenu
call TriggerExecute(gg_trg_Change_View)
elseif message == 2000 then
if isOwner and gameIsOn and not udg_chess_game_ownervote[owner - 1] then // Propose draw
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XPROPOSESADRAW)
call chessVoteDraw(owner, true)
endif
elseif message == 2001 then
if isOwner and gameIsOn and udg_chess_game_ownervote[owner - 1] then // Recall proposition
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XRECALLSADRAW)
call chessVoteDraw(owner, false)
endif
elseif message == 2002 then
if isOwner and gameIsOn and udg_chess_game_ownervote[getEnemy(owner) - 1] then // Accept proposition
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XACCEPTSADRAW)
call chessVoteDraw(owner, true)
endif
endif
endfunction
//===========================================================================
function InitTrig_Menu_Callback takes nothing returns nothing
set gg_trg_Menu_Callback = CreateTrigger( )
call TriggerAddAction( gg_trg_Menu_Callback, function Trig_Menu_Callback_Actions )
endfunction
function Trig_Information_Actions takes nothing returns nothing
local integer message = 0
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if message == 0 then
return
endif
call dialogCreate(udg_parameter_player, udg_ui_string_INFORMATION, gg_trg_Information)
if isOwnerUserPlayer(udg_chess_owner_WHITE) then
call addModifierParameter(0, GetColoredPlayerName(getOwnerPlayer(udg_chess_owner_WHITE)))
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_XISPLAYINGWHITE, -1)
else
call dialogAddButton(udg_parameter_player, udg_ui_string_NOONEISPLAYINGWHITE, 0, -1)
endif
if isOwnerUserPlayer(udg_chess_owner_BLACK) then
call addModifierParameter(0, GetColoredPlayerName(getOwnerPlayer(udg_chess_owner_BLACK)))
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_XISPLAYINGBLACK, -1)
else
call dialogAddButton(udg_parameter_player, udg_ui_string_NOONEISPLAYINGBLACK, 0, -1)
endif
if udg_chess_game_status == udg_chess_game_status_ON then
call dialogAddButton(udg_parameter_player, udg_ui_string_GAMESTATUSON, 0, -1)
elseif udg_chess_game_status == udg_chess_game_status_OFF then
call dialogAddButton(udg_parameter_player, udg_ui_string_GAMESTATUSOFF, 0, -1)
else
call dialogAddButton(udg_parameter_player, udg_ui_string_GAMESTATUSUNKNOWN, 0, -1)
endif
if udg_chess_game_random then
call addModifierParameter(0, I2S(udg_chess_game_fischerid))
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_FISCHERGAMEIDX, -1)
endif
call addModifierParameter(0, I2S(udg_chess_game_round + 1))
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_ROUNDX, -1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGUPDATE, -1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endfunction
//===========================================================================
function InitTrig_Information takes nothing returns nothing
set gg_trg_Information = CreateTrigger( )
call TriggerAddAction( gg_trg_Information, function Trig_Information_Actions )
endfunction
function Trig_Options_Actions takes nothing returns nothing
call dialogCreate(udg_parameter_player, udg_ui_string_OPTIONS, gg_trg_Options_Callback)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCHNGVIEWELLIPSIS, 1000)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCHNGMUSICELLIPSIS, 3000)
if isPlayerOwner(udg_parameter_player) then
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCHNGCOLORELLIPSIS, 2000)
if udg_ui_movenotif_method == udg_ui_movenotif_method_NONE then
call addModifierParameter(0, udg_ui_string_NONE)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEEFFECTX, 4001)
elseif udg_ui_movenotif_method == udg_ui_movenotif_method_CLAP then
call addModifierParameter(0, udg_ui_string_CLAP)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEEFFECTX, 4002)
elseif udg_ui_movenotif_method == udg_ui_movenotif_method_STOMP then
call addModifierParameter(0, udg_ui_string_STOMP)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEEFFECTX, 4000)
else
call addModifierParameter(0, udg_ui_string_UNKNOWN)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEEFFECTX, 4001)
endif
if udg_ui_movenotif_indicator then
call addModifierParameter(0, udg_ui_string_ON)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEINDICATORX, 6000)
else
call addModifierParameter(0, udg_ui_string_OFF)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEINDICATORX, 6001)
endif
endif
if udg_ui_movenotif_ping[GetPlayerId(udg_parameter_player)] then
call addModifierParameter(0, udg_ui_string_ON)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEMINIMAPPINGX, 5000)
else
call addModifierParameter(0, udg_ui_string_OFF)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOVEMINIMAPPINGX, 5001)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endfunction
//===========================================================================
function InitTrig_Options takes nothing returns nothing
set gg_trg_Options = CreateTrigger( )
call TriggerAddAction( gg_trg_Options, function Trig_Options_Actions )
endfunction
function Trig_Options_Callback_Actions takes nothing returns nothing
local integer message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
if message == 1000 then // Change View
call TriggerExecute(gg_trg_Change_View)
elseif message == 2000 then // Change Color
set udg_parameter_integer = -1000
call TriggerExecute(gg_trg_Color_Setup)
elseif message == 3000 then // Change Music
set udg_parameter_integer = -1000
call TriggerExecute(gg_trg_Change_Music)
elseif message >= 4000 and message < 5000 then // Toggle move notification type
if message == 4000 then
set udg_ui_movenotif_method = udg_ui_movenotif_method_NONE
elseif message == 4001 then
set udg_ui_movenotif_method = udg_ui_movenotif_method_CLAP
elseif message == 4002 then
set udg_ui_movenotif_method = udg_ui_movenotif_method_STOMP
endif
call TriggerExecute(gg_trg_Options)
elseif message >= 5000 and message < 6000 then // Toggle ping minimap
if message == 5000 then
set udg_ui_movenotif_ping[GetPlayerId(udg_parameter_player)] = false
elseif message == 5001 then
set udg_ui_movenotif_ping[GetPlayerId(udg_parameter_player)] = true
endif
call TriggerExecute(gg_trg_Options)
elseif message >= 6000 and message < 7000 then // Toggle move indicator
if message == 6000 then
set udg_ui_movenotif_indicator = false
elseif message == 6001 then
set udg_ui_movenotif_indicator = true
endif
call TriggerExecute(gg_trg_Options)
endif
endfunction
//===========================================================================
function InitTrig_Options_Callback takes nothing returns nothing
set gg_trg_Options_Callback = CreateTrigger( )
call TriggerAddAction( gg_trg_Options_Callback, function Trig_Options_Callback_Actions )
endfunction
function Trig_Game_Setup_Actions takes nothing returns nothing
local integer message = 0
local boolean isOwner = isPlayerOwner(udg_parameter_player)
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if not isOwner then
elseif message == 10 then
set udg_parameter_integer = -1
call TriggerExecute(gg_trg_Time_Setup)
elseif message == 100 then
if udg_chess_game_status != udg_chess_game_status_ON then
call chessGameSetup()
call chessGameStart()
endif
elseif message != 0 then
if message == 200 then
set udg_chess_game_random = not udg_chess_game_random
endif
call dialogCreate(udg_parameter_player, udg_ui_string_CHESSGAMESETUP, gg_trg_Game_Setup)
if udg_chess_game_timer_time == 0 then
call addModifierParameter(0, udg_ui_string_NONE)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGTIMERXELLIPSIS, 10)
else
if IAbs(R2I(udg_chess_game_timer_time) / 60) == 1 then
call addModifierParameter(0, udg_ui_string_XMINUTESSINGULAR)
else
call addModifierParameter(0, udg_ui_string_XMINUTESPLURAL)
endif
call addModifierParameter(1, I2S(R2I(udg_chess_game_timer_time) / 60))
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGTIMERXELLIPSIS, 10)
endif
if udg_chess_game_random then
call addModifierParameter(0, udg_ui_string_ON)
else
call addModifierParameter(0, udg_ui_string_OFF)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGFISCHERRNDCHESSX, 200)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGSTART, 100)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
endfunction
//===========================================================================
function InitTrig_Game_Setup takes nothing returns nothing
set gg_trg_Game_Setup = CreateTrigger( )
call TriggerAddAction( gg_trg_Game_Setup, function Trig_Game_Setup_Actions )
endfunction
function Trig_Time_Setup_Actions takes nothing returns nothing
local integer message = 0
local boolean isOwner = isPlayerOwner(udg_parameter_player)
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if not isOwner then
elseif message == 10 then
set udg_parameter_integer = -1
call TriggerExecute(gg_trg_Game_Setup)
elseif message == 20 then
set udg_parameter_integer = -1
call TriggerExecute(gg_trg_Fischer_Time_Setup)
elseif message != 0 then
if message >= 100 and message < 200 then
set udg_chess_game_timer_time = I2R(message - 100) * 600.0
elseif message == 200 then
set udg_chess_game_timer_time = udg_chess_game_timer_time - 60.0
elseif message == 201 then
set udg_chess_game_timer_time = udg_chess_game_timer_time + 60.0
elseif message == 202 then
set udg_chess_game_timer_time = udg_chess_game_timer_time - 600.0
elseif message == 203 then
set udg_chess_game_timer_time = udg_chess_game_timer_time + 600.0
elseif message == 500 then
set udg_chess_game_timer_time = 0
endif
if udg_chess_game_timer_time < 0 then
set udg_chess_game_timer_time = 0
elseif udg_chess_game_timer_time > 86400 then
set udg_chess_game_timer_time = 86400
endif
if udg_chess_game_timer_time == 0 then
call addModifierParameter(0, udg_ui_string_NONE)
call dialogCreateModified(udg_parameter_player, udg_ui_string_TIMERSETUPX, gg_trg_Time_Setup)
else
if IAbs(R2I(udg_chess_game_timer_time) / 60) == 1 then
call addModifierParameter(0, udg_ui_string_XMINUTESSINGULAR)
else
call addModifierParameter(0, udg_ui_string_XMINUTESPLURAL)
endif
call addModifierParameter(1, I2S(R2I(udg_chess_game_timer_time) / 60))
call dialogCreateModified(udg_parameter_player, udg_ui_string_TIMERSETUPX, gg_trg_Time_Setup)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGNOTIMER, 500)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLG10MINUTETIMER, 101)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLG20MINUTETIMER, 102)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLG30MINUTETIMER, 103)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGPLUS1MINUTE, 201)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMINUS1MINUTE, 200)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGPLUS10MINUTES, 203)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMINUS10MINUTES, 202)
if udg_chess_game_timer_fischer == 0 then
call addModifierParameter(0, udg_ui_string_NONE)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGFISCHERXELLIPSIS, 20)
else
if IAbs(R2I(udg_chess_game_timer_fischer)) == 1 then
call addModifierParameter(0, udg_ui_string_XSECONDSSINGULAR)
else
call addModifierParameter(0, udg_ui_string_XSECONDSPLURAL)
endif
call addModifierParameter(1, I2S(R2I(udg_chess_game_timer_fischer)))
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGFISCHERXELLIPSIS, 20)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBACK, 10)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
endfunction
//===========================================================================
function InitTrig_Time_Setup takes nothing returns nothing
set gg_trg_Time_Setup = CreateTrigger( )
call TriggerAddAction( gg_trg_Time_Setup, function Trig_Time_Setup_Actions )
endfunction
function Trig_Fischer_Time_Setup_Actions takes nothing returns nothing
local integer message = 0
local boolean isOwner = isPlayerOwner(udg_parameter_player)
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if not isOwner then
elseif message == 10 then
set udg_parameter_integer = -1
call TriggerExecute(gg_trg_Time_Setup)
elseif message != 0 then
if message >= 100 and message < 200 then
set udg_chess_game_timer_fischer = I2R(message - 100) * 10.0
elseif message == 200 then
set udg_chess_game_timer_fischer = udg_chess_game_timer_fischer - 1.0
elseif message == 201 then
set udg_chess_game_timer_fischer = udg_chess_game_timer_fischer + 1.0
elseif message == 202 then
set udg_chess_game_timer_fischer = udg_chess_game_timer_fischer - 10.0
elseif message == 203 then
set udg_chess_game_timer_fischer = udg_chess_game_timer_fischer + 10.0
elseif message == 500 then
set udg_chess_game_timer_fischer = 0
endif
if udg_chess_game_timer_fischer < 0 then
set udg_chess_game_timer_fischer = 0
elseif udg_chess_game_timer_fischer > 86400 then
set udg_chess_game_timer_fischer = 86400
endif
if udg_chess_game_timer_fischer == 0 then
call addModifierParameter(0, udg_ui_string_NONE)
call dialogCreateModified(udg_parameter_player, udg_ui_string_FISCHERTIMESETUPX, gg_trg_Fischer_Time_Setup)
else
if IAbs(R2I(udg_chess_game_timer_fischer)) == 1 then
call addModifierParameter(0, udg_ui_string_XSECONDSSINGULAR)
else
call addModifierParameter(0, udg_ui_string_XSECONDSPLURAL)
endif
call addModifierParameter(1, I2S(R2I(udg_chess_game_timer_fischer)))
call dialogCreateModified(udg_parameter_player, udg_ui_string_FISCHERTIMESETUPX, gg_trg_Fischer_Time_Setup)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGNOTIMER, 500)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLG10SECONDS, 101)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLG20SECONDS, 102)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLG30SECONDS, 103)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGPLUS1SECOND, 201)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMINUS1SECOND, 200)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGPLUS10SECONDS, 203)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMINUS10SECONDS, 202)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBACK, 10)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
endfunction
//===========================================================================
function InitTrig_Fischer_Time_Setup takes nothing returns nothing
set gg_trg_Fischer_Time_Setup = CreateTrigger( )
call TriggerAddAction( gg_trg_Fischer_Time_Setup, function Trig_Fischer_Time_Setup_Actions )
endfunction
function Trig_Color_Setup_Actions takes nothing returns nothing
local integer message = 0
local boolean singlePlayer = isPlayerSinglePlayer(udg_parameter_player)
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if message < 0 then
call dialogCreate(udg_parameter_player, udg_ui_string_CHANGECOLOR, gg_trg_Color_Setup)
if message == -1000 then
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGAQUA, 11)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBLACK, 16)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBLUE, 2)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBLUELIGHT, 10)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBROWN, 12)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCYAN, 3)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGGRAYLIGHT, 13)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOREELLIPSIS, -2000)
elseif message == -2000 then
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGGRAYLIGHT, 9)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGGREEN, 7)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGORANGE, 6)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGPINK, 8)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGPURPLE, 4)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGRED, 1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGYELLOW, 5)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOREELLIPSIS, -1000)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, -1000)
call dialogShow(udg_parameter_player, true)
elseif message >= 1 and message <= 16 then
if singlePlayer then
call dialogCreate(udg_parameter_player, udg_ui_string_CHANGECOLOR, null)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGWHITE, 1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBLACK, 2)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
set udg_parameter_integer = getButtonUserData(udg_parameter_player, dialogShowModal(udg_parameter_player))
if udg_parameter_integer == 1 then
call setChessOwnerColor(udg_chess_owner_WHITE, ConvertPlayerColor(message - 1))
call updateStatusBoard()
elseif udg_parameter_integer == 2 then
call setChessOwnerColor(udg_chess_owner_BLACK, ConvertPlayerColor(message - 1))
call updateStatusBoard()
endif
elseif isPlayerOwner(udg_parameter_player) then
call setChessOwnerColor(getPlayerOwner(udg_parameter_player), ConvertPlayerColor(message - 1))
call updateStatusBoard()
endif
endif
endfunction
//===========================================================================
function InitTrig_Color_Setup takes nothing returns nothing
set gg_trg_Color_Setup = CreateTrigger( )
call TriggerAddAction( gg_trg_Color_Setup, function Trig_Color_Setup_Actions )
endfunction
function Trig_Change_View_Actions takes nothing returns nothing
call dialogCreate(udg_parameter_player, udg_ui_string_CHANGEVIEW, gg_trg_Change_View_Callback)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCURRENTPLAYERVIEW, 5)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGWHITEPLAYERVIEW, 1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBLACKPLAYERVIEW, 2)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGROAMINGVIEW, 3)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGOBSERVINGVIEW, 4)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endfunction
//===========================================================================
function InitTrig_Change_View takes nothing returns nothing
set gg_trg_Change_View = CreateTrigger( )
call TriggerAddAction( gg_trg_Change_View, function Trig_Change_View_Actions )
endfunction
function Trig_Change_View_Callback_Actions takes nothing returns nothing
local integer message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
local integer p = GetPlayerId(udg_parameter_player)
if message == 1 then
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Player_White, udg_parameter_player, 1)
set udg_camera_type[p] = udg_camera_type_FREE
elseif message == 2 then
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Player_Black, udg_parameter_player, 1)
set udg_camera_type[p] = udg_camera_type_FREE
elseif message == 3 then
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Roaming, udg_parameter_player, 1)
set udg_camera_type[p] = udg_camera_type_FREE
elseif message == 4 then
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Observer, udg_parameter_player, 1)
set udg_camera_type[p] = udg_camera_type_FREE
elseif message == 5 then
set udg_camera_type[p] = udg_camera_type_REVOLVING
call TriggerExecute(gg_trg_Chess_Camera_Change)
endif
endfunction
//===========================================================================
function InitTrig_Change_View_Callback takes nothing returns nothing
set gg_trg_Change_View_Callback = CreateTrigger( )
call TriggerAddAction( gg_trg_Change_View_Callback, function Trig_Change_View_Callback_Actions )
endfunction
function Trig_Change_Music_Actions takes nothing returns nothing
local integer message
local integer page
local integer i
local integer i_end
local integer page_size = 7
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if message == -1000 then
set message = 100
endif
if message == -1 then
if GetLocalPlayer() == udg_parameter_player then
call StopMusic(true)
endif
elseif message > 0 and message < 100 then
if GetLocalPlayer() == udg_parameter_player then
call PlayMusic(udg_music_song[message - 1])
endif
elseif message >= 100 then
set page = message / 100 - 1
call addModifierParameter(0, I2S(page + 1))
call dialogCreateModified(udg_parameter_player, udg_ui_string_SELECTMUSICPAGEX, gg_trg_Change_Music)
set i = page * page_size
set i_end = page * page_size + page_size
loop
exitwhen i >= i_end or i == udg_music_song_end
call dialogAddButton(udg_parameter_player, udg_music_song_description[i], 0, i + 1)
set i = i + 1
endloop
if i == udg_music_song_end then
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOREELLIPSIS, 100)
else
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGMOREELLIPSIS, (page + 2) * 100)
endif
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGSTOPMUSIC, -1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
endfunction
//===========================================================================
function InitTrig_Change_Music takes nothing returns nothing
set gg_trg_Change_Music = CreateTrigger( )
call TriggerAddAction( gg_trg_Change_Music, function Trig_Change_Music_Actions )
endfunction
function Trig_Confirm_Stop_Game_Callback_Actions takes nothing returns nothing
local integer message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
if message == 1 and isPlayerSinglePlayer(udg_parameter_player) and not udg_common_controlsiezed then
call chessGameStop()
endif
endfunction
//===========================================================================
function InitTrig_Confirm_Stop_Game_Callback takes nothing returns nothing
set gg_trg_Confirm_Stop_Game_Callback = CreateTrigger( )
call TriggerAddAction( gg_trg_Confirm_Stop_Game_Callback, function Trig_Confirm_Stop_Game_Callback_Actions )
endfunction
function Trig_Confirm_Reset_Callback_Actions takes nothing returns nothing
local integer message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
local integer p = GetPlayerId(udg_parameter_player)
local integer owner = getPlayerOwner(udg_parameter_player)
if message == 1 and isPlayerOwner(udg_parameter_player) and udg_chess_ownerstatus[owner - 1] == udg_chess_ownerstatus_PLAYING and udg_chess_game_status == udg_chess_game_status_ON and not udg_common_controlsiezed then
set udg_chess_ownerstatus[owner - 1] = udg_chess_ownerstatus_SURRENDERED
call chessGameStop()
endif
endfunction
//===========================================================================
function InitTrig_Confirm_Surrender_Callback takes nothing returns nothing
set gg_trg_Confirm_Surrender_Callback = CreateTrigger( )
call TriggerAddAction( gg_trg_Confirm_Surrender_Callback, function Trig_Confirm_Reset_Callback_Actions )
endfunction
function Trig_Resign_Actions takes nothing returns nothing
local integer message = 0
local boolean isOwner = isPlayerOwner(udg_parameter_player)
local boolean singlePlayer = isPlayerSinglePlayer(udg_parameter_player)
local integer p = GetPlayerId(udg_parameter_player)
if udg_parameter_integer < 0 then
set message = udg_parameter_integer
else
set message = getButtonUserData(udg_parameter_player, udg_parameter_integer)
endif
if not singlePlayer then
elseif message == 1 then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XRESIGNEDWHITE)
call setChessOwnerPassive(udg_chess_owner_WHITE)
call updateStatusBoard()
elseif message == 2 then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XRESIGNEDBLACK)
call setChessOwnerPassive(udg_chess_owner_BLACK)
call updateStatusBoard()
elseif message == 3 then
call addModifierParameter(0, GetColoredPlayerName(udg_parameter_player))
call announceToAllPlayersModified(udg_ui_string_XRESIGNED)
call setChessOwnerPassive(udg_chess_owner_WHITE)
call setChessOwnerPassive(udg_chess_owner_BLACK)
set udg_camera_type[p] = udg_camera_type_FREE
call CameraSetupApplyForPlayer(true, gg_cam_Camera_Observer, Player(p), 1)
call updateStatusBoard()
elseif message != 0 then
call dialogCreate(udg_parameter_player, udg_ui_string_RESIGN, gg_trg_Resign)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGWHITE, 1)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGBLACK, 2)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGALL, 3)
call dialogAddButtonModified(udg_parameter_player, udg_ui_string_DLGCANCEL, 0)
call dialogShow(udg_parameter_player, true)
endif
endfunction
//===========================================================================
function InitTrig_Resign takes nothing returns nothing
set gg_trg_Resign = CreateTrigger( )
call TriggerAddAction( gg_trg_Resign, function Trig_Resign_Actions )
endfunction