Skip to content

Commit

Permalink
working on rez and link pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
zadium committed Nov 11, 2022
1 parent 5f8c8a1 commit 2ba2706
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 29 deletions.
86 changes: 60 additions & 26 deletions ChessBoard.lsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author: Zai Dium
@update: 2022-02-16
@revision: 225
@revision: 265
@localfile: ?defaultpath\Chess\[email protected]
@license: MIT
Expand All @@ -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;
Expand Down Expand Up @@ -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 <x, y, size.z / 2 + 0.0001>;
}

//* 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 = <x, y, size.z / 2 + 0.0001>;
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"];
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -297,7 +333,6 @@ default
setPlace("ActiveTo", 3, 2);
llListen(0, "", NULL_KEY, "");
llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);

}

on_rez(integer number)
Expand All @@ -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)
Expand Down
51 changes: 49 additions & 2 deletions Piece.lsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,61 @@
@name: Piece
@author: Zai Dium
@update: 2022-02-16
@revision: 215
@revision: 223
@localfile: ?defaultpath\Chess\[email protected]
*/

//* 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();
}
}
}
}
Binary file modified Pieces.blend
Binary file not shown.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2ba2706

Please sign in to comment.