Skip to content

Commit

Permalink
06.01.00097: fixed killing aiTrafficTriggers
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGaertner committed Feb 26, 2019
1 parent 7668b54 commit a8b36c9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
5 changes: 3 additions & 2 deletions TrafficCollision.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ end
-- not running with the AIDriver (the code in traffic.lua seems to be safely handle
-- the lack of collision triggers)
function CollisionDetector:removeLegacyCollisionTriggers()
for i, node in ipairs(self.vehicle.cp.trafficCollisionTriggers) do
for i=self.vehicle.cp.numTrafficCollisionTriggers,1,-1 do
local node = self.vehicle.cp.trafficCollisionTriggers[i]
if node then
removeTrigger(node)
if entityExists(node) then
Expand All @@ -68,8 +69,8 @@ function CollisionDetector:removeLegacyCollisionTriggers()
end
CpManager.trafficCollisionIgnoreList[node] = nil
self.vehicle.cp.trafficCollisionTriggers[i] = nil
self.vehicle.cp.numTrafficCollisionTriggers = 0 -- why not #trafficCollisionTriggers???
end
self.vehicle.cp.numTrafficCollisionTriggers = 0 -- why not #trafficCollisionTriggers???
end

function CollisionDetector:findAiCollisionTrigger(object)
Expand Down
28 changes: 23 additions & 5 deletions base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ function courseplay:onLoad(savegame)
self.cp.numCollidingObjects = {
all = 0;
};

--TODO Tommi: remove this when we are completely on AIDriver
if self.aiTrafficCollisionTrigger ~= nil then
self.cp.numTrafficCollisionTriggers = 4;
for i=1,self.cp.numTrafficCollisionTriggers do
Expand Down Expand Up @@ -1251,14 +1253,30 @@ function courseplay:preDelete()
end;
end;

function courseplay:delete()
function courseplay:onDelete()
if self.cp.driver and self.cp.driver.collisionDetector then
self.cp.driver.collisionDetector:deleteTriggers()
end


--TODO Tommi: remove this when we are completely on AIDriver
for i=#self.cp.trafficCollisionTriggers,1,-1 do

local node = self.cp.trafficCollisionTriggers[i]
if node ~= nil then
removeTrigger(trigger);
if entityExists(node) then
unlink(node)
delete(node)
end
end
end;
if self.aiTrafficCollisionTrigger ~= nil then
removeTrigger(self.aiTrafficCollisionTrigger);
end;
for i,trigger in pairs(self.cp.trafficCollisionTriggers) do
removeTrigger(trigger);
end;

---


if self.cp ~= nil then
if self.cp.headland and self.cp.headland.tg then
unlink(self.cp.headland.tg);
Expand Down
2 changes: 1 addition & 1 deletion modDesc.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="40">
<version>6.01.00096</version>
<version>6.01.00097</version>
<author><![CDATA[Courseplay.devTeam]]></author>
<title>
<br>CoursePlay SIX</br>
Expand Down
1 change: 1 addition & 0 deletions register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function courseplay.registerEventListeners(vehicleType)
SpecializationUtil.registerEventListener(vehicleType, "onPostLoad", courseplay)
SpecializationUtil.registerEventListener(vehicleType, "onEnterVehicle", courseplay)
SpecializationUtil.registerEventListener(vehicleType, "onLeaveVehicle", courseplay)
SpecializationUtil.registerEventListener(vehicleType, "onDelete", courseplay)
end

if courseplay.houstonWeGotAProblem then
Expand Down

0 comments on commit a8b36c9

Please sign in to comment.