Ticket #2128: diffDirectDeploy

File diffDirectDeploy, 5.1 KB (added by Palantius, 11 years ago)
Line 
1--- /home/albert/VirtualBox VMs/0ad/mods/ProductionQueueOld.js
2+++ /home/albert/VirtualBox VMs/0ad/mods/asd
3@@ -29,7 +29,20 @@
4 "</attribute>" +
5 "<text/>" +
6 "</element>" +
7- "</optional>";
8+ "</optional>" +
9+ "<optional>" +
10+ "<element name='DirectDeployUnit'>" +
11+ "<attribute name='datatype'>" +
12+ "<value>tokens</value>" +
13+ "</attribute>" +
14+ "<text/>" +
15+ "</element>" +
16+ "</optional>" +
17+ "<optional>" +
18+ "<element name='DirectDeployCount'>" +
19+ "<data type='nonNegativeInteger'/>" +
20+ "</element>" +
21+ "</optional>";;
22
23 ProductionQueue.prototype.Init = function()
24 {
25@@ -67,6 +80,41 @@
26 this.spawnNotified = false;
27 };
28
29+ProductionQueue.prototype.OnOwnershipChanged = function(msg)
30+{
31+ if (msg.from == -1)
32+ {
33+ //Deploy units once the structure is built
34+ if (this.template.DirectDeployUnit && this.template.DirectDeployCount)
35+ {
36+ var directDeployCount = +this.template.DirectDeployCount;
37+ var directDeployUnit = this.template.DirectDeployUnit._string;
38+
39+ // Replace the "{civ}" codes with this entity's civ ID
40+ var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
41+ if (cmpIdentity)
42+ directDeployUnit = directDeployUnit.replace(/\{civ\}/g, cmpIdentity.GetCiv())
43+
44+ //Deploy the units
45+ this.AddBatch(directDeployUnit, "directDeploy", directDeployCount, "");
46+ }
47+ }
48+ else
49+ {
50+ // Unset flag that previous owner's training may be blocked
51+ var cmpPlayer = QueryPlayerIDInterface(msg.from, IID_Player);
52+ if (cmpPlayer && this.queue.length > 0)
53+ cmpPlayer.UnBlockTraining();
54+
55+ // Reset the production queue whenever the owner changes.
56+ // (This should prevent players getting surprised when they capture
57+ // an enemy building, and then loads of the enemy's civ's soldiers get
58+ // created from it. Also it means we don't have to worry about
59+ // updating the reserved pop slots.)
60+ this.ResetQueue();
61+ }
62+};
63+
64 /*
65 * Returns list of entities that can be trained by this building.
66 */
67@@ -185,7 +233,7 @@
68 if (this.queue.length < MAX_QUEUE_SIZE)
69 {
70
71- if (type == "unit")
72+ if (type == "unit" || type == "directDeploy")
73 {
74 // Find the template data so we can determine the build costs
75 var cmpTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager);
76@@ -211,10 +259,6 @@
77
78 var population = +template.Cost.Population;
79
80- // TrySubtractResources should report error to player (they ran out of resources)
81- if (!cmpPlayer.TrySubtractResources(totalCosts))
82- return;
83-
84 // Update entity count in the EntityLimits component
85 if (template.TrainingRestrictions)
86 {
87@@ -222,19 +266,41 @@
88 var cmpPlayerEntityLimits = QueryOwnerInterface(this.entity, IID_EntityLimits);
89 cmpPlayerEntityLimits.IncreaseCount(unitCategory, count);
90 }
91-
92- this.queue.push({
93- "id": this.nextID++,
94- "player": cmpPlayer.GetPlayerID(),
95- "unitTemplate": templateName,
96- "count": count,
97- "metadata": metadata,
98- "resources": costs,
99- "population": population,
100- "productionStarted": false,
101- "timeTotal": time*1000,
102- "timeRemaining": time*1000,
103- });
104+
105+ if (type == "unit")
106+ {
107+ // TrySubtractResources should report error to player (they ran out of resources)
108+ if (!cmpPlayer.TrySubtractResources(totalCosts))
109+ return;
110+
111+ this.queue.push({
112+ "id": this.nextID++,
113+ "player": cmpPlayer.GetPlayerID(),
114+ "unitTemplate": templateName,
115+ "count": count,
116+ "metadata": metadata,
117+ "resources": costs,
118+ "population": population,
119+ "productionStarted": false,
120+ "timeTotal": time*1000,
121+ "timeRemaining": time*1000,
122+ });
123+ }
124+ else if (type == "directDeploy")
125+ {
126+ this.queue.push({
127+ "id": this.nextID++,
128+ "player": cmpPlayer.GetPlayerID(),
129+ "unitTemplate": templateName,
130+ "count": count,
131+ "metadata": metadata,
132+ "resources": [],
133+ "population": 0,
134+ "productionStarted": false,
135+ "timeTotal": 1000,
136+ "timeRemaining": 1000,
137+ });
138+ }
139 }
140 else if (type == "technology")
141 {
142@@ -411,24 +477,6 @@
143 return Math.pow(batchSize, batchTimeModifier) * cmpPlayer.GetCheatTimeMultiplier();
144 };
145
146-ProductionQueue.prototype.OnOwnershipChanged = function(msg)
147-{
148- if (msg.from != -1)
149- {
150- // Unset flag that previous owner's training may be blocked
151- var cmpPlayer = QueryPlayerIDInterface(msg.from, IID_Player);
152- if (cmpPlayer && this.queue.length > 0)
153- cmpPlayer.UnBlockTraining();
154- }
155-
156- // Reset the production queue whenever the owner changes.
157- // (This should prevent players getting surprised when they capture
158- // an enemy building, and then loads of the enemy's civ's soldiers get
159- // created from it. Also it means we don't have to worry about
160- // updating the reserved pop slots.)
161- this.ResetQueue();
162-};
163-
164 ProductionQueue.prototype.OnDestroy = function()
165 {
166 // Reset the queue to refund any resources