-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcommon.j
25304 lines (19070 loc) · 744 KB
/
common.j
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
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//============================================================================
// Native types. All native functions take extended handle types when
// possible to help prevent passing bad values to native functions
//
/**
@patch 1.24a
*/
type agent extends handle // all reference counted objects
/**
Currently useless, although triggers return an event reference when you register
a new trigger-event, there are no useful functions.
You cannot destroy an event object either (technically a leak).
The only functions that take event are: `SaveTriggerEventHandle` and
`SaveTriggerEventHandleBJ`.
@patch 1.00
*/
type event extends agent // a reference to an event registration
/**
@patch 1.00
*/
type player extends agent // a single player reference
/**
A widget is an "interactive game object" with HP, possibly an inventory etc.
Types `unit`, `destructable`, `item` extend from widget.
Widget is the parent type and unit etc. are the descendant types (children).
Therefore all API functions that accept `widget` as a type, will also work with
any of the children types.
However if doesn't work the other way around, then you need to explicitly cast the type by pushing it through a hashtable, this is called "downcasting":
1. Put the widget object in a hashtable
2. Retrieve it as unit/destructable/item - needed since 1.24b,
[source](https://web.archive.org/web/20100118203210/http://wiki.thehelper.net/wc3/jass/common.j/Widget_API)
**Example (Lua)**:
```{.lua}
hasht = InitHashtable() -- for type-casting
SaveWidgetHandle(hasht, 1, 1, widgetHandle) -- put as widget
itemHandle = LoadItemHandle(hasht, 1, 1) -- retrieve as item
```
See `TriggerRegisterDeathEvent` for a full practical example.
@patch 1.00
*/
type widget extends agent // an interactive game object with life
/**
@patch 1.00
*/
type unit extends widget // a single unit reference
/**
@patch 1.00
*/
type destructable extends widget
/**
@patch 1.00
*/
type item extends widget
/**
@patch 1.07
*/
type ability extends agent
/**
@patch 1.07
*/
type buff extends ability
/**
@patch 1.00
*/
type force extends agent
/**
@patch 1.00
*/
type group extends agent
/**
@patch 1.00
*/
type trigger extends agent
/**
@patch 1.00
*/
type triggercondition extends agent
/**
@patch 1.00
*/
type triggeraction extends handle
/**
@patch 1.00
*/
type timer extends agent
/**
@patch 1.00
*/
type location extends agent
/**
@patch 1.00
*/
type region extends agent
/**
@patch 1.00
*/
type rect extends agent
/**
@patch 1.00
*/
type boolexpr extends agent
/**
@patch 1.00
*/
type sound extends agent
/**
@patch 1.00
*/
type conditionfunc extends boolexpr
/**
@patch 1.00
*/
type filterfunc extends boolexpr
/**
@patch 1.00
*/
type unitpool extends handle
/**
@patch 1.00
*/
type itempool extends handle
/**
@patch 1.00
*/
type race extends handle
/**
@patch 1.00
*/
type alliancetype extends handle
/**
@patch 1.00
*/
type racepreference extends handle
/**
@patch 1.00
*/
type gamestate extends handle
/**
@patch 1.00
*/
type igamestate extends gamestate
/**
@patch 1.00
*/
type fgamestate extends gamestate
/**
@patch 1.00
*/
type playerstate extends handle
/**
@patch 1.13
*/
type playerscore extends handle
/**
@patch 1.00
*/
type playergameresult extends handle
/**
@patch 1.00
*/
type unitstate extends handle
/**
@patch 1.07
*/
type aidifficulty extends handle
/**
@patch 1.00
*/
type eventid extends handle
/**
@patch 1.00
*/
type gameevent extends eventid
/**
@patch 1.00
*/
type playerevent extends eventid
/**
Events of this type are similar to `unitevent` but are limited to the specified player.
This can be useful to reduce the amount of triggered events, because the "condition" check
will be handled within the game rather than your code.
@note See: `TriggerRegisterPlayerUnitEvent`,
or BJ `TriggerRegisterAnyUnitEventBJ`, `TriggerRegisterPlayerUnitEventSimple` to register for this event.
@patch 1.00
*/
type playerunitevent extends eventid
/**
@note See: `TriggerRegisterUnitEvent`, `TriggerRegisterFilterUnitEvent` to register for this event.
@patch 1.00
*/
type unitevent extends eventid
/**
@patch 1.00
*/
type limitop extends eventid
/**
Currently useless, there are no functions that take `widgetevent`.
@patch 1.00
*/
type widgetevent extends eventid
/**
@patch 1.00
*/
type dialogevent extends eventid
/**
@patch 1.00
*/
type unittype extends handle
/**
Represents a game speed option at which the map can run. There are five
predefined settings, but only SLOWEST, SLOW, NORMAL can be set and used.
Setting FAST or FASTEST will automatically set it to NORMAL instead.
Warcraft 3 game speed setting:
| Menu Name | Game constant | Speed | 10 seconds is |
|----------------|--------------------|-------|---------------|
| High (default) | `MAP_SPEED_NORMAL` | 1.0x | 10s |
| Medium | `MAP_SPEED_SLOW` | 0.8x | 12.5s |
| Slow | `MAP_SPEED_SLOWEST`| 0.6x | 16.667s |
@note
This setting is actually just a multiplier for a "base game speed",
which is normally set to 1.0x (100%).
You can achieve a higher "base game speed" via a .wgc file only for testing.
The in-game `gamespeed` is actually a multiplier on top of that. The results
are shown in the table below:
| Base game speed | Game speed option | Effective speed |
| --------------: | ----------------: | --------------: |
| 1x | 0.6x | 0.60x |
| 1x | 0.8x | 0.80x |
| 1x | 1.0x | 1.00x |
| 2x | 0.6x | 1.20x |
| 2x | 0.8x | 1.60x |
| 2x | 1.0x | 2.00x |
| 3x | 0.6x | 1.80x |
| 3x | 0.8x | 2.40x |
| 3x | 1.0x | 3.00x |
Further reading:
- [How to run maps with high gamespeed](https://www.hiveworkshop.com/threads/how-to-run-maps-with-high-gamespeed.37255/)
- [WGC file format specification](https://github.com/ChiefOfGxBxL/WC3MapSpecification/pull/4)
@bug (v1.27, v1.32.10 tested) Restarting the map from the F10 in-game menu
will reset the "base game speed" back to 1x.
@patch 1.00
*/
type gamespeed extends handle
/**
@patch 1.00
*/
type gamedifficulty extends handle
/**
@patch 1.00
*/
type gametype extends handle
/**
@patch 1.00
*/
type mapflag extends handle
/**
@patch 1.00
*/
type mapvisibility extends handle
/**
@patch 1.00
*/
type mapsetting extends handle
/**
@patch 1.00
*/
type mapdensity extends handle
/**
@patch 1.00
*/
type mapcontrol extends handle
/**
@patch 1.32.0.13369
*/
type minimapicon extends handle
/**
@patch 1.00
*/
type playerslotstate extends handle
/**
@patch 1.00
*/
type volumegroup extends handle
/**
@patch 1.00
*/
type camerafield extends handle
/**
@patch 1.00
*/
type camerasetup extends handle
/**
@patch 1.00
*/
type playercolor extends handle
/**
@patch 1.00
*/
type placement extends handle
/**
@patch 1.00
*/
type startlocprio extends handle
/**
@patch 1.00
*/
type raritycontrol extends handle
/**
@patch 1.00
*/
type blendmode extends handle
/**
@patch 1.00
*/
type texmapflags extends handle
/**
@patch 1.00
*/
type effect extends agent
/**
@patch 1.00
*/
type effecttype extends handle
/**
@patch 1.00
*/
type weathereffect extends handle
/**
@patch 1.07
*/
type terraindeformation extends handle
/**
Represents different fog of war types.
- `FOG_OF_WAR_MASKED` (1): Black mask, an unexplored map area.
- If "Masked areas are partially visible" is enabled in
Map Properties, unexplored areas are shown in dark grey.
You can see the terrain, but no units.
- If disabled, unexplored areas are black and not visible.
- `FOG_OF_WAR_FOGGED` (2): Haze, a previously explored
map area that is currently not visible.
- You can see the terrain, but no units.
- `FOG_OF_WAR_VISIBLE` (4): A fully visible map area.
- Other (non-existent) fog types do nothing.
@patch 1.00
*/
type fogstate extends handle
/**
@patch 1.00
*/
type fogmodifier extends agent
/**
@patch 1.00
*/
type dialog extends agent
/**
@patch 1.00
*/
type button extends agent
/**
@patch 1.00
*/
type quest extends agent
/**
@patch 1.00
*/
type questitem extends agent
/**
@patch 1.00
*/
type defeatcondition extends agent
/**
@patch 1.00
*/
type timerdialog extends agent
/**
@patch 1.00
*/
type leaderboard extends agent
/**
@patch 1.07
*/
type multiboard extends agent
/**
@patch 1.07
*/
type multiboarditem extends agent
/**
Trackables can register both click and hover events by players. But they don't
provide a way to get the triggering player. In fact the only (as of writing)
functions that have the trackable type in their signature are:
* `CreateTrackable`
* `TriggerRegisterTrackableHitEvent`
* `TriggerRegisterTrackableTrackEvent`
* `GetTriggeringTrackable`
* `SaveTrackableHandle`
* `LoadTrackableHandle`
To create a trackable which can distinguish the triggering player we simply
create a trackable for each player but with a *locally* different path:
```
function CreateTrackableForPlayer takes player p, string path, real x, real y, real facing returns trackable
if GetLocalPlayer() != p then
set path = ""
endif
return CreateTrackable(path, x, y, facing)
endfunction
```
Now using something like `hashtable`s or [lua tables](https://www.lua.org/pil/2.5.html)
we can attach the correct player to the trackable handle and retrieve it by
accessing `GetTriggeringTrackable`. You can use the same technique to attach
other information like the trackables position, facing, etc.
@note See `CreateTrackable` for a way to create a trackable with a non-zero
z-coordinate.
@patch 1.00
*/
type trackable extends agent
/**
Gamecaches are designed for transferring data between maps in a campaign, by
storing data on the hard disk. In multi-player games however, the data is never
stored on the hard disk, making online campaigns and saving/loading data between
games impossible.
To be able to read and write from a gamecache across maps you have to use a
consistent name between them, that is the first parameter for `InitGameCache`.
If you're developing a campaign it would be reasonable to use something like
`set my_gc = InitGameCache("my_campaign.w3v")`.
Once you've setup your `gamecache` it is time to fill it with data. There are
only five natives to store data inside a `gamecache`, that is
* `StoreInteger`
* `StoreReal`
* `StoreBoolean`
* `StoreString`
* `StoreUnit`
These should be enough to track stats like gold, lumber and all your important
`unit`s. Just storing values inside the `gamecache` is not enough to transfer
them between maps though; in fact those natives still work in multiplayer.
Persisting stored values to disk is achieved by calling `SaveGameCache(my_gc)`.
Now if you create your `gamecache` again via `InitGameCache("my_campaign.w3v")`
(in another map or another game) it should have all previously stored values
available and can be queried via `HaveStoredString`, `RestoreUnit`, `GetStoredInteger`, etc.
@patch 1.00
*/
type gamecache extends agent
/**
@patch 1.07
*/
type version extends handle
/**
@patch 1.07
*/
type itemtype extends handle
/**
@patch 1.07
*/
type texttag extends handle
/**
@patch 1.17a
*/
type attacktype extends handle
/**
@patch 1.17a
*/
type damagetype extends handle
/**
@patch 1.17a
*/
type weapontype extends handle
/**
@patch 1.17a
*/
type soundtype extends handle
/**
@patch 1.17a
*/
type lightning extends handle
/**
@patch 1.18a
*/
type pathingtype extends handle
/**
@patch 1.29.0.8803
*/
type mousebuttontype extends handle
/**
@patch 1.30.0.9655
*/
type animtype extends handle
/**
@patch 1.30.0.9655
*/
type subanimtype extends handle
/**
@patch 1.18a
*/
type image extends handle
/**
@patch 1.18a
*/
type ubersplat extends handle
/**
@patch 1.24a
*/
type hashtable extends agent
/**
@patch 1.31.0.11889
*/
type framehandle extends handle
/**
@patch 1.31.0.11889
*/
type originframetype extends handle
/**
@patch 1.31.0.11889
*/
type framepointtype extends handle
/**
@patch 1.31.0.11889
*/
type textaligntype extends handle
/**
@patch 1.31.0.11889
*/
type frameeventtype extends handle
/**
@patch 1.31.0.11889
*/
type oskeytype extends handle
/**
@patch 1.31.0.11889
*/
type abilityintegerfield extends handle
/**
@patch 1.31.0.11889
*/
type abilityrealfield extends handle
/**
@patch 1.31.0.11889
*/
type abilitybooleanfield extends handle
/**
@patch 1.31.0.11889
*/
type abilitystringfield extends handle
/**
@patch 1.31.0.11889
*/
type abilityintegerlevelfield extends handle
/**
@patch 1.31.0.11889
*/
type abilityreallevelfield extends handle
/**
@patch 1.31.0.11889
*/
type abilitybooleanlevelfield extends handle
/**
@patch 1.31.0.11889
*/
type abilitystringlevelfield extends handle
/**
@patch 1.31.0.11889
*/
type abilityintegerlevelarrayfield extends handle
/**
@patch 1.31.0.11889
*/
type abilityreallevelarrayfield extends handle
/**
@patch 1.31.0.11889
*/
type abilitybooleanlevelarrayfield extends handle
/**
@patch 1.31.0.11889
*/
type abilitystringlevelarrayfield extends handle
/**
@patch 1.31.0.11889
*/
type unitintegerfield extends handle
/**
@patch 1.31.0.11889
*/
type unitrealfield extends handle
/**
@patch 1.31.0.11889
*/
type unitbooleanfield extends handle
/**
@patch 1.31.0.11889
*/
type unitstringfield extends handle
/**
@patch 1.31.0.11889
*/
type unitweaponintegerfield extends handle
/**
@patch 1.31.0.11889
*/
type unitweaponrealfield extends handle
/**
@patch 1.31.0.11889
*/
type unitweaponbooleanfield extends handle
/**
@patch 1.31.0.11889
*/
type unitweaponstringfield extends handle
/**
@patch 1.31.0.11889
*/
type itemintegerfield extends handle
/**
@patch 1.31.0.11889
*/
type itemrealfield extends handle
/**
@patch 1.31.0.11889
*/
type itembooleanfield extends handle
/**
@patch 1.31.0.11889
*/
type itemstringfield extends handle
/**
@patch 1.31.0.11889
*/
type movetype extends handle
/**
Constants of this type were defined (and their list is incomplete), but this type remains completely unused.
@note See `UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED` to access a unit's attack properties.
@patch 1.31.0.11889
*/
type targetflag extends handle
/**
@patch 1.31.0.11889
*/
type armortype extends handle
/**
@patch 1.31.0.11889
*/
type heroattribute extends handle
/**
@patch 1.31.0.11889
*/
type defensetype extends handle
/**
@patch 1.31.0.11889
*/
type regentype extends handle
/**
@patch 1.31.0.11889
*/
type unitcategory extends handle
/**
@patch 1.31.0.11889
*/
type pathingflag extends handle
/**
@patch 1.32.0.13369
*/
type commandbuttoneffect extends handle
/**
Returns the race that corresponds to the given integer.
@param i The integer representation of the race.
@pure
@patch 1.00
*/
constant native ConvertRace takes integer i returns race
/**
Returns the alliancetype that corresponds to the given integer.
@param i The integer representation of the alliancetype.
@pure
@patch 1.00
*/
constant native ConvertAllianceType takes integer i returns alliancetype
/**
Returns the racepreference that corresponds to the given integer.
@param i The integer representation of the racepreference.
@pure
@patch 1.00
*/
constant native ConvertRacePref takes integer i returns racepreference
/**
Returns the igamestate that corresponds to the given integer.
@param i The integer representation of the igamestate.
@pure
@patch 1.00
*/
constant native ConvertIGameState takes integer i returns igamestate
/**
Returns the fgamestate that corresponds to the given integer.
@param i The integer representation of the fgamestate.
@pure
@patch 1.00
*/
constant native ConvertFGameState takes integer i returns fgamestate
/**
Returns the playerstate that corresponds to the given integer.
@param i The integer representation of the playerstate.
@pure
@patch 1.00
*/
constant native ConvertPlayerState takes integer i returns playerstate
/**
Returns the playerscore that corresponds to the given integer.
@param i The integer representation of the playerscore.
@pure
@patch 1.13
*/
constant native ConvertPlayerScore takes integer i returns playerscore
/**
Returns the playergameresult that corresponds to the given integer.
@param i The integer representation of the playergameresult.
@pure
@patch 1.00
*/
constant native ConvertPlayerGameResult takes integer i returns playergameresult
/**
Returns unitstate, first index is 0.
It is used to define the constants representing unit state. Accepts any integer, the unitstate reference is always the same for a given integer.
**Example:** `constant unitstate UNIT_STATE_MAX_MANA = ConvertUnitState(3)`
@param i The integer representation of the unitstate.
@note See: `GetUnitState`, `SetUnitState`.
@pure
@patch 1.00
*/
constant native ConvertUnitState takes integer i returns unitstate
/**
Returns the aidifficulty that corresponds to the given integer.
@param i The integer representation of the aidifficulty.
@pure
@patch 1.07
*/
constant native ConvertAIDifficulty takes integer i returns aidifficulty
/**
Returns the gameevent that corresponds to the given integer.
@param i The integer representation of the gameevent.
@pure
@patch 1.00
*/
constant native ConvertGameEvent takes integer i returns gameevent
/**
Returns the playerevent that corresponds to the given integer.
@param i The integer representation of the playerevent.
@pure
@patch 1.00
*/
constant native ConvertPlayerEvent takes integer i returns playerevent
/**
Returns the playerunitevent that corresponds to the given integer.
@param i The integer representation of the playerunitevent.
@pure
@patch 1.00
*/
constant native ConvertPlayerUnitEvent takes integer i returns playerunitevent
/**
Returns the widgetevent that corresponds to the given integer.
@param i The integer representation of the widgetevent.
@pure
@patch 1.00
*/
constant native ConvertWidgetEvent takes integer i returns widgetevent
/**
Returns the dialogevent that corresponds to the given integer.
@param i The integer representation of the dialogevent.
@pure
@patch 1.00
*/