1 | ///////////////////////////////////////////////////////////////////////////////
|
---|
2 | // Function defenitions //
|
---|
3 | ///////////////////////////////////////////////////////////////////////////////
|
---|
4 |
|
---|
5 | // These actions control the tutorials in which the player has no interaction with.
|
---|
6 | Trigger.prototype.WelcomeMessage = function(data)
|
---|
7 | {
|
---|
8 | var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
|
---|
9 | if (this.state != "start")
|
---|
10 | return;
|
---|
11 | cmpGUIInterface.PushNotification({
|
---|
12 | playrers: [1],
|
---|
13 | markForTranslation("Welcome to the basic tutorial of the 0 A.D.!"),
|
---|
14 | translateMessage: true
|
---|
15 | });
|
---|
16 | this.DoAfterDelay(3000, "IntroductionMessage", {});
|
---|
17 | };
|
---|
18 |
|
---|
19 | Trigger.prototype.IntroductionMessage = function(data)
|
---|
20 | {
|
---|
21 | if (this.state != "start")
|
---|
22 | return;
|
---|
23 | cmpGUIInterface.PushNotification({
|
---|
24 | playrers: [1],
|
---|
25 | markForTranslation("In this tutorial you will learn the basics of the gameplay of 0 A.D."),
|
---|
26 | translateMessage: true
|
---|
27 | });
|
---|
28 | this.DoAfterDelay(6000, "CameraMovementTutorial1", {});
|
---|
29 | };
|
---|
30 |
|
---|
31 | Trigger.prototype.CameraMovementTutorial1 = function(data)
|
---|
32 | {
|
---|
33 | if (this.state != "start")
|
---|
34 | return;
|
---|
35 | cmpGUIInterface.PushNotification({
|
---|
36 | playrers: [1],
|
---|
37 | markForTranslation("First, we try the camera movements. To move your camera, move the mouse pointer to the edge of the screen."),
|
---|
38 | translateMessage: true
|
---|
39 | });
|
---|
40 | this.DoAfterDelay(8000, "CameraMovementTutorial2", {});
|
---|
41 | };
|
---|
42 |
|
---|
43 | Trigger.prototype.CameraMovementTutorial2 = function(data)
|
---|
44 | {
|
---|
45 | if (this.state != "start")
|
---|
46 | return;
|
---|
47 | cmpGUIInterface.PushNotification({
|
---|
48 | playrers: [1],
|
---|
49 | markForTranslation("You can also move the camera using W,A,S,D or arrow keys on the keyboard, or by holding the middle mouse button and moving it."),
|
---|
50 | translateMessage: true
|
---|
51 | });
|
---|
52 | this.DoAfterDelay(15000, "CameraMovementTutorial3", {});
|
---|
53 | };
|
---|
54 |
|
---|
55 | Trigger.prototype.CameraMovementTutorial3 = function(data)
|
---|
56 | {
|
---|
57 | if (this.state != "start")
|
---|
58 | return;
|
---|
59 | cmpGUIInterface.PushNotification({
|
---|
60 | playrers: [1],
|
---|
61 | markForTranslation("To rotate the camera, hold Ctrl and one of the arrow keys."),
|
---|
62 | translateMessage: true
|
---|
63 | });
|
---|
64 | this.DoAfterDelay(7000, "CameraMovementTutorial4", {});
|
---|
65 | };
|
---|
66 |
|
---|
67 | Trigger.prototype.CameraMovementTutorial4 = function(data)
|
---|
68 | {
|
---|
69 | if (this.state != "start")
|
---|
70 | return;
|
---|
71 | cmpGUIInterface.PushNotification({
|
---|
72 | playrers: [1],
|
---|
73 | markForTranslation("To zoom, use the mouse scroll or + and - keys on the keyboard."),
|
---|
74 | translateMessage: true
|
---|
75 | });
|
---|
76 | this.DoAfterDelay(7000, "IntroductionToUnits", {});
|
---|
77 | };
|
---|
78 |
|
---|
79 | Trigger.prototype.IntroductionToUnits = function(data)
|
---|
80 | {
|
---|
81 | if (this.state != "start")
|
---|
82 | return;
|
---|
83 | cmpGUIInterface.PushNotification({
|
---|
84 | playrers: [1],
|
---|
85 | markForTranslation("Now it is time to work with units. Move the mouse pointer on one of the units present in the screen, and left-click to select it. Then, right-click on an open part of the terrain."),
|
---|
86 | translateMessage: true
|
---|
87 | });
|
---|
88 | this.state = "movingTutorial1";
|
---|
89 | this.EnableTrigger("OnInterval", "MovingUnitsTutorial");
|
---|
90 | this.EnableTrigger("OnPlayerCommand", "HandleOrders");
|
---|
91 | };
|
---|
92 |
|
---|
93 | Trigger.prototype.IntroductionToResources = function(data)
|
---|
94 | {
|
---|
95 | if (this.state != "gatheringFruit")
|
---|
96 | return;
|
---|
97 | cmpGUIInterface.PushNotification({
|
---|
98 | playrers: [1],
|
---|
99 | markForTranslation("Resource gathering plays a central role in 0 A.D.. There are four resources found in the game. Food, wood, stone and metal. You can find your current stockpile in the upper left section of the screen."),
|
---|
100 | translateMessage: true
|
---|
101 | });
|
---|
102 | this.DoAfterDelay(15000, "MoreDescriptionAboutResources", {});
|
---|
103 | };
|
---|
104 |
|
---|
105 | Trigger.prototype.MoreDescriptionAboutResources = function(data)
|
---|
106 | {
|
---|
107 | if (this.state != "gatheringFruit")
|
---|
108 | return;
|
---|
109 | cmpGUIInterface.PushNotification({
|
---|
110 | playrers: [1],
|
---|
111 | markForTranslation("Resources are required to train units, build structures and research technologies."),
|
---|
112 | translateMessage: true
|
---|
113 | });
|
---|
114 | this.EnableTrigger("OnInterval", "TutorialOnGatheringFood");
|
---|
115 | };
|
---|
116 |
|
---|
117 | // These actions remind the players of what they should do.
|
---|
118 | Trigger.prototype.MovingUnitsTutorial = function(data)
|
---|
119 | {
|
---|
120 | if (this.state != "movingTutorial1")
|
---|
121 | return;
|
---|
122 | cmpGUIInterface.PushNotification({
|
---|
123 | playrers: [1],
|
---|
124 | markForTranslation("Select a unit by left clicking on it, and then, right-click on an open part of the terrain."),
|
---|
125 | translateMessage: true
|
---|
126 | });
|
---|
127 | };
|
---|
128 |
|
---|
129 | Trigger.prototype.MovingAGroupOfUnitsTutorial = function(data)
|
---|
130 | {
|
---|
131 | if (this.state != "movingTutorial2")
|
---|
132 | return;
|
---|
133 | cmpGUIInterface.PushNotification({
|
---|
134 | playrers: [1],
|
---|
135 | markForTranslation("Hold the left button of the mouse and drag it to select a group of units. Then, order them to move."),
|
---|
136 | translateMessage: true
|
---|
137 | });
|
---|
138 | };
|
---|
139 |
|
---|
140 | Trigger.prototype.TutorialOnGatheringFood = function(data)
|
---|
141 | {
|
---|
142 | if (this.state != "gatheringFruit")
|
---|
143 | return;
|
---|
144 | cmpGUIInterface.PushNotification({
|
---|
145 | playrers: [1],
|
---|
146 | markForTranslation("Food is gathered from farms, fruit trees and bushes, animals, fishes and farms. Select some of your units and right-click on the berry bushes in the east to gather food."),
|
---|
147 | translateMessage: true
|
---|
148 | });
|
---|
149 | };
|
---|
150 |
|
---|
151 | Trigger.prototype.TutorialOnGatheringWood = function(data)
|
---|
152 | {
|
---|
153 | if (this.state != "gatheringWood")
|
---|
154 | return;
|
---|
155 | cmpGUIInterface.PushNotification({
|
---|
156 | playrers: [1],
|
---|
157 | markForTranslation("Wood is gathered from trees. Select some of your units and right-click on a tree to gather wood."),
|
---|
158 | translateMessage: true
|
---|
159 | });
|
---|
160 | };
|
---|
161 |
|
---|
162 | Trigger.prototype.TutorialOnGatheringStone = function(data)
|
---|
163 | {
|
---|
164 | if (this.state != "gatheringStone")
|
---|
165 | return;
|
---|
166 | cmpGUIInterface.PushNotification({
|
---|
167 | playrers: [1],
|
---|
168 | markForTranslation("Stone is gathered from stone quarries. Select some of your units and right-click on the quarry in the south of your town to gather stone."),
|
---|
169 | translateMessage: true
|
---|
170 | });
|
---|
171 | };
|
---|
172 |
|
---|
173 | Trigger.prototype.TutorialOnGatheringMetal = function(data)
|
---|
174 | {
|
---|
175 | if (this.state != "gatheringMetal")
|
---|
176 | return;
|
---|
177 | cmpGUIInterface.PushNotification({
|
---|
178 | playrers: [1],
|
---|
179 | markForTranslation("Metal is gathered from metal ores. Select some of your units and right-click on the rock in the north-east of your town to gather metal."),
|
---|
180 | translateMessage: true
|
---|
181 | });
|
---|
182 | };
|
---|
183 |
|
---|
184 | Trigger.prototype.TutorialOnExploration = function(data)
|
---|
185 | {
|
---|
186 | if (this.state != "goToTriggerPoint")
|
---|
187 | return;
|
---|
188 | cmpGUIInterface.PushNotification({
|
---|
189 | playrers: [1],
|
---|
190 | markForTranslation("Notice that you can only see the immidiate surroundings of you town. To see further, select your rider and order him to move along the south-eastern road into the black area.")),
|
---|
191 | translateMessage: true
|
---|
192 | });
|
---|
193 | };
|
---|
194 |
|
---|
195 | Trigger.prototype.TutorialOnGatheringTreasure = function(data)
|
---|
196 | {
|
---|
197 | if (this.state != "gatheringTreasure")
|
---|
198 | return;
|
---|
199 | cmpGUIInterface.PushNotification({
|
---|
200 | playrers: [1],
|
---|
201 | markForTranslation("Order your rider to gather the treasures. To do so, select your rider and right-click on one of the treasures near the road.")),
|
---|
202 | translateMessage: true
|
---|
203 | });
|
---|
204 | };
|
---|
205 |
|
---|
206 | // Thse actions set the next stage of the tutorial after the player has successfully done the previous ones
|
---|
207 |
|
---|
208 | Trigger.prototype.HandleOrders = function(data)
|
---|
209 | {
|
---|
210 | if (data.cmd.type == "walk")
|
---|
211 | {
|
---|
212 | if (data.cmd.entities.length == 1)
|
---|
213 | this.PlayerMovedAUnit(data);
|
---|
214 | else if (data.cmd.entities.length > 1)
|
---|
215 | this.PlayerMovedMultipleUnits(data);
|
---|
216 | }
|
---|
217 | else if (data.cmd.type == "gather")
|
---|
218 | {
|
---|
219 | var type = TriggerHelper.GetResourceType(data.cmd.target);
|
---|
220 | if (type === undefined)
|
---|
221 | return;
|
---|
222 | else if (type.specific == "fruit")
|
---|
223 | this.UnitOrderedToGatherFruit(data);
|
---|
224 | else if (type.generic == "wood")
|
---|
225 | this.UnitOrderedToGatherWood(data);
|
---|
226 | else if (type.generic == "stone")
|
---|
227 | this.UnitOrderedToGatherStone(data);
|
---|
228 | else if (type.generic == "metal")
|
---|
229 | this.UnitOrderedToGatherMetal(data);
|
---|
230 | else if (type.generic == "treasure")
|
---|
231 | this.UnitOrderedToGatherTreasure(data);
|
---|
232 | }
|
---|
233 | };
|
---|
234 |
|
---|
235 | // This one is called when the player moves a unit.
|
---|
236 | Trigger.prototype.PlayerMovedAUnit = function(data)
|
---|
237 | {
|
---|
238 | if (this.state != "movingTutorial1")
|
---|
239 | return;
|
---|
240 | this.state = "movingTutorial2";
|
---|
241 | this.DisableTrigger("OnInterval", "MovingUnitsTutorial");
|
---|
242 | cmpGUIInterface.PushNotification({
|
---|
243 | playrers: [1],
|
---|
244 | markForTranslation("Good. You can also select a group of units by holding the left mouse button and dragging it. Select a group of units and order them to move.")),
|
---|
245 | translateMessage: true
|
---|
246 | });
|
---|
247 | this.EnableTrigger("OnInterval", "MovingAGroupOfUnitsTutorial");
|
---|
248 | };
|
---|
249 |
|
---|
250 | Trigger.prototype.PlayerMovedMultipleUnits = function(data)
|
---|
251 | {
|
---|
252 | if (this.state != "movingTutorial2")
|
---|
253 | return;
|
---|
254 | this.state = "gatheringFruit";
|
---|
255 | this.DisableTrigger("OnInterval", "MovingAGroupOfUnitsTutorial");
|
---|
256 | cmpGUIInterface.PushNotification({
|
---|
257 | playrers: [1],
|
---|
258 | markForTranslation("Very Good.")),
|
---|
259 | translateMessage: true
|
---|
260 | });
|
---|
261 | this.DoAfterDelay(6000, "IntroductionToResources", {});
|
---|
262 | };
|
---|
263 |
|
---|
264 | // This one is called when the player orders a unit to gather from fruit bushes
|
---|
265 | Trigger.prototype.UnitOrderedToGatherFruit = function(data)
|
---|
266 | {
|
---|
267 | if (this.state != "gatheringFruit")
|
---|
268 | return;
|
---|
269 | this.state = "gatheringWood";
|
---|
270 | cmpGUIInterface.PushNotification({
|
---|
271 | playrers: [1],
|
---|
272 | markForTranslation("Excelent. Now your units will move and gather food from those bushes.")),
|
---|
273 | translateMessage: true
|
---|
274 | });
|
---|
275 | this.DisableTrigger("OnInterval", "TutorialOnGatheringFood");
|
---|
276 | this.EnableTrigger("OnInterval", "TutorialOnGatheringWood");
|
---|
277 | };
|
---|
278 |
|
---|
279 | // This one is called when the player orders a unit to gather from trees
|
---|
280 | Trigger.prototype.UnitOrderedToGatherWood = function(data)
|
---|
281 | {
|
---|
282 | if (this.state != "gatheringWood")
|
---|
283 | return;
|
---|
284 | this.state = "gatheringStone";
|
---|
285 | cmpGUIInterface.PushNotification({
|
---|
286 | playrers: [1],
|
---|
287 | markForTranslation("Perfect. Now your units will move and gather wood from the trees.")),
|
---|
288 | translateMessage: true
|
---|
289 | });
|
---|
290 | this.DisableTrigger("OnInterval", "TutorialOnGatheringWood");
|
---|
291 | this.EnableTrigger("OnInterval", "TutorialOnGatheringStone");
|
---|
292 | };
|
---|
293 |
|
---|
294 | // This one is called when the player orders a unit to gather from stone quarries
|
---|
295 | Trigger.prototype.UnitOrderedToGatherStone = function(data)
|
---|
296 | {
|
---|
297 | if (this.state != "gatheringStone")
|
---|
298 | return;
|
---|
299 | this.state = "gatheringMetal";
|
---|
300 | cmpGUIInterface.PushNotification({
|
---|
301 | playrers: [1],
|
---|
302 | markForTranslation("Good. Now your units will move and gather stone from the quarry.")),
|
---|
303 | translateMessage: true
|
---|
304 | });
|
---|
305 | this.DisableTrigger("OnInterval", "TutorialOnGatheringStone");
|
---|
306 | this.EnableTrigger("OnInterval", "TutorialOnGatheringMetal");
|
---|
307 | };
|
---|
308 |
|
---|
309 | // This one is called when the player orders a unit to gather from metal mines
|
---|
310 | Trigger.prototype.UnitOrderedToGatherMetal = function(data)
|
---|
311 | {
|
---|
312 | if (this.state != "gatheringMetal")
|
---|
313 | return;
|
---|
314 | this.state = "goToTriggerPoint";
|
---|
315 | cmpGUIInterface.PushNotification({
|
---|
316 | playrers: [1],
|
---|
317 | markForTranslation("Very Good. Now your units will move and gather metal from the ore.")),
|
---|
318 | translateMessage: true
|
---|
319 | });
|
---|
320 | this.DisableTrigger("OnInterval", "TutorialOnGatheringMetal");
|
---|
321 |
|
---|
322 | // Spawn a cavalry unit from trigger point B (near the player's CC)
|
---|
323 | TriggerHelper.SpawnUnitsFromTriggerPoints("B", "skirmish/units/default_cavalry", 1, 1)
|
---|
324 | this.EnableTrigger("OnInterval", "TutorialOnExploration");
|
---|
325 | this.EnableTrigger("OnRange", "StartTreasureTutorial");
|
---|
326 | };
|
---|
327 |
|
---|
328 | // This one is called when a unit gets near the trigger entity in the south-east
|
---|
329 | Trigger.prototype.StartTreasureTutorial = function(data)
|
---|
330 | {
|
---|
331 | if (this.state != "goToTriggerPoint")
|
---|
332 | return;
|
---|
333 | this.state = "gatheringTreasure";
|
---|
334 | cmpGUIInterface.PushNotification({
|
---|
335 | playrers: [1],
|
---|
336 | markForTranslation("You have found some treasures. Treasures give large ammount of their representing resources instantly. Order your rider to gather the treasures.")),
|
---|
337 | translateMessage: true
|
---|
338 | });
|
---|
339 | this.DisableTrigger("OnInterval", "TutorialOnExploration");
|
---|
340 | this.DisableTrigger("OnRange", "StartTreasureTutorial");
|
---|
341 | this.EnableTrigger("OnInterval", "TutorialOnGatheringTreasure");
|
---|
342 | };
|
---|
343 |
|
---|
344 | // This one is called when the player orders a unit to gather from treasures
|
---|
345 | Trigger.prototype.UnitOrderedToGatherTreasure = function(data)
|
---|
346 | {
|
---|
347 | if (this.state != "gatheringTreasure")
|
---|
348 | return;
|
---|
349 | this.state = "complete";
|
---|
350 | cmpGUIInterface.PushNotification({
|
---|
351 | playrers: [1],
|
---|
352 | markForTranslation("Outstanding. This tutorial is now done.")),
|
---|
353 | translateMessage: true
|
---|
354 | });
|
---|
355 | this.DisableTrigger("OnInterval", "TutorialOnGatheringTreasure");
|
---|
356 | this. gatheringTreasureCompleted = true;
|
---|
357 | this.DoAfterDelay(4000, "Victory", {});
|
---|
358 | };
|
---|
359 |
|
---|
360 | Trigger.prototype.Victory = function(data)
|
---|
361 | {
|
---|
362 | TriggerHelper.SetPlayerWon(1);
|
---|
363 | };
|
---|
364 |
|
---|
365 | ///////////////////////////////////////////////////////////////////////////////
|
---|
366 | // Startup Actions //
|
---|
367 | ///////////////////////////////////////////////////////////////////////////////
|
---|
368 |
|
---|
369 | // This function is run in the start of the game. We should initialize everything here.
|
---|
370 | Trigger.prototype.InitGame = function(data)
|
---|
371 | {
|
---|
372 | // Our trigger variables should be defined here or they will be lost
|
---|
373 | // after a save.
|
---|
374 | // This map will use some states, to know in which part of the tutorial it is
|
---|
375 | // possible states:
|
---|
376 | //[ start, movingTutorial1, movingTutorial2, gatheringFruit, gatheringWood, gatheringStone, gatheringMetal, goToTriggerPoint,gatheringTreasure, complete]
|
---|
377 | this.state = "start";
|
---|
378 |
|
---|
379 | // Start the first tutorial after 2 seconds.
|
---|
380 | this.DoAfterDelay(2000, "WelcomeMessage", {});
|
---|
381 |
|
---|
382 | ///////////////////////////////////////////////////////////////////////////
|
---|
383 | // Register Triggers //
|
---|
384 | ///////////////////////////////////////////////////////////////////////////
|
---|
385 |
|
---|
386 | // For a trigger to work, actions should be bound to an event.
|
---|
387 | var timerData = {"enabled": false, "delay": 10000, "interval": 12000}
|
---|
388 | this.RegisterTrigger("OnInterval", "MovingUnitsTutorial", timerData);
|
---|
389 | timerData.interval = 10000;
|
---|
390 | this.RegisterTrigger("OnInterval", "MovingAGroupOfUnitsTutorial", timerData);
|
---|
391 | timerData.delay = 5000
|
---|
392 | this.RegisterTrigger("OnInterval", "TutorialOnGatheringFood", timerData);
|
---|
393 | this.RegisterTrigger("OnInterval", "TutorialOnGatheringWood", timerData);
|
---|
394 | this.RegisterTrigger("OnInterval", "TutorialOnGatheringStone", timerData);
|
---|
395 | this.RegisterTrigger("OnInterval", "TutorialOnGatheringMetal", timerData);
|
---|
396 | this.RegisterTrigger("OnInterval", "TutorialOnExploration", timerData);
|
---|
397 | this.RegisterTrigger("OnInterval", "TutorialOnGatheringTreasure", timerData);
|
---|
398 |
|
---|
399 | // the query data to be used for the following range query
|
---|
400 | var queryData = {
|
---|
401 | "entities": this.GetTriggerPoints("A"), // source of the range trigger (the trigger entity A on this map)
|
---|
402 | "maxRange": 60, // maximum range
|
---|
403 | "players": [1], // only accept results from player 1
|
---|
404 | "requiredComponent": IID_UnitAI, // require the results to implement the UnitAI
|
---|
405 | "enabled": false, // disabled for now
|
---|
406 | }
|
---|
407 | // Range triggers are run when a unit enters or leaves the circle around the source
|
---|
408 | this.RegisterTrigger("OnRange", "StartTreasureTutorial", queryData);
|
---|
409 |
|
---|
410 |
|
---|
411 | // Normal triggers. The first parameter is the "event". The second one is the action
|
---|
412 | // By default, the trigger is disabled
|
---|
413 | this.RegisterTrigger("OnPlayerCommand", "HandleOrders");
|
---|
414 | };
|
---|
415 |
|
---|