1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00
* optimizations
* syntax fix
* models info moved to shared file
* moved positions to shared file
* fixed arrow bug, swaped L and R routenumbers
* fixed bug when lamp didnt respawn on spawner left click
* removed local vectors, angles, colors; tickrate set to 30
* fixed switches debug
This commit is contained in:
TheFUlDeep
2021-03-25 20:16:12 +03:00
committed by GitHub
parent 68f963efae
commit cbb6bc0267
4 changed files with 229 additions and 172 deletions

View File

@@ -59,16 +59,18 @@ function ENT:SpawnMainModels(pos,ang,LenseNum,add)
local TLM = self.TrafficLightModels[self.LightType] local TLM = self.TrafficLightModels[self.LightType]
for k,v in pairs(TLM) do for k,v in pairs(TLM) do
if type(v) == "string" and not k:find("long") then if type(v) == "string" and not k:find("long") then
if IsValid(self.Models[1][add and v..add or v]) then break else local idx = add and v..add or v
if TLM[k.."_long"] and LenseNum >= 7 then if IsValid(self.Models[1][idx]) then break else
self.Models[1][add and v..add or v] = ClientsideModel(TLM[k.."_long"],RENDERGROUP_OPAQUE) local k_long = k.."_long"
if TLM[k_long] and LenseNum >= 7 then
self.Models[1][idx] = ClientsideModel(TLM[k_long],RENDERGROUP_OPAQUE)
self.LongOffset = Vector(0,0,TLM[k.."_long_pos"]) self.LongOffset = Vector(0,0,TLM[k.."_long_pos"])
else else
self.Models[1][add and v..add or v] = ClientsideModel(v,RENDERGROUP_OPAQUE) self.Models[1][idx] = ClientsideModel(v,RENDERGROUP_OPAQUE)
end end
self.Models[1][add and v..add or v]:SetPos(self:LocalToWorld(pos)) self.Models[1][idx]:SetPos(self:LocalToWorld(pos))
self.Models[1][add and v..add or v]:SetAngles(self:LocalToWorldAngles(ang)) self.Models[1][idx]:SetAngles(self:LocalToWorldAngles(ang))
self.Models[1][add and v..add or v]:SetParent(self) self.Models[1][idx]:SetParent(self)
end end
end end
end end
@@ -85,23 +87,27 @@ function ENT:SpawnHeads(ID,model,pos,ang,glass,notM,add)
self.RN = self.RN + 1 self.RN = self.RN + 1
end end
local id = self.RN local id = self.RN
if id and not IsValid(self.Models[1]["rou"..id]) then local rouid = id and "rou"..id
if rouid and not IsValid(self.Models[1][rouid]) then
local rnadd = ((self.RouteNumbers[id] and self.RouteNumbers[id][1] ~= "X") and (self.RouteNumbers[id][3] and not self.RouteNumbers[id][2] and "2" or "") or "5") local rnadd = ((self.RouteNumbers[id] and self.RouteNumbers[id][1] ~= "X") and (self.RouteNumbers[id][3] and not self.RouteNumbers[id][2] and "2" or "") or "5")
self.Models[1]["rou"..id] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator"..rnadd..".mdl",RENDERGROUP_OPAQUE) local LampIndicator = self.TrafficLightModels[self.LightType].LampIndicator
self.Models[1]["rou"..id]:SetPos(self:LocalToWorld(pos-self.RouteNumberOffset*Vector(self.Left and 0.2 or 1))) self.Models[1][rouid] = ClientsideModel(LampIndicator.model..rnadd..".mdl",RENDERGROUP_OPAQUE)
self.Models[1]["rou"..id]:SetAngles(self:GetAngles()) self.Models[1][rouid]:SetPos(self:LocalToWorld(pos-self.RouteNumberOffset*(self.Left and LampIndicator[1] or LampIndicator[2])))
self.Models[1]["rou"..id]:SetParent(self) self.Models[1][rouid]:SetAngles(self:GetAngles())
if self.RouteNumbers[id] then self.RouteNumbers[id].pos = pos-self.RouteNumberOffset*Vector(self.Left and 0.2 or 1) end self.Models[1][rouid]:SetParent(self)
if self.RouteNumbers[id] then self.RouteNumbers[id].pos = pos-self.RouteNumberOffset*(self.Left and LampIndicator[1] or LampIndicator[2]) end
self.RN = self.RN + 1 self.RN = self.RN + 1
end end
if notM then if notM then
if glass then if glass then
local ID_glass = tostring(ID).."_glass"
for i,tbl in pairs(glass) do for i,tbl in pairs(glass) do
if not IsValid(self.Models[1][tostring(ID).."_glass"..i]) then --NEWLENSES local ID_glassi = ID_glass..i
self.Models[1][tostring(ID).."_glass"..i] = ClientsideModel(tbl[1],RENDERGROUP_OPAQUE) if not IsValid(self.Models[1][ID_glassi]) then --NEWLENSES
self.Models[1][tostring(ID).."_glass"..i]:SetPos(self:LocalToWorld(pos+tbl[2]*Vector(add and -1 or 1,1,1))) self.Models[1][ID_glassi] = ClientsideModel(tbl[1],RENDERGROUP_OPAQUE)
self.Models[1][tostring(ID).."_glass"..i]:SetAngles(self:LocalToWorldAngles(ang)) self.Models[1][ID_glassi]:SetPos(self:LocalToWorld(pos+tbl[2]*(add and Vector(-1,1,1) or 1)))
self.Models[1][tostring(ID).."_glass"..i]:SetParent(self) self.Models[1][ID_glassi]:SetAngles(self:LocalToWorldAngles(ang))
self.Models[1][ID_glassi]:SetParent(self)
end end
end end
end end
@@ -109,44 +115,53 @@ function ENT:SpawnHeads(ID,model,pos,ang,glass,notM,add)
end end
function ENT:SetLight(ID,ID2,pos,ang,skin,State,Change) function ENT:SetLight(ID,ID2,pos,ang,skin,State,Change)
if State >0 and Change and not IsValid(self.Models[3][ID..ID2]) then local IsStateAboveZero = State > 0
self.Models[3][ID..ID2] = ClientsideModel("models/metrostroi/signals/mus/lamp_base.mdl",RENDERGROUP_OPAQUE) local IDID2 = ID..ID2
self.Models[3][ID..ID2]:SetPos(self:LocalToWorld(pos)) local IsModelValid = IsValid(self.Models[3][IDID2])
self.Models[3][ID..ID2]:SetAngles(self:LocalToWorldAngles(ang)) if IsModelValid then
self.Models[3][ID..ID2]:SetSkin(skin) if IsStateAboveZero then
self.Models[3][ID..ID2]:SetParent(self) if Change then
self.Models[3][ID..ID2]:SetRenderMode(RENDERMODE_TRANSCOLOR) self.Models[3][IDID2]:SetColor(Color(255,255,255,State*255))
self.Models[3][ID..ID2]:SetColor(Color(255,255,255,0)) end
end else
if IsValid(self.Models[3][ID..ID2]) then self.Models[3][IDID2]:Remove()
if State > 0 and Change then
self.Models[3][ID..ID2]:SetColor(Color(255,255,255,State*255))
elseif State == 0 then
self.Models[3][ID..ID2]:Remove()
end end
elseif IsStateAboveZero then
self.Models[3][IDID2] = ClientsideModel(self.TrafficLightModels[self.LightType].LampBase.model,RENDERGROUP_OPAQUE)
self.Models[3][IDID2]:SetPos(self:LocalToWorld(pos))
self.Models[3][IDID2]:SetAngles(self:LocalToWorldAngles(ang))
self.Models[3][IDID2]:SetSkin(skin)
self.Models[3][IDID2]:SetParent(self)
self.Models[3][IDID2]:SetRenderMode(RENDERMODE_TRANSCOLOR)
-- self.Models[3][IDID2]:SetColor(Color(255, 255, 255, 0))
self.Models[3][IDID2]:SetColor(Color(255,255,255,State*255))
end end
end end
function ENT:SpawnLetter(i,model,pos,letter,double) function ENT:SpawnLetter(i,model,pos,letter,double)
local LetMaterials = self.TrafficLightModels[self.LightType].LetMaterials.str
local LetMaterialsStart = LetMaterials.."let_start"
local LetMaterialsletter = LetMaterials..letter
if double ~= false and not IsValid(self.Models[2][i]) and (self.Double or not self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and self.Left) then if double ~= false and not IsValid(self.Models[2][i]) and (self.Double or not self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and self.Left) then
self.Models[2][i] = ClientsideModel(model,RENDERGROUP_OPAQUE) self.Models[2][i] = ClientsideModel(model,RENDERGROUP_OPAQUE)
self.Models[2][i]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0))) self.Models[2][i]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0)))
self.Models[2][i]:SetPos(self:LocalToWorld(self.BasePosition+pos)) self.Models[2][i]:SetPos(self:LocalToWorld(self.BasePosition+pos))
self.Models[2][i]:SetParent(self) self.Models[2][i]:SetParent(self)
for k,v in pairs(self.Models[2][i]:GetMaterials()) do for k,v in pairs(self.Models[2][i]:GetMaterials()) do
if v:find("models/metrostroi/signals/let/let_start") then if v:find(LetMaterialsStart) then
self.Models[2][i]:SetSubMaterial(k-1,"models/metrostroi/signals/let/"..letter) self.Models[2][i]:SetSubMaterial(k-1,LetMaterialsletter)
end end
end end
end end
if not double and not IsValid(self.Models[2][i.."d"]) and (self.Double or self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and not self.Left) then local id = i.."d"
self.Models[2][i.."d"] = ClientsideModel(model,RENDERGROUP_OPAQUE) if not double and not IsValid(self.Models[2][id]) and (self.Double or self.Left) and (not letter:match("s[1-3]") or letter == "s3" or self.Double and not self.Left) then
self.Models[2][i.."d"]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0))) self.Models[2][id] = ClientsideModel(model,RENDERGROUP_OPAQUE)
self.Models[2][i.."d"]:SetPos(self:LocalToWorld((self.BasePosition+pos)*Vector(-1,1,1))) self.Models[2][id]:SetAngles(self:LocalToWorldAngles(Angle(0,180,0)))
self.Models[2][i.."d"]:SetParent(self) self.Models[2][id]:SetPos(self:LocalToWorld((self.BasePosition+pos)*Vector(-1,1,1)))
for k,v in pairs(self.Models[2][i.."d"]:GetMaterials()) do self.Models[2][id]:SetParent(self)
if v:find("models/metrostroi/signals/let/let_start") then for k,v in pairs(self.Models[2][id]:GetMaterials()) do
self.Models[2][i.."d"]:SetSubMaterial(k-1,"models/metrostroi/signals/let/"..letter) if v:find(LetMaterialsStart) then
self.Models[2][id]:SetSubMaterial(k-1,LetMaterialsletter)
end end
end end
end end
@@ -184,6 +199,8 @@ net.Receive("metrostroi-signal", function()
end) end)
function ENT:Think() function ENT:Think()
local CurTime = CurTime()
self:SetNextClientThink(CurTime + 0.0333)
self.PrevTime = self.PrevTime or RealTime() self.PrevTime = self.PrevTime or RealTime()
self.DeltaTime = (RealTime() - self.PrevTime) self.DeltaTime = (RealTime() - self.PrevTime)
self.PrevTime = RealTime() self.PrevTime = RealTime()
@@ -191,7 +208,7 @@ function ENT:Think()
if not self.ReloadModels and self.ModelsCreated then if not self.ReloadModels and self.ModelsCreated then
self:RemoveModels() self:RemoveModels()
end end
return return true
end end
if self.ReloadModels then if self.ReloadModels then
@@ -200,16 +217,16 @@ function ENT:Think()
end end
if not self.Name then if not self.Name then
if self.sended and (CurTime() - self.sended) > 0 then if self.sended and (CurTime - self.sended) > 0 then
self.sended = nil self.sended = nil
end end
if not self.sended then if not self.sended then
net.Start("metrostroi-signal") net.Start("metrostroi-signal")
net.WriteEntity(self) net.WriteEntity(self)
net.SendToServer() net.SendToServer()
self.sended = CurTime() + 1.5 self.sended = CurTime + 1.5
end end
return return true
end end
local TLM = self.TrafficLightModels[self.LightType] local TLM = self.TrafficLightModels[self.LightType]
@@ -219,34 +236,37 @@ function ENT:Think()
-- Create new clientside models -- Create new clientside models
if not self.ARSOnly then if not self.ARSOnly then
--SPAWN A OLD ROUTE Numbers --SPAWN A OLD ROUTE Numbers
--оператор # съедает больше производительности, чем исопльзование своей переменной с хранением количества элементов в таблице
--поэтому добавляю каунтеры
--TODO вообще сравнить бы это здесь xD
local rn1 = {} local rn1 = {}
local rn1N = 0
local rn2 = {} local rn2 = {}
self.RouteNumbers = {} self.RouteNumbers = {}
self.SpecRouteNumbers = {} self.SpecRouteNumbers = {}
for i=1,#self.RouteNumberSetup do for i=1,#self.RouteNumberSetup do
local CurRN = self.RouteNumberSetup[i] local CurRN = self.RouteNumberSetup[i]
if self.OldRouteNumberSetup[1]:find(CurRN) then if self.OldRouteNumberSetup[1]:find(CurRN) then
table.insert(rn1,CurRN) rn1N = table.insert(rn1,CurRN)
elseif self.OldRouteNumberSetup[2]:find(CurRN) then elseif self.OldRouteNumberSetup[2]:find(CurRN) then
table.insert(rn2,CurRN) table.insert(rn2,CurRN)
elseif self.OldRouteNumberSetup[3]:find(CurRN) then elseif self.OldRouteNumberSetup[3]:find(CurRN) then
table.insert(self.SpecRouteNumbers,{CurRN,CurRN == "F"}) table.insert(self.SpecRouteNumbers,{CurRN,CurRN == "F"})
end end
end end
for i=1,#rn1,2 do for i=1,rn1N,2 do
table.insert(self.RouteNumbers,{rn1[i],rn1[i+1],true}) table.insert(self.RouteNumbers,{rn1[i],rn1[i+1],true})
end end
for k,v in pairs(rn2) do for k,v in pairs(rn2) do
table.insert(self.RouteNumbers,{v}) table.insert(self.RouteNumbers,{v})
end end
self.Arrow = nil self.Arrow = nil
if #self.SpecRouteNumbers > 0 then
for k,v in pairs(self.SpecRouteNumbers) do for k,v in pairs(self.SpecRouteNumbers) do
if not v[2] then if not v[2] then
self.Arrow = k self.Arrow = k
self.SpecRouteNumbers = v self.SpecRouteNumbers = v
break break
end
end end
end end
local LenseNum = self.Arrow and 1 or 0 local LenseNum = self.Arrow and 1 or 0
@@ -262,9 +282,9 @@ function ENT:Think()
end end
end end
if LenseNum == 0 then OneLense = false end if LenseNum == 0 then OneLense = false end
local offset = self.RenderOffset[self.LightType] or Vector(0,0,0) local offset = self.RenderOffset[self.LightType] or Vector(0, 0, 0)
self.LongOffset = self.LongOffset or Vector(0,0,0) self.LongOffset = self.LongOffset or Vector(0, 0, 0)
if not self.Left or self.Double then self:SpawnMainModels(self.BasePosition,Angle(0,0,0),LenseNum) end if not self.Left or self.Double then self:SpawnMainModels(self.BasePosition,Angle(0, 0, 0),LenseNum) end
if self.Left or self.Double then self:SpawnMainModels(self.BasePosition*Vector(-1,1,1),Angle(0,180,0),LenseNum,self.Double and "d" or nil) end if self.Left or self.Double then self:SpawnMainModels(self.BasePosition*Vector(-1,1,1),Angle(0,180,0),LenseNum,self.Double and "d" or nil) end
@@ -276,17 +296,17 @@ function ENT:Think()
if self.RouteNumbers.sep and self.RouteNumbers[self.RouteNumbers.sep][1] ~= "X" then if self.RouteNumbers.sep and self.RouteNumbers[self.RouteNumbers.sep][1] ~= "X" then
local id = self.RouteNumbers.sep local id = self.RouteNumbers.sep
local rnadd = self.RouteNumbers[id][3] and not self.RouteNumbers[id][2] and "3" or "4" local rnadd = self.RouteNumbers[id][3] and not self.RouteNumbers[id][2] and "3" or "4"
self.Models[1]["rous"] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator"..rnadd..".mdl",RENDERGROUP_OPAQUE) self.Models[1]["rous"] = ClientsideModel(TLM.LampIndicator.model..rnadd..".mdl",RENDERGROUP_OPAQUE)
self.RouteNumbers[id].pos = (self.BasePosition+offset+self.LongOffset-Vector(8,0,0)) self.RouteNumbers[id].pos = (self.BasePosition+offset+self.LongOffset-TLM.LampIndicator[3])
if self.Left then self.RouteNumbers[id].pos = self.RouteNumbers[id].pos*Vector(-0.9,1,1) end if self.Left then self.RouteNumbers[id].pos = self.RouteNumbers[id].pos*TLM.LampIndicator[4] end
self.Models[1]["rous"]:SetPos(self:LocalToWorld(self.RouteNumbers[id].pos)) self.Models[1]["rous"]:SetPos(self:LocalToWorld(self.RouteNumbers[id].pos))
self.Models[1]["rous"]:SetAngles(self:GetAngles()) self.Models[1]["rous"]:SetAngles(self:GetAngles())
self.Models[1]["rous"]:SetParent(self) self.Models[1]["rous"]:SetParent(self)
end end
if #self.RouteNumbers > 0 and (#self.RouteNumbers ~= 1 or not self.RouteNumbers.sep) then if #self.RouteNumbers > 0 and (#self.RouteNumbers ~= 1 or not self.RouteNumbers.sep) then
self.RN = 1 self.RN = 1
self.RouteNumberOffset = Vector(10,0,0) self.RouteNumberOffset = TLM.RouteNumberOffset
offset = offset + self.RouteNumberOffset*Vector(self.Left and -1 or 1,1,1) offset = offset + self.RouteNumberOffset*(self.Left and Vector(-1,1,1) or 1)
else else
self.RouteNumberOffset = nil self.RouteNumberOffset = nil
self.RN = nil self.RN = nil
@@ -299,7 +319,7 @@ function ENT:Think()
self.Models[1]["autostop"]:SetParent(self) self.Models[1]["autostop"]:SetParent(self)
end end
end end
self.NamesOffset = Vector(0,0,0) self.NamesOffset = Vector(0, 0, 0)
-- Create traffic light models -- Create traffic light models
--if self.LightType > 2 then self.LightType = 2 end --if self.LightType > 2 then self.LightType = 2 end
--if self.LightType < 0 then self.LightType = 0 end --if self.LightType < 0 then self.LightType = 0 end
@@ -315,24 +335,26 @@ function ENT:Think()
data = self.TrafficLightModels[self.LightType][v] data = self.TrafficLightModels[self.LightType][v]
end end
if not data then continue end if not data then continue end
local vec = Vector(0,0,data[1])
if first then if first then
first = false first = false
else else
offset = offset - Vector(0,0,data[1]) offset = offset - vec
end end
self.NamesOffset = self.NamesOffset + Vector(0,0,data[1]) self.NamesOffset = self.NamesOffset + vec
if not self.Left or self.Double then self:SpawnHeads(ID,data[2],self.BasePosition + offset + self.LongOffset,Angle(0,0,0),data[3] and data[3].glass,v~="M") end local offsetAndLongOffset = offset + self.LongOffset
if self.Left or self.Double then self:SpawnHeads((self.Double and ID.."d" or ID),(not TLM.noleft) and data[2]:Replace(".mdl","_mirror.mdl") or data[2],self.BasePosition*Vector(-1,1,1) + offset + self.LongOffset,Angle(0,0,0),data[3] and data[3].glass,v~="M",true) end if not self.Left or self.Double then self:SpawnHeads(ID,data[2],self.BasePosition + offsetAndLongOffset,Angle(0, 0, 0),data[3] and data[3].glass,v~="M") end
if self.Left or self.Double then self:SpawnHeads((self.Double and ID.."d" or ID),(not TLM.noleft) and data[2]:Replace(".mdl","_mirror.mdl") or data[2],self.BasePosition*Vector(-1,1,1) + offsetAndLongOffset,Angle(0, 0, 0),data[3] and data[3].glass,v~="M",true) end
if v ~= "M" then if v ~= "M" then
for i = 1,#v do for i = 1,#v do
ID2 = ID2 + 1 ID2 = ID2 + 1
if not self.Signals[ID2] then self.Signals[ID2] = {} end if not self.Signals[ID2] then self.Signals[ID2] = {} end
if not self.DoubleL then if not self.DoubleL then
self:SetLight(ID,ID2,self.BasePosition*Vector(self.Left and -1 or 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(self.Left and -1 or 1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,0 ) self:SetLight(ID,ID2,self.BasePosition*(self.Left and Vector(-1,1,1) or 1) + offsetAndLongOffset + data[3][i-1]*(self.Left and Vector(-1,1,1) or 1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,0 )
else else
self:SetLight(ID,ID2,self.BasePosition*Vector( 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,0) self:SetLight(ID,ID2,self.BasePosition + offsetAndLongOffset + data[3][i-1],Angle(0, 0, 0),self.SignalConverter[v[i]]-1,0)
self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,0) self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offsetAndLongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,0)
end end
end end
end end
@@ -341,41 +363,41 @@ function ENT:Think()
end end
if self.Arrow then if self.Arrow then
local id = self.Arrow local id = self.Arrow
self.Models[1]["roua"] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator4.mdl",RENDERGROUP_OPAQUE) self.Models[1]["roua"] = ClientsideModel(TLM.LampIndicator.model.."4.mdl",RENDERGROUP_OPAQUE)
self.SpecRouteNumbers.pos = (self.BasePosition+offset+self.LongOffset-Vector(3,0,3))*Vector(self.Left and -1 or 1,1,self.Left and 0.85 or 1)-(self.RouteNumberOffset or Vector()) self.SpecRouteNumbers.pos = (self.BasePosition+offset+self.LongOffset-TLM.LampIndicator[5])*(self.Left and TLM.LampIndicator[6] or 1) - (self.RouteNumberOffset or Vector(0, 0, 0))
self.Models[1]["roua"]:SetPos(self:LocalToWorld(self.SpecRouteNumbers.pos)) self.Models[1]["roua"]:SetPos(self:LocalToWorld(self.SpecRouteNumbers.pos))
self.Models[1]["roua"]:SetAngles(self:LocalToWorldAngles(Angle(self.Left and -90 or 90,0,0))) self.Models[1]["roua"]:SetAngles(self:LocalToWorldAngles(self.Left and Angle(-90,0,0) or Angle(90,0,0)))
self.Models[1]["roua"]:SetParent(self) self.Models[1]["roua"]:SetParent(self)
end end
offset = self.RenderOffset[self.LightType]+(OneLense and TLM.name_one or TLM.name)+(OneLense and self.RouteNumberOffset or Vector()) offset = self.RenderOffset[self.LightType]+(OneLense and TLM.name_one or TLM.name)+(OneLense and self.RouteNumberOffset or Vector(0, 0, 0))
if self.LightType == 1 then if self.LightType == 1 then
offset = offset - self.NamesOffset offset = offset - self.NamesOffset
end end
local double = self.LightType ~= 1 and string.find(self.Name,"^[A-Z][A-Z]") local double = self.LightType ~= 1 and string.find(self.Name,"^[A-Z][A-Z]")
if double then if double then
if not self.Left or self.Double then if not self.Left or self.Double then
self:SpawnLetter(0,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(-1.5,0,0),(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),true) self:SpawnLetter(0,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[2],(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),true)
self:SpawnLetter(1,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(1.5,0,0),(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),true) self:SpawnLetter(1,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[1],(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),true)
end end
if self.Left or self.Double then if self.Left or self.Double then
self:SpawnLetter(0,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(1.5,0,0),(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),false) self:SpawnLetter(0,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[1],(Metrostroi.LiterWarper[self.Name[0+1]] or self.Name[0+1]),false)
self:SpawnLetter(1,"models/metrostroi/signals/mus/sign_letter_small.mdl",offset - Vector(-1.5,0,0),(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),false) self:SpawnLetter(1,TLM.SignLetterSmall.model,offset - TLM.SignLetterSmall[2],(Metrostroi.LiterWarper[self.Name[1+1]] or self.Name[1+1]),false)
end end
end end
local min = 0 local min = 0
for i = double and 2 or 0,#self.Name-1 do for i = double and 2 or 0,#self.Name-1 do
local id = (double and i-1 or i) - min local id = (double and i-1 or i) - min
if double and i == 2 then offset = offset + Vector(0,0,1.62) end if double and i == 2 then offset = offset + TLM.DoubleOffset end
if self.Name[i+1] == " " then continue end if self.Name[i+1] == " " then continue end
if self.Name[i+1] == "/" then min = min + 1; continue end if self.Name[i+1] == "/" then min = min + 1; continue end
--if not IsValid(self.Models[2][i]) then --if not IsValid(self.Models[2][i]) then
self:SpawnLetter(i,"models/metrostroi/signals/mus/sign_letter.mdl",offset - Vector(0,0,id*5.85),(Metrostroi.LiterWarper[self.Name[i+1]] or self.Name[i+1])) self:SpawnLetter(i,TLM.SignLetter.model,offset - Vector(0,0,id*TLM.SignLetter.z),(Metrostroi.LiterWarper[self.Name[i+1]] or self.Name[i+1]))
--end --end
end end
if self.Name and self.Name:match("(/+)$") then if self.Name and self.Name:match("(/+)$") then
local i = #self.Name local i = #self.Name
local id = (double and i-1 or i) - min local id = (double and i-1 or i) - min
self:SpawnLetter(i,"models/metrostroi/signals/mus/sign_letter.mdl",offset - Vector(0,0,id*5.85),Format("s%d",math.min(3,#self.Name:match("(/+)$")))) self:SpawnLetter(i,TLM.SignLetter.model,offset - Vector(0,0,id*TLM.SignLetter.z),Format("s%d",math.min(3,#self.Name:match("(/+)$"))))
end end
else else
local k = "m1" local k = "m1"
@@ -383,8 +405,8 @@ function ENT:Think()
if not IsValid(self.Models[1][k]) then if not IsValid(self.Models[1][k]) then
local v = TLM["m1"] local v = TLM["m1"]
self.Models[1][k] = ClientsideModel(v,RENDERGROUP_OPAQUE) self.Models[1][k] = ClientsideModel(v,RENDERGROUP_OPAQUE)
self.Models[1][k]:SetPos(self:LocalToWorld(self.BasePosition*Vector(self.Left and -1 or 1,1,1))) self.Models[1][k]:SetPos(self:LocalToWorld(self.BasePosition*(self.Left and Vector(-1,1,1) or 1)))
self.Models[1][k]:SetAngles(self:LocalToWorldAngles(Angle(self.Left and -1 or 1,1,1))) self.Models[1][k]:SetAngles(self:LocalToWorldAngles(self.Left and Angle(-1,1,1) or Angle(1,1,1)))
self.Models[1][k]:SetParent(self) self.Models[1][k]:SetParent(self)
end end
end end
@@ -402,16 +424,16 @@ function ENT:Think()
self.Sig = self:GetNW2String("Signal","") self.Sig = self:GetNW2String("Signal","")
self.Num = self:GetNW2String("Number",nil) self.Num = self:GetNW2String("Number",nil)
if self.OldNum ~= self.Num then if self.OldNum ~= self.Num then
self.NextNumWork = CurTime() + 1 self.NextNumWork = CurTime + 1
end end
self.OldNum = self.Num self.OldNum = self.Num
if (self.NextNumWork or CurTime()) - CurTime() >= 0 then if (self.NextNumWork or CurTime) - CurTime >= 0 then
self.Num = "" self.Num = ""
end end
if self.ARSOnly then return end if self.ARSOnly then return true end
local offset = (self.RenderOffset[self.LightType] or Vector(0,0,0)) local offset = (self.RenderOffset[self.LightType] or Vector(0, 0, 0))
if self.RouteNumberOffset then offset = offset + self.RouteNumberOffset*Vector(self.Left and -1 or 1,1) end if self.RouteNumberOffset then offset = offset + self.RouteNumberOffset*(self.Left and Vector(-1,1) or Vector(1,1)) end
local ID = 0 local ID = 0
local ID2 = 0 local ID2 = 0
local first = true local first = true
@@ -433,20 +455,22 @@ function ENT:Think()
if v ~= "M" then if v ~= "M" then
for i = 1,#v do for i = 1,#v do
ID2 = ID2 + 1 ID2 = ID2 + 1
if tonumber(self.Sig[ID2]) and self.Signals[ID2].RealState ~= (tonumber(self.Sig[ID2]) > 0) then local n = tonumber(self.Sig[ID2])
self.Signals[ID2].RealState = tonumber(self.Sig[ID2]) > 0 if n and self.Signals[ID2].RealState ~= (n > 0) then
self.Signals[ID2].Stop = CurTime() + 0.5 self.Signals[ID2].RealState = n > 0
self.Signals[ID2].Stop = CurTime + 0.5
end end
if self.Signals[ID2].Stop and CurTime()-self.Signals[ID2].Stop > 0 then if self.Signals[ID2].Stop and CurTime-self.Signals[ID2].Stop > 0 then
self.Signals[ID2].Stop = nil self.Signals[ID2].Stop = nil
end end
local State = self:Animate(ID.."/"..i, ((tonumber(self.Sig[ID2]) == 1 or (tonumber(self.Sig[ID2]) == 2 and (RealTime() % 1.2 > 0.4))) and not self.Signals[ID2].Stop) and 1 or 0, 0,1, 128) local State = self:Animate(ID.."/"..i, ((n == 1 or (n == 2 and (RealTime() % 1.2 > 0.4))) and not self.Signals[ID2].Stop) and 1 or 0, 0,1, 128)
if not IsValid(self.Models[3][ID..ID2]) and State > 0 then self.Signals[ID2].State = nil end if not IsValid(self.Models[3][ID..ID2]) and State > 0 then self.Signals[ID2].State = nil end
local offsetAndLongOffset = offset + self.LongOffset
if not self.DoubleL then if not self.DoubleL then
self:SetLight(ID,ID2,self.BasePosition*Vector(self.Left and -1 or 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(self.Left and -1 or 1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) self:SetLight(ID,ID2,self.BasePosition*(self.Left and Vector(-1,1,1) or 1) + offsetAndLongOffset + data[3][i-1]*(self.Left and Vector(-1,1,1) or 1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State)
else else
self:SetLight(ID,ID2,self.BasePosition*Vector( 1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) self:SetLight(ID,ID2,self.BasePosition + offsetAndLongOffset + data[3][i-1],Angle(0, 0, 0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State)
self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offset + self.LongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0,0,0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State) self:SetLight(ID,ID2.."x",self.BasePosition*Vector(-1,1,1) + offsetAndLongOffset + data[3][i-1]*Vector(-1,1,1),Angle(0, 0, 0),self.SignalConverter[v[i]]-1,State,self.Signals[ID2].State ~= State)
end end
self.Signals[ID2].State = State self.Signals[ID2].State = State
end end
@@ -456,52 +480,57 @@ function ENT:Think()
ID = ID + 1 ID = ID + 1
end end
local LampIndicatorModels_numb_mdl = TLM.LampIndicator.model.."_numb.mdl"
local LampIndicatorModels_lamp_mdl = TLM.LampIndicator.model.."_lamp.mdl"
for k,v in pairs(self.RouteNumbers) do for k,v in pairs(self.RouteNumbers) do
if k == "sep" then continue end if k == "sep" then continue end
local State1 = self:Animate("rou1"..k,self.Num:find(v[1]) and 1 or 0, 0,1, 256) local rou1k = "rou1"..k
local State1 = self:Animate(rou1k,self.Num:find(v[1]) and 1 or 0, 0,1, 256)
local State2 local State2
--if v[3] then --if v[3] then
if v[2] then State2 = self:Animate("rou2"..k,self.Num:find(v[2])and 1 or 0, 0,1, 256) end local rou2k = "rou2"..k
if not IsValid(self.Models[3]["rou1"..k]) and State1 > 0 then if v[2] then State2 = self:Animate(rou2k,self.Num:find(v[2])and 1 or 0, 0,1, 256) end
self.Models[3]["rou1"..k] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator_"..(v[3] and "numb" or "lamp")..".mdl",RENDERGROUP_OPAQUE) if not IsValid(self.Models[3][rou1k]) and State1 > 0 then
self.Models[3]["rou1"..k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4])) self.Models[3][rou1k] = ClientsideModel(v[3] and LampIndicatorModels_numb_mdl or LampIndicatorModels_lamp_mdl,RENDERGROUP_OPAQUE)
self.Models[3]["rou1"..k]:SetAngles(self:GetAngles()) self.Models[3][rou1k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4]))
self.Models[3]["rou1"..k]:SetParent(self) self.Models[3][rou1k]:SetAngles(self:GetAngles())
self.Models[3]["rou1"..k]:SetSkin(v[3] and self.OldRouteNumberSetup[5][v[1]] or self.OldRouteNumberSetup[6][v[1]] or tonumber(v[1])-1) self.Models[3][rou1k]:SetParent(self)
self.Models[3]["rou1"..k]:SetRenderMode(RENDERMODE_TRANSCOLOR) self.Models[3][rou1k]:SetSkin(v[3] and self.OldRouteNumberSetup[5][v[1]] or self.OldRouteNumberSetup[6][v[1]] or tonumber(v[1])-1)
self.Models[3]["rou1"..k]:SetColor(Color(255,255,255,0)) self.Models[3][rou1k]:SetRenderMode(RENDERMODE_TRANSCOLOR)
self.Models[3][rou1k]:SetColor(Color(255, 255, 255, 0))
end end
if IsValid(self.Models[3]["rou1"..k]) then if IsValid(self.Models[3][rou1k]) then
if State1 > 0 then if State1 > 0 then
self.Models[3]["rou1"..k]:SetColor(Color(255,255,255,State1*255)) self.Models[3][rou1k]:SetColor(Color(255,255,255,State1*255))
elseif State1 == 0 then elseif State1 == 0 then
self.Models[3]["rou1"..k]:Remove() self.Models[3][rou1k]:Remove()
end end
end end
if not IsValid(self.Models[3]["rou2"..k]) and v[3] and v[2] and State2 > 0 then if not IsValid(self.Models[3][rou2k]) and v[3] and v[2] and State2 > 0 then
self.Models[3]["rou2"..k] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator_numb.mdl",RENDERGROUP_OPAQUE) self.Models[3][rou2k] = ClientsideModel(LampIndicatorModels_numb_mdl,RENDERGROUP_OPAQUE)
self.Models[3]["rou2"..k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4] + Vector(0,0,7.2))) self.Models[3][rou2k]:SetPos(self:LocalToWorld(v.pos + self.OldRouteNumberSetup[4] + TLM.RouteNumberOffset2))
self.Models[3]["rou2"..k]:SetAngles(self:GetAngles()) self.Models[3][rou2k]:SetAngles(self:GetAngles())
self.Models[3]["rou2"..k]:SetParent(self) self.Models[3][rou2k]:SetParent(self)
self.Models[3]["rou2"..k]:SetSkin(self.OldRouteNumberSetup[5][v[2]] or tonumber(v[2])-1) self.Models[3][rou2k]:SetSkin(self.OldRouteNumberSetup[5][v[2]] or tonumber(v[2])-1)
self.Models[3]["rou2"..k]:SetRenderMode(RENDERMODE_TRANSCOLOR) self.Models[3][rou2k]:SetRenderMode(RENDERMODE_TRANSCOLOR)
self.Models[3]["rou2"..k]:SetColor(Color(255,255,255,0)) self.Models[3][rou2k]:SetColor(Color(255, 255, 255, 0))
end end
if IsValid(self.Models[3]["rou2"..k]) then if IsValid(self.Models[3][rou2k]) then
if State2 > 0 then if State2 > 0 then
self.Models[3]["rou2"..k]:SetColor(Color(255,255,255,State2*255)) self.Models[3][rou2k]:SetColor(Color(255,255,255,State2*255))
elseif State2 == 0 then elseif State2 == 0 then
self.Models[3]["rou2"..k]:Remove() self.Models[3][rou2k]:Remove()
end end
end end
end end
if self.Arrow then if self.Arrow then
local State = self:Animate("roua",self.Num:find(self.SpecRouteNumbers[1]) and 1 or 0, 0,1, 256) local State = self:Animate("roua",self.Num:find(self.SpecRouteNumbers[1]) and 1 or 0, 0,1, 256)
if not IsValid(self.Models[3]["roua"]) and State > 0 then if not IsValid(self.Models[3]["roua"]) and State > 0 then
self.Models[3]["roua"] = ClientsideModel("models/metrostroi/signals/mus/light_lampindicator_lamp.mdl",RENDERGROUP_OPAQUE) self.Models[3]["roua"] = ClientsideModel(LampIndicatorModels_lamp_mdl,RENDERGROUP_OPAQUE)
self.SpecRouteNumbers.pos = (self.BasePosition+offset-Vector(3,-1,3))-self.RouteNumberOffset+ Vector(10.5,0,-6) self.SpecRouteNumbers.pos = (self.BasePosition+offset-TLM.SpecRouteNumberOffset)-(self.RouteNumberOffset or Vector(0, 0, 0))+TLM.RouteNumberOffset3
if self.Left then self.SpecRouteNumbers.pos = self.SpecRouteNumbers.pos*Vector(-0.8,1,0.94) end if self.Left then self.SpecRouteNumbers.pos = self.SpecRouteNumbers.pos*TLM.SpecRouteNumberOffset2 end
self.Models[3]["roua"]:SetPos(self.Models[1]["roua"]:LocalToWorld(Vector(6.2,0,24.5))) self.Models[3]["roua"]:SetPos(self.Models[1]["roua"]:LocalToWorld(TLM.RouaOffset))
self.Models[3]["roua"]:SetAngles(self.Models[1]["roua"]:LocalToWorldAngles(Angle(180,0,0))) self.Models[3]["roua"]:SetAngles(self.Models[1]["roua"]:LocalToWorldAngles(Angle(180,0,0)))
self.Models[3]["roua"]:SetParent(self) self.Models[3]["roua"]:SetParent(self)
if self.Left then if self.Left then
@@ -514,7 +543,7 @@ function ENT:Think()
self.Models[3]["roua"]:SetSkin(self.OldRouteNumberSetup[6][self.Num[1]] or 0) self.Models[3]["roua"]:SetSkin(self.OldRouteNumberSetup[6][self.Num[1]] or 0)
end end
self.Models[3]["roua"]:SetRenderMode(RENDERMODE_TRANSCOLOR) self.Models[3]["roua"]:SetRenderMode(RENDERMODE_TRANSCOLOR)
self.Models[3]["roua"]:SetColor(Color(255,255,255,0)) self.Models[3]["roua"]:SetColor(Color(255, 255, 255, 0))
end end
if IsValid(self.Models[3]["roua"]) then if IsValid(self.Models[3]["roua"]) then
if State > 0 then if State > 0 then
@@ -526,6 +555,8 @@ function ENT:Think()
end end
--self.SpecRouteNumbers --self.SpecRouteNumbers
end end
return true
end end
function ENT:Draw() function ENT:Draw()
@@ -545,11 +576,20 @@ local ars = {
{"125 Hz", "70 KM/H"}, {"125 Hz", "70 KM/H"},
{"75 Hz", "80 KM/H"}, {"75 Hz", "80 KM/H"},
} }
local cols = {
R = Color(200,0,0),
Y = Color(200,200,0),
G = Color(0,200,0),
W = Color(200,200,200),
B = Color(0,0,200),
}
local function enableDebug() local function enableDebug()
if debug:GetBool() then if debug:GetBool() then
hook.Add("PostDrawTranslucentRenderables","MetrostroiSignalDebug",function(bDrawingDepth,bDrawingSkybox) hook.Add("PreDrawEffects","MetrostroiSignalDebug",function()
for _,ent in pairs(ents.FindByClass("gmod_track_signal")) do for _,sig in pairs(ents.FindByClass("gmod_track_signal")) do
if bDrawingDepth and LocalPlayer():GetPos():Distance(sig:GetPos()) < 384 then if IsValid(sig) and LocalPlayer():GetPos():Distance(sig:GetPos()) < 384 then
local pos = sig:LocalToWorld(Vector(48,0,150)) local pos = sig:LocalToWorld(Vector(48,0,150))
local ang = sig:LocalToWorldAngles(Angle(0,180,90)) local ang = sig:LocalToWorldAngles(Angle(0,180,90))
cam.Start3D2D(pos, ang, 0.25) cam.Start3D2D(pos, ang, 0.25)
@@ -569,27 +609,27 @@ local function enableDebug()
if sig.Name then if sig.Name then
draw.DrawText(Format("Joint main info (%d)",sig:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255)) draw.DrawText(Format("Joint main info (%d)",sig:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255))
draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0,0,0,255)) draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0, 0, 0, 255))
draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0,0,0,255)) draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0,0,0,255)) draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255))
draw.DrawText(Format("NextSignalName: %s",sig:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 15, 0,Color(0,0,0,255)) draw.DrawText(Format("NextSignalName: %s",sig:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 15, 0,Color(0, 0, 0, 255))
draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0,0,0,255)) draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0,0,0,255)) draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0, 0, 0, 255))
draw.DrawText(Format("Dist: %.02f",sig:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 15, 40,Color(0,0,0,255)) draw.DrawText(Format("Dist: %.02f",sig:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 15, 40,Color(0, 0, 0, 255))
draw.DrawText(Format("PrevSignalName: %s",sig:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 15, 60,Color(0,0,0,255)) draw.DrawText(Format("PrevSignalName: %s",sig:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 15, 60,Color(0, 0, 0, 255))
draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0,0,0,255)) draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0,0,0,255)) draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0, 0, 0, 255))
draw.DrawText(Format("DistPrev: %.02f",sig:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 15, 100,Color(0,0,0,255)) draw.DrawText(Format("DistPrev: %.02f",sig:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 15, 100,Color(0, 0, 0, 255))
draw.DrawText(Format("Current route: %d",sig:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 15, 120,Color(0,0,0,255)) draw.DrawText(Format("Current route: %d",sig:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 15, 120,Color(0, 0, 0, 255))
draw.DrawText("AB info","Trebuchet24",5,160,Color(200,0,0,255)) draw.DrawText("AB info","Trebuchet24",5,160,Color(200,0,0,255))
draw.DrawText(Format("Occupied: %s",sig:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,180,Color(0,0,0,255)) draw.DrawText(Format("Occupied: %s",sig:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,180,Color(0, 0, 0, 255))
draw.DrawText(Format("Linked to controller: %s",sig:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,200,Color(0,0,0,255)) draw.DrawText(Format("Linked to controller: %s",sig:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,200,Color(0, 0, 0, 255))
draw.DrawText(Format("Num: %d",sig:GetNW2Int("ControllersNumber",0)),"Trebuchet24",10,220,Color(0,0,0,255)) draw.DrawText(Format("Num: %d",sig:GetNW2Int("ControllersNumber",0)),"Trebuchet24",10,220,Color(0, 0, 0, 255))
draw.DrawText(Format("Controller logic: %s",sig:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,240,Color(0,0,0,255)) draw.DrawText(Format("Controller logic: %s",sig:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,240,Color(0, 0, 0, 255))
draw.DrawText(Format("Autostop: %s",not sig.ARSOnly and sig.AutostopPresent and (sig:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,260,Color(0,0,0,255)) draw.DrawText(Format("Autostop: %s",not sig.ARSOnly and sig.AutostopPresent and (sig:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,260,Color(0, 0, 0, 255))
draw.DrawText(Format("2/6: %s",sig:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,280,Color(0,0,0,255)) draw.DrawText(Format("2/6: %s",sig:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,280,Color(0, 0, 0, 255))
draw.DrawText(Format("FreeBS: %d",sig:GetNW2Int("FreeBS")),"Trebuchet24",5,300,Color(0,0,0,255)) draw.DrawText(Format("FreeBS: %d",sig:GetNW2Int("FreeBS")),"Trebuchet24",5,300,Color(0, 0, 0, 255))
draw.DrawText("ARS info","Trebuchet24",5,335,Color(200,0,0,255)) draw.DrawText("ARS info","Trebuchet24",5,335,Color(200,0,0,255))
local num = 0 local num = 0
@@ -599,8 +639,8 @@ local function enableDebug()
draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,100,0,255)) draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,100,0,255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,100,0,255)) draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,100,0,255))
else else
draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,0,0,255)) draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,0,0,255)) draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255))
end end
num = num+1 num = num+1
end end
@@ -608,8 +648,8 @@ local function enableDebug()
draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,100,0,255)) draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,100,0,255))
draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,100,0,255)) draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,100,0,255))
else else
draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,0,0,255)) draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,0,0,255)) draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255))
end end
if not sig.ARSOnly then if not sig.ARSOnly then
@@ -627,17 +667,11 @@ local function enableDebug()
if not data then continue end if not data then continue end
--sig.NamesOffset = sig.NamesOffset + Vector(0,0,data[1]) --sig.NamesOffset = sig.NamesOffset + Vector(0,0,data[1])
local cols = {
R = Color(200,0,0),
Y = Color(200,200,0),
G = Color(0,200,0),
W = Color(200,200,200),
B = Color(0,0,200),
}
if v ~= "M" then if v ~= "M" then
for i = 1,#v do for i = 1,#v do
ID2 = ID2 + 1 ID2 = ID2 + 1
local State = tonumber(sig.Sig[ID2]) == 1 and "X" or (tonumber(sig.Sig[ID2]) == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false local n = tonumber(sig.Sig[ID2])
local State = n == 1 and "X" or (n == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false
draw.DrawText(Format(v[i],sig:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]]) draw.DrawText(Format(v[i],sig:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]])
if State then if State then
draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]]) draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]])
@@ -655,22 +689,22 @@ local function enableDebug()
end end
end end
else else
draw.DrawText("No data...","Trebuchet24",5,0,Color(0,0,0,255)) draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255))
end end
else else
surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255) surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255)
surface.DrawRect(0, 0, 364, 25) surface.DrawRect(0, 0, 364, 25)
draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0,0,0,255)) draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255))
end end
cam.End3D2D() cam.End3D2D()
end end
end end
end) end)
else else
hook.Remove("PostDrawTranslucentRenderables","MetrostroiSignalDebug") hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
end end
end end
hook.Remove("PostDrawTranslucentRenderables","MetrostroiSignalDebug") hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug() enableDebug()

View File

@@ -178,7 +178,7 @@ function MSignalSayHook(ply, comm, fromULX)
end end
hook.Add("PlayerSay","metrostroi-signal-say", function(ply, comm) MSignalSayHook(ply,comm) end) hook.Add("PlayerSay","metrostroi-signal-say", function(ply, comm) MSignalSayHook(ply,comm) end)
function ENT:Initialize() function ENT:Initialize()
self:SetModel("models/metrostroi/signals/mus/ars_box.mdl") self:SetModel(self.TrafficLightModels[self.SignalType or 0].ArsBox.model)
self.Sprites = {} self.Sprites = {}
self.Sig = "" self.Sig = ""
self.FreeBS = 1 self.FreeBS = 1
@@ -303,9 +303,9 @@ function ENT:PostInitalize()
self.GoodInvationSignal = -1 self.GoodInvationSignal = -1
end end
if self.Left then if self.Left then
self:SetModel("models/metrostroi/signals/mus/ars_box_mittor.mdl") self:SetModel(self.TrafficLightModels[self.SignalType or 0].ArsBoxMittor.model)
else else
self:SetModel("models/metrostroi/signals/mus/ars_box.mdl") self:SetModel(self.TrafficLightModels[self.SignalType or 0].ArsBox.model)
end end
self.PostInitalized = false self.PostInitalized = false

View File

@@ -171,7 +171,7 @@ ENT.OldRouteNumberSetup = {
"1234D", "1234D",
"WKFX","LR", "WKFX","LR",
Vector(6,0,10.5), Vector(6,0,10.5),
{D=4},{["F"]=0,["L"]=0,["R"]=2,W=3,K=4} {D=4},{["F"]=0,["L"]=2,["R"]=0,W=3,K=4}
} }
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@@ -294,3 +294,26 @@ ENT.SignalConverter = {
B = 4, B = 4,
W = 5 W = 5
} }
for i = 0,2 do
--SERVER
ENT.TrafficLightModels[i].ArsBox = {model = "models/metrostroi/signals/mus/ars_box.mdl"}
ENT.TrafficLightModels[i].ArsBoxMittor = {model = "models/metrostroi/signals/mus/ars_box_mittor.mdl"}
--CLIENT
ENT.TrafficLightModels[i].LampIndicator = {model = "models/metrostroi/signals/mus/light_lampindicator", Vector(0.2), Vector(1), Vector(8), Vector(-0.9,1,1), Vector(3,0,3), Vector(-1,1,0.85)}
ENT.TrafficLightModels[i].LampBase = {model = "models/metrostroi/signals/mus/lamp_base.mdl"}
ENT.TrafficLightModels[i].SignLetterSmall = {model = "models/metrostroi/signals/mus/sign_letter_small.mdl", Vector(1.5,0,0), Vector(-1.5,0,0)}
ENT.TrafficLightModels[i].SignLetter = {model = "models/metrostroi/signals/mus/sign_letter.mdl", z = 5.85}
ENT.TrafficLightModels[i].LetMaterials = {str = "models/metrostroi/signals/let/"}
ENT.TrafficLightModels[i].RouteNumberOffset = Vector(10,0,0)
ENT.TrafficLightModels[i].DoubleOffset = Vector(0,0,1.62)
ENT.TrafficLightModels[i].RouteNumberOffset2 = Vector(0,0,7.2)
ENT.TrafficLightModels[i].SpecRouteNumberOffset = Vector(3,-1,3)
ENT.TrafficLightModels[i].RouteNumberOffset3 = Vector(10.5,0,-6)
ENT.TrafficLightModels[i].SpecRouteNumberOffset2 = Vector(-0.8,1,0.94)
ENT.TrafficLightModels[i].RouaOffset = Vector(6.2,0,24.5)
end

View File

@@ -3,9 +3,9 @@ include("shared.lua")
local debug = GetConVar("metrostroi_drawsignaldebug") local debug = GetConVar("metrostroi_drawsignaldebug")
local function enableDebug() local function enableDebug()
if debug:GetBool() then if debug:GetBool() then
hook.Add("PostDrawTranslucentRenderables","MetrostroiSwitchDebug",function(bDrawingDepth,bDrawingSkybox) hook.Add("PreDrawEffects","MetrostroiSwitchDebug",function()
for _,ent in pairs(ents.FindByClass("gmod_track_switch")) do for _,ent in pairs(ents.FindByClass("gmod_track_switch")) do
if bDrawingDepth and LocalPlayer():GetPos():Distance(sig:GetPos()) < 512 then if IsValid(ent) and LocalPlayer():GetPos():Distance(ent:GetPos()) < 512 then
local pos = ent:LocalToWorld(Vector(30,0,75)) local pos = ent:LocalToWorld(Vector(30,0,75))
local ang = ent:LocalToWorldAngles(Angle(0,180,90)) local ang = ent:LocalToWorldAngles(Angle(0,180,90))
cam.Start3D2D(pos, ang, 0.25) cam.Start3D2D(pos, ang, 0.25)
@@ -18,9 +18,9 @@ local function enableDebug()
end end
end) end)
else else
hook.Remove("PostDrawTranslucentRenderables","MetrostroiSwitchDebug") hook.Remove("PreDrawEffects","MetrostroiSwitchDebug")
end end
end end
hook.Remove("PostDrawTranslucentRenderables","MetrostroiSwitchDebug") hook.Remove("PreDrawEffects","MetrostroiSwitchDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug) cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug() enableDebug()