diff --git a/ChessBoard.lsl b/ChessBoard.lsl index 29c6425..b705fb9 100644 --- a/ChessBoard.lsl +++ b/ChessBoard.lsl @@ -4,7 +4,7 @@ @author: Zai Dium @update: 2022-02-16 - @revision: 225 + @revision: 265 @localfile: ?defaultpath\Chess\?@name.lsl @license: MIT @@ -28,31 +28,48 @@ integer start_move = 0; list pieces = [ "King", "Queen", + "Rook", "Bishop", "Knight", - "Rook", "Pawn" ]; list p = [ "k", "q", - "b", - "k", "r", + "b", + "n", "p" ]; -//* lower case is black, upper case is white +//* Piece color List by color used when rez to give names +list pc = [ + "kw", + "qw", + "rw", + "bw", + "nw", + "pw", + + "kb", + "qb", + "rb", + "bb", + "nb", + "pb" +]; + +//* initial board list initBoard = [ -"r", "n", "b", "q", "k", "b", "n", "r", -"p", "p", "p", "p", "p", "p", "p", "p", +"pb", "pb", "pb", "pb", "pb", "pb", "pb", "pb", +"rb", "nb", "bb", "qb", "kb", "bb", "nb", "rb", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", -"P", "P", "P", "P", "P", "P", "P", "P", -"R", "N", "B", "Q", "K", "B", "N", "R" +"rw", "nw", "bw", "qw", "kw", "bw", "nw", "rw", +"pw", "pw", "pw", "pw", "pw", "pw", "pw", "pw" ]; list board; @@ -105,22 +122,27 @@ integer getLinkByKey(key id) { return -1; } +//* +vector calcPos(float x, float y) { + x = x * unit.x - size.x / 2 + unit.x / 2; + y = y * unit.y - size.y / 2 + unit.y / 2; + list values = llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_POS_LOCAL]); + vector pos = llList2Vector(values, 0); + return ; +} + //* coordinates by meters (inworld) -setPos(string name, float x, float y){ +setPos(string name, vector pos){ integer index = getLinkByName(name); if (index>0) { - list values = llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_POS_LOCAL]); - vector pos = llList2Vector(values, 0); - pos = ; llSetLinkPrimitiveParams(index, [PRIM_POSITION, pos]); } } //* coordinates 0-7, 0-7 setPlace(string name, float x, float y){ - x = x * unit.x - size.x / 2 + unit.x / 2; - y = y * unit.y - size.y / 2 + unit.y / 2; - setPos(name, x, y); + vector pos = calcPos(x, y); + setPos(name, pos); } list chars = ["a", "b", "c", "d", "e", "f", "g", "h"]; @@ -182,24 +204,38 @@ integer text_move(string msg) { return FALSE; } -rezObject(string name, integer param) +string guessName(integer index) { + return llList2String(pc, index); //* yes -1 based on 0 +} + +rezObject(string name, integer param, float x, float y) { - vector myPos = llGetPos(); - rotation myRot = llGetRot(); - llRezObject(name, myPos, <0, 0, 0>, myRot, param); + rotation rot = llGetRot(); + vector pos = llGetPos();// + calcPos(x, y); + llRezObject(name, pos, <0, 0, 0>, rot, param); +} + +rezPiece(string name, integer black, float x, float y) +{ + integer index = llListFindList(pieces, [name]); + if (black) + index += llGetListLength(pieces); + rezObject(name, index, x, y); + //setPlace(guessName(index), x, y); } rezObjects(){ - rezObject("Queen", 1); - rezObject("King", 2); + rezPiece("Queen", FALSE, 1, 1); + rezPiece("Queen", TRUE, 6, 1); } resetBoard() { - rezObjects(); + rezObjects(); } clearBoard(){ +// llMessageLinked(LINK_ALL_CHILDREN, 0, "die", NULL_KEY); } resized() @@ -297,7 +333,6 @@ default setPlace("ActiveTo", 3, 2); llListen(0, "", NULL_KEY, ""); llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS); - } on_rez(integer number) @@ -309,10 +344,9 @@ default { if (perm & PERMISSION_CHANGE_LINKS) - ///rezObjects(); link_perm = TRUE; else - llOwnerSay("Sorry, we can't link."); + llOwnerSay("Can't link."); } object_rez(key id) diff --git a/Piece.lsl b/Piece.lsl index f10cc29..f92adba 100644 --- a/Piece.lsl +++ b/Piece.lsl @@ -2,14 +2,61 @@ @name: Piece @author: Zai Dium @update: 2022-02-16 - @revision: 215 + @revision: 223 @localfile: ?defaultpath\Chess\?@name.lsl */ + +//* Piece color List by color used when rez to give names +list pc = [ + "kw", + "qw", + "rw", + "bw", + "nw", + "pw", + + "kb", + "qb", + "rb", + "bb", + "nb", + "pb" +]; + +string guessName(integer index) { + return llList2String(pc, index); //* yes -1 based on 0 +} + default { + state_entry() + { + } + + on_rez(integer number) + { + if (number>0) + { + string name = guessName(number - 1); //* yes -1 based on 0 + llSetObjectName(name); + if (llGetSubString(name, 1, 1) == "b") + llSetColor(<0, 0, 0>, ALL_SIDES); + } + } + touch(integer num_detected) { - llMessageLinked(LINK_ROOT, 0, "touch", llGetLinkNumber()); + llMessageLinked(LINK_ROOT, llGetStartParameter(), "touch", llGetKey()); } + link_message( integer sender_num, integer num, string str, key id ) + { + if (str=="die") + { + if (llGetStartParameter()>0) + { + //llDie(); + } + } + } } diff --git a/Pieces.blend b/Pieces.blend index 5b1e164..c1c9e2e 100644 Binary files a/Pieces.blend and b/Pieces.blend differ diff --git a/README.md b/README.md index b129dbb..b3daeff 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ In object mode, select all, export as Dae file, Import it to opensim using Fires * Rezz it in the world * Set texture and color to white * Unlink all chessboard - * Rename it to right name, care about letter case, "King", "Queen", "Rock", "Bishop", "Knight", "Pown" + * Rename it to right name, care about letter case, "King", "Queen", "Rook", "Bishop", "Knight", "Pown" + * Copy Piece.lsl script into each one * Take it all * Copy it to into root of ChessBoard * Reset scripts