Fixed automatic registration to not break gate datablock transmission
This commit is contained in:
parent
5f58a531a8
commit
d47e6a50dc
@ -1,171 +1,201 @@
|
|||||||
function lualogic_addwire(%wire)
|
function lualogic_addwire(%wire)
|
||||||
{
|
{
|
||||||
%color = %wire.getColorID();
|
%color = %wire.getColorID();
|
||||||
|
|
||||||
%box = %wire.getWorldBox();
|
%box = %wire.getWorldBox();
|
||||||
|
|
||||||
%minX = mFloatLength(getWord(%box, 0)*2, 0)/2;
|
%minX = mFloatLength(getWord(%box, 0)*2, 0)/2;
|
||||||
%minY = mFloatLength(getWord(%box, 1)*2, 0)/2;
|
%minY = mFloatLength(getWord(%box, 1)*2, 0)/2;
|
||||||
%minZ = mFloatLength(getWord(%box, 2)*5, 0)/5;
|
%minZ = mFloatLength(getWord(%box, 2)*5, 0)/5;
|
||||||
|
|
||||||
%maxX = mFloatLength(getWord(%box, 3)*2, 0)/2;
|
%maxX = mFloatLength(getWord(%box, 3)*2, 0)/2;
|
||||||
%maxY = mFloatLength(getWord(%box, 4)*2, 0)/2;
|
%maxY = mFloatLength(getWord(%box, 4)*2, 0)/2;
|
||||||
%maxZ = mFloatLength(getWord(%box, 5)*5, 0)/5;
|
%maxZ = mFloatLength(getWord(%box, 5)*5, 0)/5;
|
||||||
|
|
||||||
%min = lualogic_pos(%minX SPC %minY SPC %minZ);
|
%min = lualogic_pos(%minX SPC %minY SPC %minZ);
|
||||||
%max = lualogic_pos(%maxX SPC %maxY SPC %maxZ);
|
%max = lualogic_pos(%maxX SPC %maxY SPC %maxZ);
|
||||||
|
|
||||||
lualogic_send("W;" @ %wire.getID() @ ";" @ %color @ ";" @ %min @ ";" @ %max);
|
lualogic_send("W;" @ %wire.getID() @ ";" @ %color @ ";" @ %min @ ";" @ %max);
|
||||||
%wire.logicIsAdded = true;
|
%wire.logicIsAdded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_addgate(%gate)
|
function lualogic_addgate(%gate)
|
||||||
{
|
{
|
||||||
%db = %gate.getDataBlock();
|
%db = %gate.getDataBlock();
|
||||||
%pos = lualogic_pos(%gate.getPosition());
|
%pos = lualogic_pos(%gate.getPosition());
|
||||||
%rot = %gate.angleId;
|
%rot = %gate.angleId;
|
||||||
|
|
||||||
%data = "G;" @ %gate.getID() @ ";" @ %db @ ";" @ %pos @ ";" @ %rot;
|
%data = "G;" @ %gate.getID() @ ";" @ %db @ ";" @ %pos @ ";" @ %rot;
|
||||||
|
|
||||||
lualogic_send(%data);
|
lualogic_send(%data);
|
||||||
%gate.logicIsAdded = true;
|
%gate.logicIsAdded = true;
|
||||||
|
|
||||||
if(isFunction(%db.getName(), "Logic_onAdd"))
|
if(isFunction(%db.getName(), "Logic_onAdd"))
|
||||||
%db.Logic_onAdd(%gate);
|
%db.Logic_onAdd(%gate);
|
||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_removewire(%wire)
|
function lualogic_removewire(%wire)
|
||||||
{
|
{
|
||||||
if(%wire.logicIsRemoved == false)
|
if(%wire.logicIsRemoved == false)
|
||||||
{
|
{
|
||||||
lualogic_send("RW;" @ %wire);
|
lualogic_send("RW;" @ %wire);
|
||||||
%wire.logicIsRemoved = true;
|
%wire.logicIsRemoved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_removegate(%gate)
|
function lualogic_removegate(%gate)
|
||||||
{
|
{
|
||||||
if(%gate.logicIsRemoved == false)
|
if(%gate.logicIsRemoved == false)
|
||||||
{
|
{
|
||||||
%db = %gate.getDataBlock();
|
%db = %gate.getDataBlock();
|
||||||
if(isFunction(%db.getName(), "Logic_onRemove"))
|
if(isFunction(%db.getName(), "Logic_onRemove"))
|
||||||
%db.Logic_onRemove(%gate);
|
%db.Logic_onRemove(%gate);
|
||||||
|
|
||||||
lualogic_send("RG;" @ %gate);
|
lualogic_send("RG;" @ %gate);
|
||||||
%gate.logicIsRemoved = true;
|
%gate.logicIsRemoved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_sendall()
|
function lualogic_sendall()
|
||||||
{
|
{
|
||||||
%groups = mainBrickGroup.getCount();
|
%groups = mainBrickGroup.getCount();
|
||||||
for(%i = 0; %i < %groups; %i++)
|
for(%i = 0; %i < %groups; %i++)
|
||||||
{
|
{
|
||||||
%group = mainBrickGroup.getObject(%i);
|
%group = mainBrickGroup.getObject(%i);
|
||||||
%bricks = %group.getCount();
|
%bricks = %group.getCount();
|
||||||
for(%a = 0; %a < %bricks; %a++)
|
for(%a = 0; %a < %bricks; %a++)
|
||||||
{
|
{
|
||||||
%brick = %group.getObject(%a);
|
%brick = %group.getObject(%a);
|
||||||
%data = %brick.getDataBlock();
|
%data = %brick.getDataBlock();
|
||||||
if(%data.isLogic && %brick.isPlanted())
|
if(%data.isLogic && %brick.isPlanted())
|
||||||
{
|
{
|
||||||
if(%data.isLogicWire)
|
if(%data.isLogicWire)
|
||||||
lualogic_addwire(%brick);
|
lualogic_addwire(%brick);
|
||||||
else if(%data.isLogicGate)
|
else if(%data.isLogicGate)
|
||||||
lualogic_addgate(%brick);
|
lualogic_addgate(%brick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fxDTSBrick::Logic_SetOutput(%this, %port, %state)
|
function fxDTSBrick::Logic_SetOutput(%this, %port, %state)
|
||||||
{
|
{
|
||||||
lualogic_send("SP;" @ %this @ ";" @ %port+1 @ ";" @ %state);
|
lualogic_send("SP;" @ %this @ ";" @ %port+1 @ ";" @ %state);
|
||||||
}
|
}
|
||||||
|
|
||||||
package LuaLogic_Bricks
|
function fxDtsBrick::Logic_HandlePlant(%brick){
|
||||||
{
|
if(!%brick.Logic_HasPlanted){
|
||||||
function fxDTSBrickData::onPlant(%this, %brick)
|
%brick.Logic_HasPlanted = true;
|
||||||
{
|
|
||||||
parent::onPlant(%this, %brick);
|
%data = %brick.getDatablock();
|
||||||
|
if(isFunction(%data.getName(), "Logic_onPlant")){
|
||||||
if(isObject(%brick) && %this.isLogic)
|
%data.Logic_onPlant(%brick);
|
||||||
{
|
}
|
||||||
if(%this.isLogicWire)
|
}
|
||||||
lualogic_addwire(%brick);
|
}
|
||||||
else if(%this.isLogicGate)
|
|
||||||
lualogic_addgate(%brick);
|
function fxDtsBrick::Logic_HandleRemove(%brick){
|
||||||
}
|
if(!%brick.Logic_HasRemoved){
|
||||||
}
|
%brick.Logic_HasRemoved = true;
|
||||||
|
|
||||||
function fxDTSBrickData::onLoadPlant(%this, %brick)
|
%data = %brick.getDatablock();
|
||||||
{
|
if(isFunction(%data.getName(), "Logic_onRemove")){
|
||||||
parent::onLoadPlant(%this, %brick);
|
%data.Logic_onRemove(%brick);
|
||||||
|
}
|
||||||
if(isObject(%brick) && %this.isLogic)
|
}
|
||||||
{
|
}
|
||||||
if(%this.isLogicWire)
|
|
||||||
lualogic_addwire(%brick);
|
package LuaLogic_Bricks
|
||||||
else if(%this.isLogicGate)
|
{
|
||||||
lualogic_addgate(%brick);
|
function fxDTSBrickData::onPlant(%data, %brick)
|
||||||
}
|
{
|
||||||
}
|
parent::onPlant(%data, %brick);
|
||||||
|
|
||||||
function fxDTSBrickData::onColorChange(%data, %obj)
|
if(isObject(%brick) && %data.isLogic)
|
||||||
{
|
{
|
||||||
parent::onColorChange(%data, %obj);
|
if(%data.isLogicWire)
|
||||||
|
lualogic_addwire(%brick);
|
||||||
if(isObject(%obj) && %obj.isPlanted() && !%obj.isDead() && %data.isLogic && %data.isLogicWire)
|
else if(%data.isLogicGate)
|
||||||
lualogic_send("SL;" @ %obj @ ";" @ %obj.getColorID());
|
lualogic_addgate(%brick);
|
||||||
}
|
|
||||||
|
%brick.Logic_HandlePlant();
|
||||||
function fxDTSBrickData::onDeath(%this, %brick)
|
}
|
||||||
{
|
}
|
||||||
if(%this.isLogic)
|
|
||||||
{
|
function fxDTSBrickData::onLoadPlant(%this, %brick)
|
||||||
if(%this.isLogicWire)
|
{
|
||||||
lualogic_removewire(%brick);
|
parent::onLoadPlant(%this, %brick);
|
||||||
else if(%this.isLogicGate)
|
|
||||||
lualogic_removegate(%brick);
|
if(isObject(%brick) && %this.isLogic)
|
||||||
}
|
{
|
||||||
|
if(%this.isLogicWire)
|
||||||
parent::onDeath(%this, %brick);
|
lualogic_addwire(%brick);
|
||||||
}
|
else if(%this.isLogicGate)
|
||||||
|
lualogic_addgate(%brick);
|
||||||
function fxDTSBrickData::onRemove(%this, %brick)
|
|
||||||
{
|
%brick.Logic_HandlePlant();
|
||||||
if(%this.isLogic && %brick.logicIsAdded)
|
}
|
||||||
{
|
}
|
||||||
if(%this.isLogicWire)
|
|
||||||
lualogic_removewire(%brick);
|
function fxDTSBrickData::onColorChange(%data, %obj)
|
||||||
else if(%this.isLogicGate)
|
{
|
||||||
lualogic_removegate(%brick);
|
parent::onColorChange(%data, %obj);
|
||||||
}
|
|
||||||
|
if(isObject(%obj) && %obj.isPlanted() && !%obj.isDead() && %data.isLogic && %data.isLogicWire)
|
||||||
parent::onRemove(%this, %brick);
|
lualogic_send("SL;" @ %obj @ ";" @ %obj.getColorID());
|
||||||
}
|
}
|
||||||
|
|
||||||
function Player::activateStuff(%this, %a, %b)
|
function fxDTSBrickData::onDeath(%this, %brick)
|
||||||
{
|
{
|
||||||
parent::activateStuff(%this, %a, %b);
|
if(%this.isLogic)
|
||||||
|
{
|
||||||
if(isObject(%client = %this.client))
|
if(%this.isLogicWire)
|
||||||
{
|
lualogic_removewire(%brick);
|
||||||
%eye = %this.getEyePoint();
|
else if(%this.isLogicGate)
|
||||||
%vec = %this.getEyeVector();
|
lualogic_removegate(%brick);
|
||||||
%ray = containerRayCast(%eye, vectorAdd(%eye, vectorScale(%vec, 5*getWord(%this.getScale(), 2))), $TypeMasks::FxBrickObjectType);
|
|
||||||
if(isObject(%hit = firstWord(%ray)))
|
%brick.Logic_HandleRemove();
|
||||||
{
|
}
|
||||||
%data = %hit.getDataBlock();
|
|
||||||
if(%data.isLogic)
|
parent::onDeath(%this, %brick);
|
||||||
{
|
}
|
||||||
if(%data.isLogicInput)
|
|
||||||
%data.Logic_onInput(%hit, %hitPos, %hitNorm, %client);
|
function fxDTSBrickData::onRemove(%this, %brick)
|
||||||
else
|
{
|
||||||
lualogic_send("GINFO;" @ %client @ ";" @ %hit);
|
if(%this.isLogic && %brick.logicIsAdded)
|
||||||
}
|
{
|
||||||
}
|
if(%this.isLogicWire)
|
||||||
}
|
lualogic_removewire(%brick);
|
||||||
}
|
else if(%this.isLogicGate)
|
||||||
};
|
lualogic_removegate(%brick);
|
||||||
activatePackage("LuaLogic_Bricks");
|
|
||||||
|
%brick.Logic_HandleRemove();
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::onRemove(%this, %brick);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Player::activateStuff(%this, %a, %b)
|
||||||
|
{
|
||||||
|
parent::activateStuff(%this, %a, %b);
|
||||||
|
|
||||||
|
if(isObject(%client = %this.client))
|
||||||
|
{
|
||||||
|
%eye = %this.getEyePoint();
|
||||||
|
%vec = %this.getEyeVector();
|
||||||
|
%ray = containerRayCast(%eye, vectorAdd(%eye, vectorScale(%vec, 5*getWord(%this.getScale(), 2))), $TypeMasks::FxBrickObjectType);
|
||||||
|
if(isObject(%hit = firstWord(%ray)))
|
||||||
|
{
|
||||||
|
%data = %hit.getDataBlock();
|
||||||
|
if(%data.isLogic)
|
||||||
|
{
|
||||||
|
if(%data.isLogicInput)
|
||||||
|
%data.Logic_onInput(%hit, %hitPos, %hitNorm, %client);
|
||||||
|
else
|
||||||
|
lualogic_send("GINFO;" @ %client @ ";" @ %hit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
activatePackage("LuaLogic_Bricks");
|
||||||
|
@ -117,7 +117,10 @@ package LuaLogic
|
|||||||
activatePackage("LuaLogic");
|
activatePackage("LuaLogic");
|
||||||
|
|
||||||
function llr(){
|
function llr(){
|
||||||
|
%path = $LuaLogic::Path;
|
||||||
deleteVariables("$LuaLogic*");
|
deleteVariables("$LuaLogic*");
|
||||||
|
$LuaLogic::Path = %path;
|
||||||
|
|
||||||
resetAllOpCallFunc();
|
resetAllOpCallFunc();
|
||||||
exec("./lualogic.cs");
|
exec("./lualogic.cs");
|
||||||
schedule(3000, 0, lualogic_connect, 25000);
|
schedule(3000, 0, lualogic_connect, 25000);
|
||||||
|
@ -11,7 +11,9 @@ function lualogic_escapelogicfunction(%text){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_registergatedefinition(%data){
|
function lualogic_registergatedefinition(%data){
|
||||||
lualogic_registergatedefinition_auto(%data);
|
//lualogic_registergatedefinition_auto(%data);
|
||||||
|
|
||||||
|
//handled automatically now
|
||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_registergatedefinition_auto(%data)
|
function lualogic_registergatedefinition_auto(%data)
|
||||||
@ -19,8 +21,8 @@ function lualogic_registergatedefinition_auto(%data)
|
|||||||
if(!isObject(%data))
|
if(!isObject(%data))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(%data.luaLogic_isRegistered)
|
//if(%data.luaLogic_isRegistered)
|
||||||
return;
|
//return;
|
||||||
|
|
||||||
%id = %data.getID();
|
%id = %data.getID();
|
||||||
|
|
||||||
@ -48,10 +50,12 @@ function lualogic_registergatedefinition_auto(%data)
|
|||||||
|
|
||||||
$LuaLogic::GateDefintion[%idx] = %def;
|
$LuaLogic::GateDefintion[%idx] = %def;
|
||||||
|
|
||||||
%data.luaLogic_isRegistered = true;
|
//%data.luaLogic_isRegistered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function lualogic_registerAllGateDefinitions(){
|
function lualogic_registerAllGateDefinitions(){
|
||||||
|
echo("LuaLogic: Registering gate definitions");
|
||||||
|
|
||||||
for(%dbidx=0; %dbidx<DatablockGroup.getCount(); %dbidx++){
|
for(%dbidx=0; %dbidx<DatablockGroup.getCount(); %dbidx++){
|
||||||
%db = DatablockGroup.getObject(%dbidx);
|
%db = DatablockGroup.getObject(%dbidx);
|
||||||
if(%db.isLogic && %db.isLogicGate){
|
if(%db.isLogic && %db.isLogicGate){
|
||||||
@ -60,7 +64,7 @@ function lualogic_registerAllGateDefinitions(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lualogic_registerAllGateDefinitions();
|
schedule(1, 0, lualogic_registerAllGateDefinitions);
|
||||||
|
|
||||||
function lualogic_print(%text)
|
function lualogic_print(%text)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user