mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
release branch init
This commit is contained in:
@@ -48,7 +48,6 @@ function ENT:Initialize()
|
||||
self.NonPassengerSounds = CreateSound(self,Sound( "ambient/levels/canals/tunnel_wind_loop1.wav" ))
|
||||
self.ClientModels = {}
|
||||
self.CleanupModels = {}
|
||||
self:DrawShadow(false)
|
||||
end
|
||||
|
||||
function ENT:OnRemove()
|
||||
@@ -165,11 +164,13 @@ function ENT:Think()
|
||||
self.DeltaTime = (CurTime() - self.PrevTime)
|
||||
self.PrevTime = CurTime()
|
||||
if self:IsDormant() then
|
||||
if self.Pool then
|
||||
if self.PlatformDrawn then
|
||||
self:OnRemove()
|
||||
self.PlatformDrawn = false
|
||||
end
|
||||
return
|
||||
end
|
||||
self.PlatformDrawn = true
|
||||
|
||||
if self:GetNW2Bool("MustPlayAnnounces") then
|
||||
self.PassengerSounds:SetSoundLevel(105)
|
||||
@@ -214,7 +215,6 @@ function ENT:Think()
|
||||
self:PopulatePlatform(platformStart,platformEnd,stationCenter)
|
||||
end
|
||||
|
||||
local modelCount = 0
|
||||
-- Check if set of models changed
|
||||
if (CurTime() - (self.ModelCheckTimer or 0) > 1.0) and poolReady then
|
||||
self.ModelCheckTimer = CurTime()
|
||||
@@ -244,8 +244,6 @@ function ENT:Think()
|
||||
self.ClientModels[i]:SetModelScale(self.Pool[i].scale,0)
|
||||
self.ClientModels[i]:DestroyShadow()
|
||||
self.ClientModels[i]:DrawShadow(false)
|
||||
modelCount = modelCount + 1
|
||||
if modelCount > 15 then poolReady = false self.ModelCheckTimer = self.ModelCheckTimer - 0.9 break end
|
||||
end
|
||||
else
|
||||
-- Model found that is not in window
|
||||
@@ -272,7 +270,6 @@ function ENT:Think()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add models for cleanup of people who left trains
|
||||
self.PassengersLeft = self.PassengersLeft or self:GetNW2Int("PassengersLeft")
|
||||
while poolReady and (self.PassengersLeft < self:GetNW2Int("PassengersLeft")) do
|
||||
@@ -318,32 +315,19 @@ function ENT:Think()
|
||||
-- Animate models for cleanup
|
||||
for k,v in pairs(self.CleanupModels) do
|
||||
-- if not v or not IsValid(v) then self.CleanupModels[k] = nil return end
|
||||
if not IsValid(v.ent) then
|
||||
self.CleanupModels[k] = nil
|
||||
continue
|
||||
end
|
||||
if not IsValid(v.ent) then continue end
|
||||
-- Get pos and target in XY plane
|
||||
local pos = v.ent:GetPos()
|
||||
local target = v.target
|
||||
pos.z = 0
|
||||
target.z = 0
|
||||
|
||||
local distance = pos:DistToSqr(target)
|
||||
local count = self:GetNW2Int("TrainDoorCount",0)
|
||||
-- Delete if reached the target point
|
||||
if distance < 2*256--[[threshold]] or math.abs(LocalPlayer():GetPos().z - v.ent:GetPos().z) > 256 or count == 0 then
|
||||
v.ent:Remove()
|
||||
self.CleanupModels[k] = nil
|
||||
continue
|
||||
end
|
||||
|
||||
|
||||
-- Find direction in which pedestrians must walk
|
||||
local targetDir = (target - pos):GetNormalized()
|
||||
|
||||
-- Make it go along the platform if too far
|
||||
local threshold = 16
|
||||
if distance > 36864--[[192]] then
|
||||
local distance = pos:Distance(target)
|
||||
if distance > 192 then
|
||||
local platformDir = (platformEnd-platformStart):GetNormalized()
|
||||
local projection = targetDir:Dot(platformDir)
|
||||
if math.abs(projection) > 0.1 then
|
||||
@@ -352,19 +336,27 @@ function ENT:Think()
|
||||
end
|
||||
|
||||
-- Move pedestrian
|
||||
local threshold = 16
|
||||
local speed = 1024
|
||||
if distance > 1048576--[[1024]] then speed = 2048 end
|
||||
if distance > 1024 then speed = 256 end
|
||||
v.ent:SetPos(v.ent:GetPos() + targetDir*math.min(threshold,speed*self.DeltaTime))
|
||||
-- Rotate pedestrian
|
||||
v.ent:SetAngles(targetDir:Angle() + Angle(0,180,0))
|
||||
|
||||
-- Delete if reached the target point
|
||||
if distance < 2*threshold or LocalPlayer():GetPos().z - v.ent:GetPos().z > 500 then
|
||||
v.ent:Remove()
|
||||
self.CleanupModels[k] = nil
|
||||
end
|
||||
|
||||
--[[ Check if door can be reached at all (it still exists)
|
||||
|
||||
-- Check if door can be reached at all (it still exists)
|
||||
local count = self:GetNW2Int("TrainDoorCount",0)
|
||||
local distance = 1e9
|
||||
local new_target = target
|
||||
for j=1,count do
|
||||
local vec = self:GetNW2Vector("TrainDoor"..j,Vector(0,0,0))
|
||||
local d = vec:DistToSqr(v.target)
|
||||
local d = vec:Distance(v.target)
|
||||
if d < distance then
|
||||
new_target = vec
|
||||
distance = d
|
||||
@@ -374,7 +366,7 @@ function ENT:Think()
|
||||
--if distance > 32
|
||||
--then v.target = self:GetPos()
|
||||
--else v.target = new_target
|
||||
--end]]
|
||||
--end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ function ENT:Initialize()
|
||||
-- Get platform parameters
|
||||
self.VMF = self.VMF or {}
|
||||
self.PlatformStart = ents.FindByName(self.VMF.PlatformStart or "")[1]
|
||||
self.SignOff = tonumber(self.VMF.Sign or self.VMF.NoSign or "0") == 1
|
||||
self.SignOff = tonumber(self.VMF.Sign or "0") == 1
|
||||
self.PlatformEnd = ents.FindByName(self.VMF.PlatformEnd or "")[1]
|
||||
self.StationIndex = tonumber(self.VMF.StationIndex) or 100
|
||||
self.PlatformIndex = tonumber(self.VMF.PlatformIndex) or 1
|
||||
@@ -136,7 +136,6 @@ function ENT:Initialize()
|
||||
self.NoEntry.specarr = Sound(Metrostroi.StationAnnouncesTo[self.StationIndex][3])
|
||||
self.NoEntry.specdep = Sound(Metrostroi.StationAnnouncesTo[self.StationIndex][4])
|
||||
end]]
|
||||
self:DrawShadow(false)
|
||||
end
|
||||
|
||||
function ENT:OnRemove()
|
||||
@@ -151,6 +150,7 @@ function ENT:KeyValue(key, value)
|
||||
self.VMF[key] = value
|
||||
end
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Process platform logic
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -226,14 +226,6 @@ function ENT:GetDoorState()
|
||||
return false
|
||||
end
|
||||
|
||||
local function getPassengerRate(passCount)
|
||||
if passCount < 80 then
|
||||
return 1-((passCount/80)^3)*0.2
|
||||
else
|
||||
return 1-math.min(1, (((passCount-80)/220)^0.6)*0.85+0.2)
|
||||
end
|
||||
end
|
||||
|
||||
ENT.TESTTEST = false
|
||||
local dT = 0.25
|
||||
local trains = {}
|
||||
@@ -315,8 +307,7 @@ function ENT:Think()
|
||||
end
|
||||
|
||||
-- Open doors on station
|
||||
if stopped_fine and (v.SOSD or self.OldOpened and not self.OpenedBySOSD) then
|
||||
self.OpenedBySOSD = v.SOSD
|
||||
if stopped_fine and v.SOSD then
|
||||
self.HorliftTimer1 = self.HorliftTimer1 or CurTime()
|
||||
if ((CurTime() - self.HorliftTimer1) > 0.5) then
|
||||
if not self.HorliftTimer2 then self:FireHorliftDoors("Open") end
|
||||
@@ -362,38 +353,17 @@ function ENT:Think()
|
||||
if not left_side then door_count = #v.RightDoorPositions end
|
||||
|
||||
-- Get maximum boarding rate for normal russian subway train doors
|
||||
local max_boarding_rate = getPassengerRate(v:GetNW2Int("PassengerCount")) * 1.4 * door_count * dT
|
||||
--print(Format("R:%.2f\tS:%.2f\tP:% 3d",max_boarding_rate,getPassengerRate(v:GetNW2Int("PassengerCount")),v:GetNW2Int("PassengerCount")))
|
||||
local max_boarding_rate = 1.4 * door_count * dT
|
||||
-- Get boarding rate based on passenger density
|
||||
local boarding_rate = math.min(max_boarding_rate,passenger_count)
|
||||
if self.PlatformLast then boarding_rate = 0 end
|
||||
-- Get rate of leaving
|
||||
local leaving_rate = 1.4 * door_count * dT
|
||||
if v.PassengersToLeave == 0 and not v.AnnouncementToLeaveWagonAcknowledged then leaving_rate = 0 end
|
||||
if v.AnnouncementToLeaveWagonAcknowledged then leaving_rate = leaving_rate*1.5 end
|
||||
-- Board these passengers into train
|
||||
local speedLimit = math.max(0,1-math.abs(v.Speed/5))
|
||||
local boarded,left,count
|
||||
--if v.AnnouncementToLeaveWagonAcknowledged then
|
||||
if v.AnnouncementToLeaveWagonAcknowledged then
|
||||
boarded = 0
|
||||
left = math.ceil(math.min(math.max(2,leaving_rate + 0.5),v:GetNW2Int("PassengerCount"))*speedLimit*1.5)
|
||||
count = v:GetNW2Int("PassengerCount")
|
||||
else
|
||||
count = self:PopulationCount() + v.PassengersToLeave
|
||||
boarded = math.ceil(math.min(math.max(2,boarding_rate+0.5),self:PopulationCount())*speedLimit)
|
||||
left = math.ceil(math.min(math.max(2,leaving_rate +0.5),v.PassengersToLeave)*speedLimit)
|
||||
end
|
||||
if (v.PrevLeftDoorsOpening ~= v.LeftDoorsOpening) then
|
||||
v.CanStuckPassengerLeft = not v.LeftDoorsOpening and ((boarded > 0 or left > 0) and math.min(1,count/100) or math.min(1,count/400))
|
||||
v.PrevLeftDoorsOpening = v.LeftDoorsOpening
|
||||
if v.LeftDoorsOpening then v.LastPlatform = nil end
|
||||
end
|
||||
if (v.PrevRightDoorsOpening ~= v.RightDoorsOpening) then
|
||||
v.CanStuckPassengerRight = not v.RightDoorsOpening and ((boarded > 0 or left > 0) and math.min(1,count/100) or math.min(1,count/400))
|
||||
v.PrevRightDoorsOpening = v.RightDoorsOpening
|
||||
if v.RightDoorsOpening then v.LastPlatform = nil end
|
||||
end
|
||||
|
||||
local boarded = math.min(math.max(2,math.floor(boarding_rate+0.5)),v.AnnouncementToLeaveWagonAcknowledged and 0 or self:PopulationCount())
|
||||
local left = math.min(math.max(2,math.floor(leaving_rate +0.5)),v.AnnouncementToLeaveWagonAcknowledged and v:GetNW2Int("PassengerCount") or v.PassengersToLeave)
|
||||
if math.random() <= math.Clamp(17-passenger_count,0,17)/17*0.5 then boarded = 0 end
|
||||
if math.random() <= math.Clamp(17-v.PassengersToLeave,0,17)/17*0.5 then left = 0 end
|
||||
local passenger_delta = boarded - left
|
||||
@@ -432,11 +402,11 @@ function ENT:Think()
|
||||
|
||||
-- Keep list of door positions
|
||||
if left_side then
|
||||
for k, vec in ipairs(v.LeftDoorPositions) do
|
||||
for k, vec in pairs(v.LeftDoorPositions) do
|
||||
table.insert(boardingDoorList, v:LocalToWorld(vec))
|
||||
end
|
||||
else
|
||||
for k, vec in ipairs(v.RightDoorPositions) do
|
||||
for k, vec in pairs(v.RightDoorPositions) do
|
||||
table.insert(boardingDoorList, v:LocalToWorld(vec))
|
||||
end
|
||||
end
|
||||
@@ -548,7 +518,7 @@ function ENT:Think()
|
||||
end]]
|
||||
-- Add passengers
|
||||
if (not self.PlatformLast) and (#boardingDoorList == 0) then
|
||||
local target = (Metrostroi.PassengersScale or 50)*self.PopularityIndex --300
|
||||
local target = GetConVarNumber("metrostroi_passengers_scale",50)*self.PopularityIndex --300
|
||||
-- then target = target*0.1 end
|
||||
|
||||
if target <= 0 then
|
||||
@@ -583,7 +553,6 @@ function ENT:Think()
|
||||
self.ARSOverride = true
|
||||
self.OldOpened = self:GetDoorState()
|
||||
self.OldPeopleGoing = PeopleGoing
|
||||
if not self.OldOpened then self.OpenedBySOSD = false end
|
||||
end
|
||||
-- Block local ARS sections
|
||||
if self.ARSOverride ~= nil then
|
||||
|
||||
Reference in New Issue
Block a user