-
Notifications
You must be signed in to change notification settings - Fork 47
/
a_bargain_is_struck.lua
943 lines (911 loc) · 41.8 KB
/
a_bargain_is_struck.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
-- _________ __ __
-- / _____// |_____________ _/ |______ ____ __ __ ______
-- \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
-- / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ \
-- /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-- \/ \/ \//_____/ \/
-- ______________________ ______________________
-- T H E W A R B E G I N S
-- Stratagus - A free fantasy real time strategy game engine
--
-- (c) Copyright 2014-2022 by Andrettin
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
--
if (LoadedGame == false) then
SetPlayerData(GetFactionPlayer("shinsplitter_clan"), "Allow", "unit-dwarven-smithy", "F")
SetPlayerData(GetFactionPlayer("shinsplitter_clan"), "Allow", "unit-dwarven-lumber-mill", "F")
SetPlayerData(GetFactionPlayer("shinsplitter_clan"), "Allow", "unit-dwarven-sentry-tower", "F")
SetPlayerData(GetFactionPlayer("shinsplitter_clan"), "Allow", "unit-dwarven-stronghold", "F")
end
-- A Bargain is Struck initial dialogue
-- based on the A Bargain is Struck scenario of the Sceptre of Fire campaign from Battle for Wesnoth
AddTrigger("a-bargain-is-struck-introduction",
function()
if (GameCycle == 0) then
return false
end
for i=0, (PlayerMax - 2) do
if (GetPlayerData(i, "RaceName") == "dwarf" and (GetPlayerData(i, "Name") == "Norlund Clan" or GetPlayerData(i, "Name") == "Shinsplitter Clan" or GetPlayerData(i, "Name") == "Knalga") and FindHero("rugnur", i) ~= nil and GetPlayerData(i, "UnitTypesCount", "unit-dwarven-town-hall") >= 1 and GetCivilizationExists("gnome") and GetNumRivals(i) >= 2 and not GetPlayerData(i, "IsEnemy", GetCivilizationPlayer("gnome")) and GetPlayerData(i, "UnitTypesCount", "unit-gnomish-caravan") < 1) then
player = i
-- this check is necessary to see if there is a viable raider player (so that the game doesn't crash if the only other dwarven clan are the Shorbear)
local loop = true
local loop_count = 0
local bandit_player
while (loop) do
bandit_player = SyncRand(GetNumPlayers())
if (bandit_player ~= player and GetPlayerData(bandit_player, "Name") ~= "Shorbear Clan" and GetPlayerData(bandit_player, "RaceName") == "dwarf") then
loop = false
end
loop_count = loop_count + 1
if (loop_count > 100) then
return false
end
end
return true
end
end
return false
end,
function()
local gnomish_monarch_player = GetCivilizationPlayer("gnome")
local rugnur = FindHero("rugnur")
local pypo_i = FindUnit("unit-gnomish-master-at-arms", gnomish_monarch_player)
unit = CreateUnit("unit-revealer", player, {GetPlayerData(gnomish_monarch_player, "StartPosX"), GetPlayerData(gnomish_monarch_player, "StartPosY")})
Event(
"",
"The land of Untersberg's banner bold\nComes not from its own land;\nIt comes from Dwarfdom, grim and old\nMade by a runesmith's hand.\n\nSo now I tell from whence it came -\nThe Fire-scepter great -\nAnd of the makers of the same,\nTheir tale I now relate...",
player,
{"~!Continue"},
{function(s)
Event(
"",
"Ay, the Scepter of Fire. The scepter has a long, glorious, and fearful history. But I am not here to tell you how the jewel within it was obtained by Pypo I. Nor will I tell the story of Rubezahl I, king of Untersberg by virtue of the Scepter.",
player,
{"~!Continue"},
{function(s)
Event(
"",
"I am here to tell you of its making. Of its crafting, deep in the caverns of dwarfdom. And of the dwarves who made it; for they were great, they were. They are counted among the greatest of the heroes of ancient Knalga.",
player,
{"~!Continue"},
{function(s)
Event(
"",
"Our story begins in a small border outpost in the southern hills of Knalga, with a young dwarf, named Rugnur, in charge of it. And with the gnomish king of Untersberg, Pypo I, riding up the road from Untersberg with an army behind him...",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Gnomes, halt! Who dares bring an army into the dwarven hills?",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"We come to make a bargain with you.",
player,
{"~!Listen to him", "~!Up axes! (Forego Quest)"},
{function(s)
Event(
rugnur,
"Well, state yer business and be done with it. And if we don't like what ye say, ye leave!",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"Have you heard of the Ruby of Fire?",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Aye... yer deceased king brought it from the west, right? Ye own it.",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"Correct. However, we have a problem with it.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"What sort of problem?",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"The stone is very atypical. To cut and insert it would require more skill than my best craftsmen have...",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"And what... ye want us to do this, cut the stone? And make an artifact of some kind?",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"I want you to craft it into a mighty artifact, that will embody the power of my will and be a symbol of the legitimacy of my rule.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Well... I think we can make a deal, but I'm not sure. I'll have to ask the tribal leaders.",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"If you are not authorized to make a deal, send out someone who is, and I will bargain with him.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"They would refuse to come. Ye must come into the caves, and go to the city in person, or send a representative.",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"I can always take my offer to another tribe more friendly to its potential patrons. You are not the only smiths in these lands!",
player,
{"~!Discuss his offer", "~!No deal (Forego Quest)"},
{function(s)
Event(
rugnur,
"Uh, no, wait! Let's talk business - how much will ye pay us to do this for ye?",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"Five thousand pieces of silver.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Ye said ye wanted a potent artifact, not a child's playtoy! So... twenty thousand, minimum. The crafting of this will take us many years, ye must pay us well.",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"Ten thousand.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Nothing below fifteen!",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"Then no deal. I'll gather my things and go to another dwarven clan now.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Fine then - ten thousand... now, what exactly do ye want us to make the stone into?",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"I want you to make it into a scepter, a scepter of fire.",
player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"I'll see what I can do. But I will need five thousand silver in advance, to pay for the materials.",
player,
{"~!Continue"},
{function(s)
Event(
pypo_i,
"Very well. I have the silver here, ready to ship, and I will send someone over with the stone itself. He will stay with you as you make the scepter, and make sure you are going to get it done on time. I expect it done before my reign as king is ended.",
player,
{"~!Continue"},
{function(s)
unit = CreateUnit("unit-gnomish-duelist", player, {GetPlayerData(gnomish_monarch_player, "StartPosX"), GetPlayerData(gnomish_monarch_player, "StartPosY")}) -- gnomish envoy who holds the ruby
SetUnitVariable(unit, "Active", false)
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
-- if human-controlled player is Shinsplitter Clan, then tell the caravans to move
OrderUnit(player, "unit-gnomish-duelist", {GetUnitVariable(unit,"PosX"), GetUnitVariable(unit,"PosY")}, 0, {47, 8}, 0, "move")
end
unit = CreateUnit("unit-gnomish-caravan", player, {GetPlayerData(gnomish_monarch_player, "StartPosX"), GetPlayerData(gnomish_monarch_player, "StartPosY")})
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
-- if human-controlled player is Shinsplitter Clan, then tell the caravans to move
OrderUnit(player, "unit-gnomish-caravan", {GetUnitVariable(unit,"PosX"), GetUnitVariable(unit,"PosY")}, 0, {47, 8}, 0, "move")
end
local transporter = unit
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnit("unit-gnomish-caravan", player, {GetPlayerData(gnomish_monarch_player, "StartPosX"), GetPlayerData(gnomish_monarch_player, "StartPosY")})
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
-- if human-controlled player is Shinsplitter Clan, then tell the caravans to move
OrderUnit(player, "unit-gnomish-caravan", {GetUnitVariable(unit,"PosX"), GetUnitVariable(unit,"PosY")}, 0, {47, 8}, 0, "move")
end
transporter = unit
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnit("unit-gnomish-caravan", player, {GetPlayerData(gnomish_monarch_player, "StartPosX"), GetPlayerData(gnomish_monarch_player, "StartPosY")})
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
-- if human-controlled player is Shinsplitter Clan, then tell the caravans to move
OrderUnit(player, "unit-gnomish-caravan", {GetUnitVariable(unit,"PosX"), GetUnitVariable(unit,"PosY")}, 0, {47, 8}, 0, "move")
end
transporter = unit
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnit("unit-gnomish-caravan", player, {GetPlayerData(gnomish_monarch_player, "StartPosX"), GetPlayerData(gnomish_monarch_player, "StartPosY")})
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
-- if human-controlled player is Shinsplitter Clan, then tell the caravans to move
OrderUnit(player, "unit-gnomish-caravan", {GetUnitVariable(unit,"PosX"), GetUnitVariable(unit,"PosY")}, 0, {47, 8}, 0, "move")
end
transporter = unit
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
unit = CreateUnitInTransporter("unit-gold-chest", PlayerNumNeutral, transporter)
if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
ChangeUnitsOwner({6, 65}, {6 + 1, 65 + 1}, gnomish_monarch_player, 0)
RemovePlayerObjective(player, "- Defeat your rivals")
end
SetDiplomacy(gnomish_monarch_player, "allied", player)
SetSharedVision(gnomish_monarch_player, true, player)
SetDiplomacy(player, "allied", gnomish_monarch_player)
SetSharedVision(player, true, gnomish_monarch_player)
AddPlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
AddPlayerObjective(player, "- Rugnur must survive")
AddPlayerObjective(player, "- The gnomish envoy must survive")
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end,
function(s)
SetDiplomacy(gnomish_monarch_player, "neutral", player)
SetDiplomacy(player, "neutral", gnomish_monarch_player)
KillUnitAt("unit-revealer", player, 1, {0, 0}, {MaxMapWidth, MaxMapHeight})
ActionDraw()
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end,
function(s)
SetSharedVision(gnomish_monarch_player, false, player)
SetSharedVision(player, false, gnomish_monarch_player)
SetDiplomacy(gnomish_monarch_player, "enemy", player)
SetDiplomacy(player, "enemy", gnomish_monarch_player)
SetPlayerData(GetFactionPlayer("Shinsplitter Clan"), "Type", PlayerNeutral)
KillUnitAt("unit-revealer", player, 1, {0, 0}, {MaxMapWidth, MaxMapHeight})
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
-- Follow-up of the A Bargain is Struck initial dialogue
AddTrigger("a-bargain-is-struck-introduction-2",
function()
if (GameCycle == 0) then
return false
end
for i=0, (PlayerMax - 2) do
if (PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")) then
player = i
return true
end
end
return false
end,
function()
local rugnur = FindHero("rugnur")
local gnomish_monarch_player = GetCivilizationPlayer("gnome")
local loop = true
local loop_count = 0
local bandit_player
while (loop) do
bandit_player = SyncRand(GetNumPlayers())
if (bandit_player ~= player and GetPlayerData(bandit_player, "Name") ~= "Shorbear Clan" and GetPlayerData(bandit_player, "RaceName") == "dwarf") then
loop = false
end
loop_count = loop_count + 1
if (loop_count > 100) then
return false
end
end
SavePreferences()
unit = CreateUnit("unit-revealer", player, {GetPlayerData(bandit_player, "StartPosX"), GetPlayerData(bandit_player, "StartPosY")})
local raider_leader = FindUnit("unit-dwarven-steelclad", GetFactionPlayer("Shinsplitter Clan"))
local event_player = player
if (GetThisPlayer() == bandit_player) then
event_player = bandit_player
end
Event(
"Gnomish Envoy",
"That's right. I'll be coming over along with the silver.",
event_player,
{"~!Continue"},
{function(s)
Event(
raider_leader,
"Hey! Ye can't do that - this road belongs to the Shinsplitter clan. We're not letting ye transport gold and jewels on it without paying a toll.",
event_player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"What are ye talking about?! This road has always been open to all.",
event_player,
{"~!Continue"},
{function(s)
Event(
raider_leader,
"Aye, we have allowed people to use it, but it is our road.",
event_player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Not true! This is Norlund land; if anything, it's our road!",
event_player,
{"~!Continue"},
{function(s)
Event(
raider_leader,
"Nevertheless, if ye try to move yer caravans here ye have to pay the toll, or face our wrath!",
event_player,
{"~!Continue"},
{function(s)
Event(
rugnur,
"Very well. I have no problem with slaying ye if ye stand in our way. I advise ye to leave the shipment alone, but not doing so is yer choice.",
event_player,
{"~!Continue"},
{function(s)
-- create bandits
local bandit_x = (GetPlayerData(gnomish_monarch_player, "StartPosX") + GetPlayerData(player, "StartPosX")) / 2
local bandit_y = (GetPlayerData(gnomish_monarch_player, "StartPosY") + GetPlayerData(player, "StartPosY")) / 2
SetDiplomacy(bandit_player, "enemy", gnomish_monarch_player)
SetDiplomacy(bandit_player, "enemy", player)
SetDiplomacy(gnomish_monarch_player, "enemy", bandit_player)
SetDiplomacy(player, "enemy", bandit_player)
local second_bandit_player = FindUnusedPlayerSlot()
SetPlayerData(second_bandit_player, "Type", PlayerComputer)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {(GetPlayerData(bandit_player, "StartPosX") + GetPlayerData(player, "StartPosX")) / 2, (GetPlayerData(bandit_player, "StartPosY") + GetPlayerData(player, "StartPosY")) / 2})
SetUnitVariable(unit, "Active", false)
if (GameSettings.Difficulty == DifficultyHard) then -- if difficulty is hard
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {(GetPlayerData(bandit_player, "StartPosX") + GetPlayerData(player, "StartPosX")) / 2, (GetPlayerData(bandit_player, "StartPosY") + GetPlayerData(player, "StartPosY")) / 2})
SetUnitVariable(unit, "Active", false)
elseif (GameSettings.Difficulty == DifficultyBrutal) then -- if difficulty is brutal
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {bandit_x, bandit_y})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {(GetPlayerData(bandit_player, "StartPosX") + GetPlayerData(player, "StartPosX")) / 2, (GetPlayerData(bandit_player, "StartPosY") + GetPlayerData(player, "StartPosY")) / 2})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {(GetPlayerData(bandit_player, "StartPosX") + GetPlayerData(player, "StartPosX")) / 2, (GetPlayerData(bandit_player, "StartPosY") + GetPlayerData(player, "StartPosY")) / 2})
SetUnitVariable(unit, "Active", false)
unit = CreateUnit("unit-dwarven-axefighter", second_bandit_player, {(GetPlayerData(bandit_player, "StartPosX") + GetPlayerData(player, "StartPosX")) / 2, (GetPlayerData(bandit_player, "StartPosY") + GetPlayerData(player, "StartPosY")) / 2})
SetUnitVariable(unit, "Active", false)
end
SetPlayerData(second_bandit_player, "Name", "Raiders")
SetDiplomacy(second_bandit_player, "neutral", gnomish_monarch_player)
SetDiplomacy(gnomish_monarch_player, "neutral", second_bandit_player)
SetDiplomacy(second_bandit_player, "enemy", player)
SetDiplomacy(player, "enemy", second_bandit_player)
SetDiplomacy(bandit_player, "allied", second_bandit_player)
SetDiplomacy(second_bandit_player, "allied", bandit_player)
KillUnitAt("unit-revealer", player, 2, {0, 0}, {MaxMapWidth, MaxMapHeight})
if (is_show_tips_enabled() and not IsReplayGame()) then
Tip("", "Your enemies in this scenario are more resourceful than you - it is better to quickly assemble troops to escort the caravans, as the enemy is likely to eventually overwhelm you.")
end
end}
)
end}
)
end}
)
end}
)
end}
)
end}
)
end},
"icon-gnomish-duelist"
)
return false
end
)
return false
end
)
-- The Gnomish Envoy arrives with the stone
AddTrigger("a-bargain-is-struck-gnomish-envoy-arrives",
function()
if (GameCycle == 0) then
return false
end
for i=0, (PlayerMax - 2) do
if (
PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
and GetPlayerData(i, "RaceName") == "dwarf"
and FindHero("rugnur", i) ~= nil
and (IfNearUnit(i, ">=", 1, "unit-gnomish-duelist", "unit-dwarven-town-hall") or IfNearUnit(i, ">=", 1, "unit-gnomish-duelist", "unit-dwarven-stronghold") or IfNearUnit(i, ">=", 1, "unit-gnomish-master-at-arms", "unit-dwarven-town-hall") or IfNearUnit(i, ">=", 1, "unit-gnomish-master-at-arms", "unit-dwarven-stronghold"))
and (IfNearUnit(i, ">=", 1, "unit-dwarven-town-hall", "unit-gnomish-duelist") or IfNearUnit(i, ">=", 1, "unit-dwarven-stronghold", "unit-gnomish-duelist") or IfNearUnit(i, ">=", 1, "unit-dwarven-town-hall", "unit-gnomish-master-at-arms") or IfNearUnit(i, ">=", 1, "unit-dwarven-stronghold", "unit-gnomish-master-at-arms"))
) then
player = i
return true
end
end
return false
end,
function()
local gnomish_envoy = FindUnit("unit-gnomish-duelist", GetFactionPlayer("Norlund Clan"))
if (gnomish_envoy == nil) then
gnomish_envoy = FindUnit("unit-gnomish-master-at-arms", GetFactionPlayer("Norlund Clan"))
end
if not (GetUnitVariable(gnomish_envoy, "Idle")) then
return true
end
Event(
"Gnomish Envoy",
"Here's the stone, for you dwarves! Now, if you'll excuse me, I think I'll be taking refuge here... I don't much like fighting.",
player,
{"~!Continue"},
{function(s)
RemoveUnit(gnomish_envoy)
local caravans_loaded = true -- are all caravans loaded?
local uncount = 0
uncount = GetUnits(GetFactionPlayer("Norlund Clan"))
for unit1 = 1,table.getn(uncount) do
if (GetUnitVariable(uncount[unit1], "Ident") == "unit-gnomish-caravan" and GetUnitVariable(uncount[unit1], "Transport") < 2) then -- only checks if the unit is transporting two things, not necessarily two chests, which isn't optimal
caravans_loaded = false
end
end
if (
(IfNearUnit(player, ">=", 4, "unit-gnomish-caravan", "unit-dwarven-town-hall") or IfNearUnit(player, ">=", 4, "unit-gnomish-caravan", "unit-dwarven-stronghold"))
and (IfNearUnit(player, ">=", 1, "unit-dwarven-town-hall", "unit-gnomish-caravan") or IfNearUnit(player, ">=", 1, "unit-dwarven-stronghold", "unit-gnomish-caravan"))
and caravans_loaded) then
Event(
FindUnit("unit-gnomish-master-at-arms", gnomish_monarch_player),
"All the silver is there too. Proceed with the task, Rugnur!",
player,
{"~!Continue"},
{function(s)
RemovePlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
if (GetThisPlayer() == GetFactionPlayer("Norlund Clan")) then
ActionVictory()
else
ActionDefeat()
end
if (GrandStrategy) then -- if is grand strategy, begin war between Norlund Clan and Shinsplitter Clan
ChangeFactionResource("dwarf", "norlund_clan", "copper", 10000) -- 5000 silver, and for our purposes silver is considered to be worth 200% of copper
end
end
if (player == GetThisPlayer()) then
SetQuestCompleted("a-bargain-is-struck", GameSettings.Difficulty)
end
end}
)
end
end},
"icon-gnomish-duelist"
)
return false
end
)
-- The last caravan arrives with the silver
AddTrigger("a-bargain-is-struck-caravans-arrived",
function()
if (GameCycle == 0) then
return false
end
for i=0, (PlayerMax - 2) do
if (
PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
and GetPlayerData(i, "RaceName") == "dwarf"
and FindHero("rugnur", i) ~= nil
and (IfNearUnit(i, ">=", 4, "unit-gnomish-caravan", "unit-dwarven-town-hall") or IfNearUnit(i, ">=", 4, "unit-gnomish-caravan", "unit-dwarven-stronghold"))
and (IfNearUnit(i, ">=", 1, "unit-dwarven-town-hall", "unit-gnomish-caravan") or IfNearUnit(i, ">=", 1, "unit-dwarven-stronghold", "unit-gnomish-caravan"))
) then
local caravans_loaded = true -- are all caravans loaded?
local uncount = 0
uncount = GetUnits(GetFactionPlayer("Norlund Clan"))
for unit1 = 1,table.getn(uncount) do
if (GetUnitVariable(uncount[unit1], "Ident") == "unit-gnomish-caravan" and GetUnitVariable(uncount[unit1], "Transport") < 2) then -- only checks if the unit is transporting two things, not necessarily two chests, which isn't optimal
caravans_loaded = false
end
end
if (caravans_loaded) then
player = i
return true
end
end
end
return false
end,
function()
local gnomish_envoy = FindUnit("unit-gnomish-duelist", GetFactionPlayer("Norlund Clan"))
if (gnomish_envoy == nil) then
gnomish_envoy = FindUnit("unit-gnomish-master-at-arms", GetFactionPlayer("Norlund Clan"))
end
if (GetUnitVariable(gnomish_envoy, "Removed") and GetUnitVariable(gnomish_envoy, "Container") == -1) then
Event(
FindHero("rugnur"),
"That's the last caravan! We will commence work immediately.",
player,
{"~!Continue"},
{function(s)
RemovePlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
if (GetThisPlayer() == GetFactionPlayer("Norlund Clan")) then
ActionVictory()
else
ActionDefeat()
end
if (GrandStrategy) then -- if is grand strategy, begin war between Norlund Clan and Shinsplitter Clan
ChangeFactionResource("dwarf", "norlund_clan", "copper", 10000) -- 5000 silver, and for our purposes silver is considered to be worth 200% of copper
end
end
if (player == GetThisPlayer()) then
SetQuestCompleted("a-bargain-is-struck", GameSettings.Difficulty)
end
end}
)
else
Event(
FindHero("rugnur"),
"We have all of the silver, now all we need is the stone.",
player,
{"~!Continue"},
{function(s)
end}
)
end
return false
end
)
-- This event makes the player complete the quest in the case that the caravans or the recruit arrive first but then are moved, and when the recruit or the caravans finally arrive the quest completion doesn't happen
AddTrigger("a-bargain-is-struck-quest-completion",
function()
if (GameCycle == 0) then
return false
end
local gnomish_envoy = FindUnit("unit-gnomish-duelist", GetFactionPlayer("Norlund Clan"))
if (gnomish_envoy == nil) then
gnomish_envoy = FindUnit("unit-gnomish-master-at-arms", GetFactionPlayer("Norlund Clan"))
end
for i=0, (PlayerMax - 2) do
-- added the SyncRand so that this trigger is unlikely to fire instead of the quest completion dialogue events
if (
(SyncRand(100) + 1) <= 10
and PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
and GetPlayerData(i, "RaceName") == "dwarf"
and FindHero("rugnur", i) ~= nil
and (IfNearUnit(i, ">=", 4, "unit-gnomish-caravan", "unit-dwarven-town-hall") or IfNearUnit(i, ">=", 4, "unit-gnomish-caravan", "unit-dwarven-stronghold"))
and (IfNearUnit(i, ">=", 1, "unit-dwarven-town-hall", "unit-gnomish-caravan") or IfNearUnit(i, ">=", 1, "unit-dwarven-stronghold", "unit-gnomish-caravan"))
and GetUnitVariable(gnomish_envoy, "Removed") and GetUnitVariable(gnomish_envoy, "Container") == -1
) then
local caravans_loaded = true -- are all caravans loaded?
local uncount = 0
uncount = GetUnits(GetFactionPlayer("Norlund Clan"))
for unit1 = 1,table.getn(uncount) do
if (GetUnitVariable(uncount[unit1], "Ident") == "unit-gnomish-caravan" and GetUnitVariable(uncount[unit1], "Transport") < 2) then -- only checks if the unit is transporting two things, not necessarily two chests, which isn't optimal
caravans_loaded = false
end
end
if (caravans_loaded) then
player = i
return true
end
end
end
return false
end,
function()
RemovePlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
if (GetThisPlayer() == GetFactionPlayer("Norlund Clan")) then
ActionVictory()
else
ActionDefeat()
end
if (GrandStrategy) then -- if is grand strategy, begin war between Norlund Clan and Shinsplitter Clan
ChangeFactionResource("dwarf", "norlund_clan", "copper", 10000) -- 5000 silver, and for our purposes silver is considered to be worth 200% of copper
end
end
if (player == GetThisPlayer()) then
SetQuestCompleted("a-bargain-is-struck", GameSettings.Difficulty)
end
return false
end
)
-- If a caravan has been destroyed, the A Bargain is Struck quest fails
AddTrigger("a-bargain-is-struck-caravan-destroyed",
function()
if (GameCycle == 0) then
return false
end
for i=0, (PlayerMax - 2) do
if (PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall") and GetPlayerData(i, "UnitTypesCount", "unit-gnomish-caravan") < 4) then
player = i
return true
end
end
return false
end,
function()
local event_player = player
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
event_player = GetFactionPlayer("Shinsplitter Clan")
end
Event(
FindUnit("unit-gnomish-master-at-arms", gnomish_monarch_player),
"You just let a caravan, with ~<my~> money loaded in it, get captured! If I can't trust you to keep my property secure, the deal's off.",
event_player,
{"~!Continue"},
{function(s)
RemovePlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
if (GetThisPlayer() == player) then
ActionDefeat()
end
end
end}
)
return false
end
)
-- If a caravan's cargo has been dropped, the A Bargain is Struck quest fails
AddTrigger("a-bargain-is-struck-caravan-cargo-dropped",
function()
if (GameCycle == 0) then
return false
end
for i=0, (PlayerMax - 2) do
if (PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")) then
local caravans_loaded = true -- are all caravans loaded?
local uncount = 0
uncount = GetUnits(GetFactionPlayer("Norlund Clan"))
for unit1 = 1,table.getn(uncount) do
if (GetUnitVariable(uncount[unit1], "Ident") == "unit-gnomish-caravan" and GetUnitVariable(uncount[unit1], "Transport") < 2) then -- only checks if the unit is transporting two things, not necessarily two chests, which isn't optimal
caravans_loaded = false
end
end
if (caravans_loaded == false) then
player = i
return true
end
end
end
return false
end,
function()
local event_player = player
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
event_player = GetFactionPlayer("Shinsplitter Clan")
end
Event(
FindUnit("unit-gnomish-master-at-arms", gnomish_monarch_player),
"Rugnur, you fool! You just let a caravan's cargo fall away! If I can't trust you to keep my property secure, the deal's off.",
event_player,
{"~!Continue"},
{function(s)
RemovePlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
if (GetThisPlayer() == player) then
ActionDefeat()
end
end
end}
)
return false
end
)
-- If all caravans have been destroyed, then the raiders win, if they are human-controlled
AddTrigger("a-bargain-is-struck-raiders-victory",
function()
if (GameCycle == 0) then
return false
end
if (GetPlayerData(GetFactionPlayer("Norlund Clan"), "UnitTypesCount", "unit-gnomish-caravan") == 0) then
return true
end
return false
end,
function()
if (GetThisPlayer() == GetFactionPlayer("Shinsplitter Clan")) then
if (GrandStrategy) then
ChangeFactionResource("dwarf", "shinsplitter_clan", "copper", 10000) -- give the funds for Shinsplitter Clan if they managed to successfully stop the shipment
end
ActionVictory()
end
return false
end
)
-- If Rugnur dies the quest will fail
AddTrigger("a-bargain-is-struck-rugnur-dies",
function()
if (GameCycle == 0) then
return false
end
if (PlayerHasObjective(GetFactionPlayer("Norlund Clan"), "- Rugnur must survive") and FindHero("rugnur", GetFactionPlayer("Norlund Clan")) == nil) then
player = GetFactionPlayer("Norlund Clan")
return true
end
return false
end,
function()
if (GetFactionPlayer("Norlund Clan") == GetThisPlayer()) then
ActionDefeat()
if (GrandStrategy) then
if (PlayerHasObjective(GetThisPlayer(), "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")) then
ChangeFactionResource("dwarf", "shinsplitter_clan", "copper", 10000) -- give the funds for Shinsplitter Clan if they managed to successfully stop the shipment
end
if (PlayerHasObjective(GetThisPlayer(), "- Have one unit standing on each glyph at the same time")) then
ChangeFactionResource("dwarf", "norlund_clan", "copper", -10000)
ChangeFactionResource("dwarf", "shinsplitter_clan", "copper", 10000)
end
end
end
return false
end
)
-- If the Gnomish Envoy dies, any quests of the Scepter of Fire campaign currently being pursued fail
AddTrigger("a-bargain-is-struck-gnomish-envoy-dies",
function()
if (GameCycle == 0) then
return false
end
if (PlayerHasObjective(GetThisPlayer(), "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall") and GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-gnomish-duelist") < 1 and GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-gnomish-master-at-arms") < 1) then
player = GetThisPlayer()
return true
end
return false
end,
function()
ActionDefeat()
if (GrandStrategy and PlayerHasObjective(GetThisPlayer(), "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")) then
ChangeFactionResource("dwarf", "shinsplitter_clan", "copper", 10000) -- give the funds for Shinsplitter Clan if they managed to successfully stop the shipment
end
return false
end
)
-- If the gnomish monarch dies, the first quest of the Scepter of Fire campaign fails
--AddTrigger("a-bargain-is-struck-gnomish-monarch-dies",
-- function()
-- if (GameCycle == 0) then
-- return false
-- end
-- for i=0, (PlayerMax - 2) do
-- -- maybe could check here if the gnomish player has a gnomish recruit with level 3 instead (although perhaps it could be bad for performance)?
-- if (PlayerHasObjective(i, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall") and GetPlayerData(GetCivilizationPlayer("gnome"), "UnitTypesCount", "unit-gnomish-duelist") < 1) then
-- player = i
-- return true
-- end
-- end
-- return false
-- end,
-- function()
-- RemovePlayerObjective(player, "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")
-- if (CMap:get():get_info():get_name() == "Chaincolt Foothills") then
-- ActionDefeat()
-- if (GrandStrategy and PlayerHasObjective(GetThisPlayer(), "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall")) then
-- ChangeFactionResource("dwarf", "shinsplitter_clan", "copper", 10000) -- give the funds for Shinsplitter Clan if they managed to successfully stop the shipment
-- end
-- end
-- return false
-- end
--)
-- if the raiders have been destroyed, grant the corresponding achievement
AddTrigger("a-bargain-is-struck-safe-passage-achievement",
function()
if (GameCycle == 0) then
return false
end
if (GetFactionPlayer("Norlund Clan") == GetThisPlayer() and PlayerHasObjective(GetThisPlayer(), "- Bring the loaded Gnomish caravans and the envoy to your Mead Hall") and GetNumRivals(GetThisPlayer()) == 0 and GameSettings.Difficulty >= GetAchievementData("safe-passage", "Difficulty")) then
return true
end
return false
end,
function()
SetAchievementObtained("safe-passage")
return false
end
)