Merge pull request #4220 from CrAzYPiLoT-SS13/chess_ma_dudes

Adds SpessChess!
This commit is contained in:
Fox McCloud
2016-04-23 21:05:53 -04:00
25 changed files with 3113 additions and 0 deletions
@@ -890,6 +890,15 @@ obj/item/weapon/circuitboard/rdserver
/obj/item/weapon/stock_parts/manipulator = 1,
/obj/item/weapon/stock_parts/console_screen = 1)
/obj/item/weapon/circuitboard/gameboard
name = "circuit board (Virtual Gameboard)"
build_path = /obj/machinery/gameboard
board_type = "machine"
origin_tech = "programming=2"
req_components = list(
/obj/item/weapon/stock_parts/micro_laser = 1,
/obj/item/stack/cable_coil = 3,
/obj/item/stack/sheet/glass = 1)
//Selectable mode board, like vending machine boards
/obj/item/weapon/circuitboard/logic_gate
+79
View File
@@ -0,0 +1,79 @@
/obj/machinery/gameboard
name = "Virtual Gameboard"
icon = 'icons/obj/stationobjs.dmi'
icon_state = "gboard_on"
desc = "A holographic table allowing the crew to have fun™ on boring shifts! One player per board."
density = 1
anchored = 1
use_power = 1
/obj/machinery/gameboard/New()
..()
component_parts = list()
component_parts += new /obj/item/weapon/circuitboard/gameboard(null)
component_parts += new /obj/item/weapon/stock_parts/micro_laser(null)
component_parts += new /obj/item/stack/cable_coil(null, 3)
component_parts += new /obj/item/stack/sheet/glass(null, 1)
RefreshParts()
/obj/machinery/gameboard/power_change()
. = ..()
update_icon()
/obj/machinery/gameboard/update_icon()
if(stat & NOPOWER)
icon_state = "gboard_off"
else
icon_state = "gboard_on"
/obj/machinery/gameboard/attack_hand(mob/user)
. = ..()
if(.)
return
if(src.in_use)
to_chat(user, "This gameboard is already in use!")
return
interact(user)
/obj/machinery/gameboard/interact(mob/user)
. = ..()
if(.)
return
var/dat
dat = replacetext(file2text('html/chess.html'), "\[hsrc]", "\ref[src]")
var/datum/asset/simple/chess/assets = get_asset_datum(/datum/asset/simple/chess)
assets.send(user)
var/datum/browser/popup = new(user, "SpessChess", name, 500, 800, src)
popup.set_content(dat)
popup.add_stylesheet("chess.css", 'html/browser/chess.css')
popup.add_script("garbochess.js", 'html/browser/garbochess.js')
//popup.add_script("boardui.js", 'html/browser/boardui.js')
popup.add_script("jquery-1.8.2.min.js", 'html/browser/jquery-1.8.2.min.js')
popup.add_script("jquery-ui-1.8.24.custom.min.js", 'html/browser/jquery-ui-1.8.24.custom.min.js')
popup.set_window_options("titlebar=0")
popup.open()
user.set_machine(src)
/obj/machinery/gameboard/proc/close_game() //yes, shamelessly copied over from arcade_base
in_use = 0
for(var/mob/user in viewers(world.view, src)) // I don't know who you are.
if(user.client && user.machine == src) // I will look for you,
user.unset_machine() // I will find you,
user << browse(null, "window=SpessChess") // And I will kill you.
return
/obj/machinery/gameboard/Topic(var/href, var/list/href_list)
. = ..()
var/prize = /obj/item/stack/tickets
if (.)
return
if (href_list["checkmate"])
visible_message("<span class='info'><span class='name'>[src.name]</span> beeps, \"WINNER!\"</span>")
new prize(get_turf(src), 80)
close_game()
if (href_list["close"])
close_game()
+21
View File
@@ -204,6 +204,27 @@ proc/getFilesSlow(var/client/client, var/list/files, var/register_asset = TRUE)
"ntlogo.png" = 'icons/paper_icons/ntlogo.png'
)
/datum/asset/simple/chess
assets = list(
"bishop_black.png" = 'icons/chess_pieces/bishop_black.png',
"bishop_white.png" = 'icons/chess_pieces/bishop_white.png',
"king_black.png" = 'icons/chess_pieces/king_black.png',
"king_white.png" = 'icons/chess_pieces/king_white.png',
"knight_black.png" = 'icons/chess_pieces/knight_black.png',
"knight_white.png" = 'icons/chess_pieces/knight_white.png',
"pawn_black.png" = 'icons/chess_pieces/pawn_black.png',
"pawn_white.png" = 'icons/chess_pieces/pawn_white.png',
"queen_black.png" = 'icons/chess_pieces/queen_black.png',
"queen_white.png" = 'icons/chess_pieces/queen_white.png',
"rook_black.png" = 'icons/chess_pieces/rook_black.png',
"rook_white.png" = 'icons/chess_pieces/rook_white.png',
"sprites.png" = 'icons/chess_pieces/sprites.png',
"blank.gif" = 'icons/chess_pieces/blank.gif',
"background.png" = 'nano/images/uiBackground.png',
"garbochess.js" = 'html/browser/garbochess.js',
"boardui.js" = 'html/browser/boardui.js'
)
/datum/asset/nanoui
var/list/common = list()
+395
View File
@@ -0,0 +1,395 @@
var g_startOffset = null;
var g_selectedPiece = null;
var moveNumber = 1;
var g_allMoves = [];
var g_playerWhite = true;
var g_changingFen = false;
var g_analyzing = false;
var g_uiBoard;
var g_cellSize = 45;
function UINewGame() {
moveNumber = 1;
var pgnTextBox = document.getElementById("PgnTextBox");
pgnTextBox.value = "";
EnsureAnalysisStopped();
ResetGame();
if (InitializeBackgroundEngine()) {
g_backgroundEngine.postMessage("go");
}
g_allMoves = [];
RedrawBoard();
if (!g_playerWhite) {
SearchAndRedraw();
}
}
function UIClose() {
window.location = "byond://?src=" + hSrc + ";close=1";
}
function EnsureAnalysisStopped() {
if (g_analyzing && g_backgroundEngine != null) {
g_backgroundEngine.terminate();
g_backgroundEngine = null;
}
}
function UIAnalyzeToggle() {
if (InitializeBackgroundEngine()) {
if (!g_analyzing) {
g_backgroundEngine.postMessage("analyze");
} else {
EnsureAnalysisStopped();
}
g_analyzing = !g_analyzing;
document.getElementById("AnalysisToggleLink").innerText = g_analyzing ? "Analysis: On" : "Analysis: Off";
} else {
alert("Your browser must support web workers for analysis - (chrome4, ff4, safari)");
}
}
function UIChangeFEN() {
if (!g_changingFen) {
var fenTextBox = document.getElementById("FenTextBox");
var result = InitializeFromFen(fenTextBox.value);
if (result.length != 0) {
UpdatePVDisplay(result);
return;
} else {
UpdatePVDisplay('');
}
g_allMoves = [];
EnsureAnalysisStopped();
InitializeBackgroundEngine();
g_playerWhite = !!g_toMove;
g_backgroundEngine.postMessage("position " + GetFen());
RedrawBoard();
}
}
function UIChangeStartPlayer() {
g_playerWhite = !g_playerWhite;
RedrawBoard();
}
function UpdatePgnTextBox(move) {
var pgnTextBox = document.getElementById("PgnTextBox");
if (g_toMove != 0) {
pgnTextBox.value += moveNumber + ". ";
moveNumber++;
}
pgnTextBox.value += GetMoveSAN(move) + " ";
}
function UIChangeTimePerMove() {
var timePerMove = document.getElementById("TimePerMove");
g_timeout = parseInt(timePerMove.value, 10);
}
function FinishMove(bestMove, value, timeTaken, ply) {
if (bestMove != null) {
UIPlayMove(bestMove, BuildPVMessage(bestMove, value, timeTaken, ply));
} else {
window.location = "byond://?src=" + hSrc + ";checkmate=1";
}
}
function UIPlayMove(move, pv) {
UpdatePgnTextBox(move);
g_allMoves[g_allMoves.length] = move;
MakeMove(move);
UpdatePVDisplay(pv);
UpdateFromMove(move);
}
function UIUndoMove() {
if (g_allMoves.length == 0) {
return;
}
if (g_backgroundEngine != null) {
g_backgroundEngine.terminate();
g_backgroundEngine = null;
}
UnmakeMove(g_allMoves[g_allMoves.length - 1]);
g_allMoves.pop();
if (g_playerWhite != !!g_toMove && g_allMoves.length != 0) {
UnmakeMove(g_allMoves[g_allMoves.length - 1]);
g_allMoves.pop();
}
RedrawBoard();
}
function UpdatePVDisplay(pv) {
if (pv != null) {
var outputDiv = document.getElementById("output");
if (outputDiv.firstChild != null) {
outputDiv.removeChild(outputDiv.firstChild);
}
outputDiv.appendChild(document.createTextNode(pv));
}
}
function SearchAndRedraw() {
if (g_analyzing) {
EnsureAnalysisStopped();
InitializeBackgroundEngine();
g_backgroundEngine.postMessage("position " + GetFen());
g_backgroundEngine.postMessage("analyze");
return;
}
if (InitializeBackgroundEngine()) {
g_backgroundEngine.postMessage("search " + g_timeout);
} else {
Search(FinishMove, 99, null);
}
}
var g_backgroundEngineValid = true;
var g_backgroundEngine;
function InitializeBackgroundEngine() {
if (!g_backgroundEngineValid) {
return false;
}
if (g_backgroundEngine == null) {
g_backgroundEngineValid = true;
try {
g_backgroundEngine = new Worker("garbochess.js");
g_backgroundEngine.onmessage = function (e) {
if (e.data.match("^pv") == "pv") {
UpdatePVDisplay(e.data.substr(3, e.data.length - 3));
} else if (e.data.match("^message") == "message") {
EnsureAnalysisStopped();
UpdatePVDisplay(e.data.substr(8, e.data.length - 8));
} else {
UIPlayMove(GetMoveFromString(e.data), null);
}
}
g_backgroundEngine.error = function (e) {
alert("Error from background worker:" + e.message);
}
g_backgroundEngine.postMessage("position " + GetFen());
} catch (error) {
g_backgroundEngineValid = false;
}
}
return g_backgroundEngineValid;
}
function UpdateFromMove(move) {
var fromX = (move & 0xF) - 4;
var fromY = ((move >> 4) & 0xF) - 2;
var toX = ((move >> 8) & 0xF) - 4;
var toY = ((move >> 12) & 0xF) - 2;
if (!g_playerWhite) {
fromY = 7 - fromY;
toY = 7 - toY;
fromX = 7 - fromX;
toX = 7 - toX;
}
if ((move & moveflagCastleKing) ||
(move & moveflagCastleQueen) ||
(move & moveflagEPC) ||
(move & moveflagPromotion)) {
RedrawPieces();
} else {
var fromSquare = g_uiBoard[fromY * 8 + fromX];
$(g_uiBoard[toY * 8 + toX])
.empty()
.append($(fromSquare).children());
}
}
function RedrawPieces() {
for (y = 0; y < 8; ++y) {
for (x = 0; x < 8; ++x) {
var td = g_uiBoard[y * 8 + x];
var pieceY = g_playerWhite ? y : 7 - y;
var piece = g_board[((pieceY + 2) * 0x10) + (g_playerWhite ? x : 7 - x) + 4];
var pieceName = null;
switch (piece & 0x7) {
case piecePawn: pieceName = "pawn"; break;
case pieceKnight: pieceName = "knight"; break;
case pieceBishop: pieceName = "bishop"; break;
case pieceRook: pieceName = "rook"; break;
case pieceQueen: pieceName = "queen"; break;
case pieceKing: pieceName = "king"; break;
}
if (pieceName != null) {
pieceName += "_";
pieceName += (piece & 0x8) ? "white" : "black";
}
if (pieceName != null) {
var img = document.createElement("div");
$(img).addClass('sprite-' + pieceName);
img.style.backgroundImage = "url('sprites.png')";
img.width = g_cellSize;
img.height = g_cellSize;
var divimg = document.createElement("div");
divimg.appendChild(img);
$(divimg).draggable({ start: function (e, ui) {
if (g_selectedPiece === null) {
g_selectedPiece = this;
var offset = $(this).closest('table').offset();
g_startOffset = {
left: e.pageX - offset.left,
top: e.pageY - offset.top
};
} else {
return g_selectedPiece == this;
}
}});
$(divimg).mousedown(function(e) {
if (g_selectedPiece === null) {
var offset = $(this).closest('table').offset();
g_startOffset = {
left: e.pageX - offset.left,
top: e.pageY - offset.top
};
e.stopPropagation();
g_selectedPiece = this;
g_selectedPiece.style.backgroundImage = "url('img/transpBlue50.png')";
} else if (g_selectedPiece === this) {
g_selectedPiece.style.backgroundImage = null;
g_selectedPiece = null;
}
});
$(td).empty().append(divimg);
} else {
$(td).empty();
}
}
}
}
function RedrawBoard() {
var div = $("#board")[0];
var table = document.createElement("table");
table.cellPadding = "0px";
table.cellSpacing = "0px";
$(table).addClass('no-highlight');
var tbody = document.createElement("tbody");
g_uiBoard = [];
var dropPiece = function (e, ui) {
var endX = e.pageX - $(table).offset().left;
var endY = e.pageY - $(table).offset().top;
endX = Math.floor(endX / g_cellSize);
endY = Math.floor(endY / g_cellSize);
var startX = Math.floor(g_startOffset.left / g_cellSize);
var startY = Math.floor(g_startOffset.top / g_cellSize);
if (!g_playerWhite) {
startY = 7 - startY;
endY = 7 - endY;
startX = 7 - startX;
endX = 7 - endX;
}
var moves = GenerateValidMoves();
var move = null;
for (var i = 0; i < moves.length; i++) {
if ((moves[i] & 0xFF) == MakeSquare(startY, startX) &&
((moves[i] >> 8) & 0xFF) == MakeSquare(endY, endX)) {
move = moves[i];
}
}
if (!g_playerWhite) {
startY = 7 - startY;
endY = 7 - endY;
startX = 7 - startX;
endX = 7 - endX;
}
g_selectedPiece.style.left = 0;
g_selectedPiece.style.top = 0;
if (!(startX == endX && startY == endY) && move != null) {
UpdatePgnTextBox(move);
if (InitializeBackgroundEngine()) {
g_backgroundEngine.postMessage(FormatMove(move));
}
g_allMoves[g_allMoves.length] = move;
MakeMove(move);
UpdateFromMove(move);
g_selectedPiece.style.backgroundImage = null;
g_selectedPiece = null;
var fen = GetFen();
document.getElementById("FenTextBox").value = fen;
setTimeout("SearchAndRedraw()", 0);
} else {
g_selectedPiece.style.backgroundImage = null;
g_selectedPiece = null;
}
};
for (y = 0; y < 8; ++y) {
var tr = document.createElement("tr");
for (x = 0; x < 8; ++x) {
var td = document.createElement("td");
td.style.width = g_cellSize + "px";
td.style.height = g_cellSize + "px";
td.style.backgroundColor = ((y ^ x) & 1) ? "#D18947" : "#FFCE9E";
tr.appendChild(td);
g_uiBoard[y * 8 + x] = td;
}
tbody.appendChild(tr);
}
table.appendChild(tbody);
$('body').droppable({ drop: dropPiece });
$(table).mousedown(function(e) {
if (g_selectedPiece !== null) {
dropPiece(e);
}
});
RedrawPieces();
$(div).empty();
div.appendChild(table);
g_changingFen = true;
document.getElementById("FenTextBox").value = GetFen();
g_changingFen = false;
}
+23
View File
@@ -0,0 +1,23 @@
#FenTextBox {
width: 400px;
}
#TimePerMove {
width: 50px;
}
.no-highlight {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
.sprite-bishop_black{ background-position: 0 0; width: 45px; height: 45px; }
.sprite-bishop_white{ background-position: 0 -95px; width: 45px; height: 45px; }
.sprite-king_black{ background-position: 0 -190px; width: 45px; height: 45px; }
.sprite-king_white{ background-position: 0 -285px; width: 45px; height: 45px; }
.sprite-knight_black{ background-position: 0 -380px; width: 45px; height: 45px; }
.sprite-knight_white{ background-position: 0 -475px; width: 45px; height: 45px; }
.sprite-pawn_black{ background-position: 0 -570px; width: 45px; height: 45px; }
.sprite-pawn_white{ background-position: 0 -665px; width: 45px; height: 45px; }
.sprite-queen_black{ background-position: 0 -760px; width: 45px; height: 45px; }
.sprite-queen_white{ background-position: 0 -855px; width: 45px; height: 45px; }
.sprite-rook_black{ background-position: 0 -950px; width: 45px; height: 45px; }
.sprite-rook_white{ background-position: 0 -1045px; width: 45px; height: 45px; }
background-image:url(background.png) no-repeat center center fixed;
background-size:cover;
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+31
View File
@@ -0,0 +1,31 @@
<script type="text/javascript">var hSrc = "[hsrc]"</script>
<script src="boardui.js"></script>
<script type="text/javascript">
$(document).ready(function () {
g_timeout = 1000;
UINewGame();
});
</script>
<div align="center">
<div>
<a href="javascript:UINewGame()">New game</a>
<select onchange="javascript:UIChangeStartPlayer()">
<option value="white">White</option>
<option value="black">Black</option>
</select>
Time per move: <input id="TimePerMove" value="3000" onchange="javascript:UIChangeTimePerMove()" disabled/>ms
<a href="javascript:UIUndoMove()">Undo</a>
</div>
<div style="margin-top:5px;">
<div id='board'></div>
<span id='output' style="display: none;"></span><br/>
<textarea cols='50' rows='6' id='PgnTextBox' style="display: none;"></textarea><br/>
<div style="display: none;">
<a id='AnalysisToggleLink' href="javascript:UIAnalyzeToggle()">Analysis: Off</a>
</div>
<input id='FenTextBox' onchange="javascript:UIChangeFEN()" style="display: none;"/>
</div>
<div>
<a href="javascript:UIClose()">Close</a>
</div>
</div>
Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

After

Width:  |  Height:  |  Size: 76 KiB

+1
View File
@@ -500,6 +500,7 @@
#include "code\game\machinery\flasher.dm"
#include "code\game\machinery\floodlight.dm"
#include "code\game\machinery\Freezer.dm"
#include "code\game\machinery\gameboard.dm"
#include "code\game\machinery\guestpass.dm"
#include "code\game\machinery\hologram.dm"
#include "code\game\machinery\holosign.dm"