diff --git a/bricks/execall.cs b/bricks/execall.cs index 48f2cc5..a992101 100644 --- a/bricks/execall.cs +++ b/bricks/execall.cs @@ -25,3 +25,4 @@ exec("./outputs/TextBrick2.cs"); exec("./special/EventGate.cs"); exec("./special/rom.cs"); +exec("./special/robot.cs"); diff --git a/bricks/special/robot-init.lua b/bricks/special/robot-init.lua index 0bd3480..fc56888 100644 --- a/bricks/special/robot-init.lua +++ b/bricks/special/robot-init.lua @@ -1,5 +1,6 @@ return function(gate) + print("robot init") gate.brickcolor = 0 gate.brickcolorfx = 0 gate.brickshapefx = 0 diff --git a/bricks/special/robot-input.lua b/bricks/special/robot-input.lua index 2ca6230..610b32c 100644 --- a/bricks/special/robot-input.lua +++ b/bricks/special/robot-input.lua @@ -7,13 +7,16 @@ local function intToPort(gate, port, len, v) end return function(gate, argv) + print("robot input") + print(argv[1]) for word in argv[1]:gmatch("[^\t]+") do local first, rest = word:sub(1, 1), word:sub(2, #word) local vec = {} for a in rest:gmatch("[^ ]+") do table.insert(vec, tonumber(a) or error("invalid number "..a)) end if first=="P" then -- set position - assert(#vec==3, "invalid position given to robot: "..word) - brick.robotpos = vec + assert(#vec==4, "invalid position given to robot: "..word) + brick.robotpos = {vec[1], vec[2], vec[3]} + brick.robotdir = vec[4] elseif first=="B" then -- detected brick info assert(#vec==7, "invalid brick info given to robot: "..word) gate.brickexists = vec[1] diff --git a/bricks/special/robot-update.lua b/bricks/special/robot-update.lua index 674d712..5b695a5 100644 --- a/bricks/special/robot-update.lua +++ b/bricks/special/robot-update.lua @@ -16,6 +16,7 @@ local function rotateVector(vec, rot) end return function(gate) + print("robot update") if not gate.waiting then local action = "" if Gate.getportstate(gate, 7)~=0 then -- remove brick @@ -56,6 +57,8 @@ return function(gate) end if action~="" then + print("robot action") + print(action) Gate.cb(gate, action:sub(1, #action-1)) gate.waiting = true end diff --git a/bricks/special/robot.cs b/bricks/special/robot.cs index b1193f6..78c92bf 100644 --- a/bricks/special/robot.cs +++ b/bricks/special/robot.cs @@ -9,7 +9,7 @@ if(!isObject(LuaLogic_RobotBrickGroup)) { } datablock StaticShapeData(LuaLogic_RobotShapeData) { - shapeFile = "./cube.dts"; + shapeFile = $LuaLogic::Path @ "bricks/special/cube.dts"; }; datablock fxDTSBrickData(LogicGate_RobotController_Data) { @@ -24,7 +24,7 @@ datablock fxDTSBrickData(LogicGate_RobotController_Data) { isLogic = true; isLogicGate = true; - isLogicInput = true; + //isLogicInput = true; logicInit = lualogic_readfile($LuaLogic::Path @ "bricks/special/robot-init.lua" ); logicUpdate = lualogic_readfile($LuaLogic::Path @ "bricks/special/robot-update.lua"); @@ -69,41 +69,49 @@ datablock fxDTSBrickData(LogicGate_RobotController_Data) { logicPortPos[6] = "1 -3 0"; logicPortDir[6] = 3; logicPortUIName[6] = "Destroy Brick"; + logicPortCauseUpdate[6] = true; logicPortType[7] = 1; logicPortPos[7] = "-1 -3 0"; logicPortDir[7] = 3; logicPortUIName[7] = "Plant Brick"; + logicPortCauseUpdate[7] = true; logicPortType[8] = 1; logicPortPos[8] = "-5 -3 0"; logicPortDir[8] = 3; logicPortUIName[8] = "Move Down"; + logicPortCauseUpdate[8] = true; logicPortType[9] = 1; logicPortPos[9] = "-7 -3 0"; logicPortDir[9] = 3; logicPortUIName[9] = "Move Up"; + logicPortCauseUpdate[9] = true; logicPortType[10] = 1; logicPortPos[10] = "-9 -3 0"; logicPortDir[10] = 3; logicPortUIName[10] = "Move Right"; + logicPortCauseUpdate[10] = true; logicPortType[11] = 1; logicPortPos[11] = "-11 -3 0"; logicPortDir[11] = 3; logicPortUIName[11] = "Move Left"; + logicPortCauseUpdate[11] = true; logicPortType[12] = 1; logicPortPos[12] = "-13 -3 0"; logicPortDir[12] = 3; logicPortUIName[12] = "Move Backward"; + logicPortCauseUpdate[12] = true; logicPortType[13] = 1; logicPortPos[13] = "-15 -3 0"; logicPortDir[13] = 3; logicPortUIName[13] = "Move Forward"; + logicPortCauseUpdate[13] = true; logicPortType[14] = 0; logicPortPos[14] = "15 3 0"; @@ -144,9 +152,12 @@ datablock fxDTSBrickData(LogicGate_RobotController_Data) { logicPortPos[21] = "-1 3 0"; logicPortDir[21] = 1; logicPortUIName[21] = "Detect Brick"; + logicPortCauseUpdate[21] = true; }; function LogicGate_RobotController_Data::LuaLogic_Callback(%this, %brick, %data) { + talk("robot cb " @ %brick SPC %data); + %robot = %brick.luaLogicRobot; if(!isObject(%robot)) { talk("brick " @ %brick @ " has no robot!"); return; } %pos = %robot.getPosition(); @@ -163,7 +174,7 @@ function LogicGate_RobotController_Data::LuaLogic_Callback(%this, %brick, %data) if(%first $= "R" || %first $= "D") { // remove / detect brick if(isObject(%tbrick)) { if(%first $= "D") { - %field = "B" SPC + %field = "B" @ 1 SPC %tbrick.getColorId() SPC %tbrick.getColorFxID() SPC %tbrick.getShapeFxId() SPC @@ -174,6 +185,8 @@ function LogicGate_RobotController_Data::LuaLogic_Callback(%this, %brick, %data) } else if(%first $= "R") { %tbrick.schedule(0, delete); } + } else { + %output = %output @ "B 0 0 0 0 0 0 0\t"; } } else if(%first $= "P") { // plant brick %nbrick = new fxDTSBrick() { @@ -229,7 +242,7 @@ function LogicGate_RobotController_Data::createRobot(%this, %obj) { %obj.luaLogicRobot = %robot; - lualogic_sendinput(%brick, 1, "P" @ %rpos); + lualogic_sendinput(%obj, 1, "P" @ %rpos SPC %obj.getAngleId()); } function LogicGate_RobotController_Data::onDeath(%this, %obj) {