Skip to content

Commit b07683b

Browse files
committed
add dock ordering, magically reverse the concepts of left and right
1 parent c8af2b4 commit b07683b

File tree

7 files changed

+326
-5
lines changed

7 files changed

+326
-5
lines changed

Data/Base.rte/Activities/Utility/DeliveryCreationHandler.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,23 @@ function DeliveryCreationHandler:CreateEliteSquad(team, squadCountOrTypeTable, s
10261026

10271027
end
10281028

1029+
function DeliveryCreationHandler:CreateCraft(team, forceRocketUsage)
1030+
1031+
local craftGroup = "Craft - Dropships";
1032+
if forceRocketUsage then
1033+
craftGroup = "Craft - Rockets";
1034+
end
1035+
presetName, createFunc, techName = self:SelectPresetByGroupPair(team, craftGroup, craftGroup, craftGroup, craftGroup);
1036+
1037+
local craft = _G[createFunc](presetName, techName);
1038+
craft.Team = team;
1039+
--print(craft)
1040+
1041+
local goldCost = ToSceneObject(craft):GetTotalValue(self.teamTechIDTable[team], 1);
1042+
1043+
return craft, goldCost
1044+
end
1045+
10291046
function DeliveryCreationHandler:CreateSquadWithCraft(team, forceRocketUsage, squadCountOrTypeTable, squadType)
10301047

10311048
local craftGroup = "Craft - Dropships";

Data/Base.rte/Activities/Utility/DockingHandler.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ function DockingHandler:SpawnUndersideDockingCraft(craft, specificDock)
232232
SceneMan:ForceBounds(pos);
233233
craft:AddAISceneWaypoint(pos);
234234
craft:AddAISceneWaypoint(dockTable.dockPosition);
235-
local direction = dockToDockAt % 2 == 0 and 1 or -1;
235+
local direction = dockToDockAt % 2 == 0 and 1 or -1;
236+
print("direction: " .. direction);
236237
craft:AddAISceneWaypoint(dockTable.dockPosition + Vector(275 * direction, 0))
237238

238239
dockTable.activeCraft = craft;

Data/Browncoats.rte/Activities/RefineryAssaultFunctions.lua

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ function RefineryAssault:HandleMessage(message, object)
1515

1616
-- this is ugly, but there's no way to avoid this stuff except hiding it away even harder than in this separate script...
1717

18+
-- Dock console ordering message
19+
if message == "Refinery_DockConsoleOrder" then
20+
21+
-- object is a table with the UniqueID of the ordering console, with the dock it wants, then with a table of the ordered items in UniqueID form
22+
23+
local success = self:TryDockConsoleOrder(object[2], object[3]);
24+
25+
local console = MovableMan:FindObjectByUniqueID(object[1]);
26+
console:SendMessage("Refinery_DockConsoleOrderSuccess", success);
27+
end
28+
1829
if message == "ActorSpawner_ReturnedActor" then
1930

2031
if self.verboseLogging then
@@ -882,6 +893,25 @@ function RefineryAssault:RemoveStringFromTable(str, tab)
882893

883894
end
884895

896+
function RefineryAssault:TryDockConsoleOrder(desiredDock, itemTable)
897+
local craft, goldCost = self.deliveryCreationHandler:CreateCraft(self.humanTeam, false);
898+
craft.PlayerControllable = self.humansAreControllingAlliedActors;
899+
900+
for i = 1, #itemTable do
901+
local item = MovableMan:FindObjectByUniqueID(itemTable[i])
902+
if item then
903+
-- it's utterly ridiculous we have to do this...
904+
local class = item.ClassName;
905+
local typeCast = "To" .. class
906+
local clonedItem = _G[typeCast](item):Clone();
907+
craft:AddInventoryItem(clonedItem);
908+
end
909+
end
910+
911+
local success = self.dockingHandler:SpawnDockingCraft(craft, desiredDock);
912+
return success;
913+
end
914+
885915
function RefineryAssault:SendDockDelivery(team, task, forceRocketUsage, squadType)
886916

887917
local squadCount = math.random(3, 4);
@@ -1199,11 +1229,11 @@ function RefineryAssault:SetupFirstStage()
11991229
taskArea = SceneMan.Scene:GetOptionalArea("TacticsPatrolArea_MissionStage1");
12001230
local task = self.tacticsHandler:AddTask("Search And Destroy", self.humanTeam, taskArea, "PatrolArea", 10);
12011231

1202-
local squad = self:SendDockDelivery(self.humanTeam, task, true, "Elite");
1232+
local squad = self:SendDockDelivery(self.humanTeam, task, false, "Elite");
12031233

12041234
self.tacticsHandler:AddSquad(self.humanTeam, squad, task.Name, true);
12051235

1206-
squad = self:SendDockDelivery(self.humanTeam, task, true, "Elite");
1236+
squad = self:SendDockDelivery(self.humanTeam, task, false, "Elite");
12071237

12081238
self.tacticsHandler:AddSquad(self.humanTeam, squad, task.Name, true);
12091239

Data/Browncoats.rte/Scenes/Objects/Capturables/Capturables.ini

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,59 @@ AddActor = MOSRotating
271271

272272
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
273273
// Dock and buy door capturables
274+
// Dock capturables have an extra script to allow for ordering in the current buy order
274275

276+
// It's not great this is here but putting it elsewhere would be even less great
277+
AddPieSlice = PieSlice
278+
PresetName = Refinery Dock Console Order
279+
Description = Order
280+
Direction = Left
281+
Icon = Icon
282+
CopyOf = Trade Star
283+
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/DockConsolePieSliceActions.lua
284+
FunctionName = CommandActorDockConsoleOrder
285+
286+
// This actually starts captured, it's here for neatness and the dock ordering system
287+
AddActor = MOSRotating
288+
CopyOf = Generic Capturable Computer
289+
PresetName = Refinery S1 Dock Console
290+
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/RefineryCapturableFX.lua
291+
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/RefineryDockOrderConsole.lua
292+
AddCustomValue = NumberValue
293+
StartTeam = 0
294+
AddCustomValue = NumberValue
295+
SecondsToCapture = 10
296+
AddCustomValue = NumberValue
297+
InstantReset = 0
298+
AddCustomValue = NumberValue
299+
NeutralIfNotFullyCapped = 0
300+
AddCustomValue = NumberValue
301+
NeedFullControlToCap = 0
302+
AddCustomValue = StringValue
303+
SceneCaptureArea = CaptureArea_RefineryS1DockConsole
304+
AddCustomValue = NumberValue
305+
SendCaptureMessageGlobally = 0
306+
AddCustomValue = StringValue
307+
CaptureMessage = Captured_RefineryS1DockConsole
308+
AddCustomValue = StringValue
309+
DeactivationMessage = DeactivateCapturable_RefineryS1DockConsole
310+
AddCustomValue = StringValue
311+
ActivationMessage = ActivateCapturable_RefineryS1DockConsole
312+
AddCustomValue = NumberValue
313+
DeactivateOnCapture = 1
314+
AddCustomValue = NumberValue
315+
OnlyBrainCanCapture = 0
316+
// Unique to this for the above reason, shouldn't ever be actually captured by anyone
317+
AddCustomValue = NumberValue
318+
Deactivated = 1
319+
AddCustomValue = NumberValue
320+
DockIdentifier = 1
275321
276322
AddActor = MOSRotating
277323
CopyOf = Generic Capturable Computer
278324
PresetName = Refinery S3 Dock Console
279325
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/RefineryCapturableFX.lua
326+
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/RefineryDockOrderConsole.lua
280327
AddCustomValue = NumberValue
281328
StartTeam = 1
282329
AddCustomValue = NumberValue
@@ -306,6 +353,7 @@ AddActor = MOSRotating
306353
CopyOf = Generic Capturable Computer
307354
PresetName = Refinery S4 Dock Console
308355
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/RefineryCapturableFX.lua
356+
ScriptPath = Browncoats.rte/Scenes/Objects/Capturables/RefineryDockOrderConsole.lua
309357
AddCustomValue = NumberValue
310358
StartTeam = 1
311359
AddCustomValue = NumberValue
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function CommandActorDockConsoleOrder(self)
2+
self:SetNumberValue("DockConsole_Order", 1);
3+
end
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
function OnMessage(self, message, object)
2+
if message == "Refinery_DockConsoleOrderSuccess" then
3+
self.lastOrderSuccess = object;
4+
end
5+
end
6+
7+
function DockConsoleSetupOrder(self, orderList)
8+
local preActorItemList = {};
9+
local lastActor
10+
local finalOrder = {};
11+
12+
for item in orderList do
13+
local class = item.ClassName;
14+
local typeCast = "To" .. class
15+
16+
local clonedItem = _G[typeCast](item):Clone();
17+
if IsActor(clonedItem) and team then
18+
clonedItem.Team = team;
19+
end
20+
21+
if IsAHuman(item) then
22+
lastActor = clonedItem;
23+
if preActorItemList and #preActorItemList > 0 then
24+
for k, preActorItem in ipairs(preActorItemList) do
25+
lastActor:AddInventoryItem(preActorItem);
26+
end
27+
preActorItemList = nil;
28+
end
29+
30+
table.insert(finalOrder, lastActor);
31+
elseif IsActor(item) then
32+
item = clonedItem;
33+
table.insert(finalOrder, item);
34+
elseif IsHeldDevice(item) then
35+
item = clonedItem;
36+
if lastActor then
37+
ToAHuman(lastActor):AddInventoryItem(item);
38+
else
39+
table.insert(preActorItemList, item);
40+
end
41+
else
42+
print("Buy Door was given an order item with a class it couldn't handle: " .. item);
43+
end
44+
end
45+
46+
-- No AHumans could take the items we bought
47+
if preActorItemList and #preActorItemList > 0 then
48+
for k, preActorItem in ipairs(preActorItemList) do
49+
table.insert(finalOrder, preActorItem);
50+
end
51+
52+
preActorItemList = nil;
53+
end
54+
55+
if #finalOrder == 0 then
56+
self.Message = "Nothing to order!"
57+
self.messageTime = 4000;
58+
self.messageTimer:Reset();
59+
return nil;
60+
else -- Finally, post-process the new items into their UniqueIDs
61+
for k, item in ipairs(finalOrder) do
62+
finalOrder[k] = item.UniqueID;
63+
end
64+
end
65+
66+
return finalOrder;
67+
end
68+
69+
function Create(self)
70+
self.Activity = ToGameActivity(ActivityMan:GetActivity());
71+
72+
self.Message = "";
73+
self.messageTimer = Timer();
74+
self.messageTime = 0;
75+
76+
self.closeActorTable = {};
77+
self.actorUpdateTimer = Timer();
78+
self.actorUpdateDelay = 50;
79+
80+
self.detectRange = 200;
81+
82+
-- This is horrible and I hate it
83+
-- Represents Stage (the number after S in the dock capturable name)
84+
if self:GetNumberValue("DockIdentifier") == 1 then
85+
self.assignedDocks = {1, 2};
86+
elseif self:GetNumberValue("DockIdentifier") == 3 then
87+
self.assignedDocks = {2, 3};
88+
elseif self:GetNumberValue("DockIdentifier") == 4 then
89+
self.assignedDocks = {4, 5};
90+
end
91+
92+
self.orderPieSlice = CreatePieSlice("Refinery Dock Console Order", "Base.rte");
93+
end
94+
95+
function ThreadedUpdate(self)
96+
if self.actorUpdateTimer:IsPastSimMS(self.actorUpdateDelay) then
97+
for actor in MovableMan:GetMOsInRadius(self.Pos, self.detectRange, -1, false) do
98+
if (not self.closeActorTable[actor.UniqueID]) and IsAHuman(actor) or IsACrab(actor) then
99+
actor = ToActor(actor);
100+
if actor.Team == self.Team then
101+
self.closeActorTable[actor.UniqueID] = actor.UniqueID;
102+
end
103+
end
104+
end
105+
106+
self:RequestSyncedUpdate();
107+
end
108+
109+
if not self.messageTimer:IsPastSimMS(self.messageTime) then
110+
PrimitiveMan:DrawTextPrimitive(self.Pos + Vector(0, -50), self.Message, true, 1);
111+
end
112+
end
113+
114+
function SyncedUpdate(self)
115+
if self.actorUpdateTimer:IsPastSimMS(self.actorUpdateDelay) then
116+
self.actorUpdateTimer:Reset();
117+
118+
for k, v in pairs(self.closeActorTable) do
119+
local actor = MovableMan:FindObjectByUniqueID(v);
120+
if actor and MovableMan:ValidMO(actor) then
121+
actor = ToActor(actor);
122+
local dist = SceneMan:ShortestDistance(self.Pos, actor.Pos, true);
123+
if dist:MagnitudeIsGreaterThan(self.detectRange) then
124+
actor.PieMenu:RemovePieSlicesByPresetName(self.orderPieSlice.PresetName);
125+
actor:RemoveNumberValue("DockConsole_Order");
126+
self.closeActorTable[k] = nil;
127+
else
128+
actor.PieMenu:AddPieSliceIfPresetNameIsUnique(self.orderPieSlice, self);
129+
if actor:NumberValueExists("DockConsole_Order") then
130+
actor:RemoveNumberValue("DockConsole_Order");
131+
-- Set up order here
132+
133+
local team = actor.Team;
134+
local player = actor:GetController().Player;
135+
local buyGUI = self.Activity:GetBuyGUI(player);
136+
local orderCost = buyGUI:GetTotalCartCost();
137+
138+
local funds = self.Activity:GetTeamFunds(team);
139+
140+
if funds < orderCost then
141+
self.Message = "Insufficient funds!"
142+
self.messageTime = 4000;
143+
self.messageTimer:Reset();
144+
return;
145+
end
146+
147+
local orderList = buyGUI:GetOrderList();
148+
local finalOrder = DockConsoleSetupOrder(self, orderList, team);
149+
150+
-- Finally, we make our order table see ask if the Activity can deliver this to one of our chosen docks
151+
if finalOrder then
152+
local dockNum = self.assignedDocks[1];
153+
154+
local activityOrder = {self.UniqueID, dockNum, finalOrder};
155+
self.Activity:SendMessage("Refinery_DockConsoleOrder", activityOrder);
156+
-- By now we've gotten a response message
157+
if not self.lastOrderSuccess then
158+
-- Try again with our second assigned dock
159+
activityOrder[2] = self.assignedDocks[2];
160+
self.Activity:SendMessage("Refinery_DockConsoleOrder", activityOrder);
161+
if not self.lastOrderSuccess then
162+
self.Message = "No docks available!"
163+
self.messageTime = 4000;
164+
self.messageTimer:Reset();
165+
return;
166+
end
167+
end
168+
-- If we're here we succeeded so drain funds
169+
self.Activity:SetTeamFunds(funds - orderCost, team);
170+
171+
self.Message = "Order arriving soon..."
172+
self.messageTime = 4000;
173+
self.messageTimer:Reset();
174+
end
175+
end
176+
end
177+
else
178+
self.closeActorTable[k] = nil;
179+
end
180+
end
181+
end
182+
end
183+
184+
function OnSave(self)
185+
186+
end

0 commit comments

Comments
 (0)