-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld_util.chai
222 lines (184 loc) · 5.03 KB
/
world_util.chai
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
/*
@name World Utility
@author MrKosjaK
@description
Declare world_utility() in a global variable like this:
global WU = world_utility();
After that you just use this prefix WU and use needed function like this:
WU.randomize_angle();
@function randomize_angle() NOTE: only 8 angles.
@returns {int}
@function randomize_model()
@returns {int}
@function replace_with_new() NOTE: this is only for trees atm.
@param {struct Thing}
@function count_trees()
@returns {int} Amount of trees
@function calc_rad()
@param {Coord3D} Coords
@param {int} Degree 0-360
@param {int} Offset from the centre
@param {int} Radius
@returns {Coord3D}
@function spawn_discovery_at_pos() NOTE: currently does only one shot spells
@param {Coord3D} Coords
@param {int} Discovery model aka spell.
@function spawn_wilds_at_random_pos()
@param {int} Amount of wildies to spawn
@function calc_eight_cells_around() NOTE: used for initial spawn of wildies for cor.
@param {Coord3D} Coords
@function spawn_cor_wilds() NOTE: spawns 8 wilds around all shamans, this is used at start of level.
@function random_pos() NOTE: does search for only land point.
@param {int} Amount of searches
@returns {Coord3D} Coords
@function spawn_dormant_trees_at_random_pos()
@param {int} Amount of trees
@param {int} Dormant time in seconds
*/
class world_utility
{
var rand_a;
var rand_m;
var coord;
var cells_vect;
def world_utility()
{
this.cells_vect = Vector();
}
def randomize_angle()
{
var angles = Vector();
for (var a = 0; a < 7; ++a)
{
angles.insert_at(a, 256*a);
}
this.rand_a = G_RANDOM(angles.size());
return angles[this.rand_a];
}
def randomize_model()
{
this.rand_m = 1 + G_RANDOM(6)
return this.rand_m;
}
def replace_with_new(t)
{
this.coord = t.Pos.D3;
var nt := createThing(T_SCENERY, this.randomize_model(), TRIBE_HOSTBOT, this.coord, false, false);
nt.AngleXZ = this.randomize_angle();
DestroyThing(t);
}
def count_trees()
{
var n = 0;
ProcessGlobalTypeList(T_SCENERY, fun[n] (Thing t)
{
if (t.Model < 7)
{
++n;
}
return true;
});
return n;
}
def calc_rad(a, b, rmin, rmax)
{
var c3d = a;
var rot = double();
rot = b * PI / 180;
var thing_x = double();
var thing_z = double();
thing_x = c3d.Xpos + (cos(rot) * (G_RANDOM(rmax)+rmin));
thing_z = c3d.Zpos + (sin(rot) * (G_RANDOM(rmax)+rmin));
var final_c3d = Coord3D();
final_c3d.Xpos = thing_x;
final_c3d.Zpos = thing_z;
return final_c3d;
}
def spawn_discovery_at_pos(a, b)
{
var discovery = createThing(T_GENERAL, M_GENERAL_DISCOVERY, TRIBE_HOSTBOT, a, false, false);
discovery.u.Discovery.DiscoveryType = 11;
discovery.u.Discovery.DiscoveryModel = b;
discovery.u.Discovery.AvailabilityType = 3;
discovery.u.Discovery.TriggerType = 1;
}
def spawn_wilds_at_random_pos(amount)
{
for (var i = 0; i < amount; ++i)
{
var w_coord = this.random_pos(64);
centre_coord3d_on_block(w_coord);
var w_t := createThing(T_PERSON, M_PERSON_WILD, TRIBE_HOSTBOT, w_coord, false, false);
set_person_new_state(w_t, S_PERSON_STAND_FOR_TIME);
}
}
def calc_eight_cells_around(ec_coord)
{
var l_vect = Vector();
for (var h = 0; h < 9; ++h)
{
l_vect.insert_at(h, ec_coord);
}
l_vect[1].Xpos += 256 + 128;
l_vect[2].Xpos -= 256 + 128;
l_vect[3].Zpos += 256 + 128;
l_vect[4].Zpos -= 256 + 128;
l_vect[5].Xpos += 256 + 128;
l_vect[5].Zpos += 256 + 128;
l_vect[6].Xpos += 256 + 128;
l_vect[6].Zpos -= 256 + 128;
l_vect[7].Xpos -= 256 + 128;
l_vect[7].Zpos += 256 + 128;
l_vect[8].Xpos -= 256 + 128;
l_vect[8].Zpos -= 256 + 128;
for (var hh = 1; hh < l_vect.size(); ++hh)
{
centre_coord3d_on_block(l_vect[hh])
this.cells_vect.push_back(l_vect[hh]);
}
}
def spawn_cor_wilds()
{
for (var pn = 0; pn < 4; ++pn)
{
var shaman = getShaman(pn);
if (!shaman.is_var_null())
{
var s_c = shaman.Pos.D3;
this.calc_eight_cells_around(s_c);
this.cells_vect.for_each(fun(cell)
{
var s_t := createThing(T_PERSON, M_PERSON_WILD, TRIBE_HOSTBOT, cell, false, false);
set_person_new_state(s_t, S_PERSON_STAND_FOR_TIME);
});
this.cells_vect.clear();
}
}
}
def random_pos(_tries)
{
var tries = 0
var c3d = Coord3D();
var c2d = Coord2D();
while (tries < _tries)
{
c3d.Xpos = G_RANDOM(65536);
c3d.Zpos = G_RANDOM(65536);
coord3D_to_coord2D(c3d, c2d);
if (is_map_point_land(c2d) == 1)
{
break;
}
++tries;
}
return c3d;
}
def spawn_dormant_trees_at_random_pos(amount, time)
{
var s_to_gt = time*12;
for (var e = 0; e < amount; ++e)
{
CREATE_THING_WITH_PARAMS4(T_SCENERY, M_SCENERY_DORMANT_TREE, TRIBE_HOSTBOT, this.random_pos(64), T_SCENERY, this.randomize_model(), s_to_gt, 0);
}
}
}