summaryrefslogtreecommitdiff
path: root/npc/functions/maze.txt
blob: c1a8d86d12612f8e02987814e8b70c2d2f8e67a4 (plain) (blame)
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
// TMW2 Scripts
// Author:
//  Jesusalva
// Description:
//  Controls map domain 030 and provide helpers. See constants;
// Player Variables:
//      MAZE_ID → ID of the maze being used
//      MAZE_MAP$ → Map being used for the maze
//      MAZE_INST → Instance ID of the Maze

/////////////////////////////////////////////////////////////////////////////////
// CreateMaze(scope=IOT_CHAR{, size=MAZE_SIZE_S})
// Creates the maze instances so they can be configured
// But does not initializes anything.
function	script	CreateMaze	{
    .@scope = getarg(0, IOT_CHAR);
    .@size  = getarg(1, MAZE_SIZE_S);

    // Small mazes (30x30 average) (24 total)
    if (.@size & MAZE_SIZE_S) {
        .@p = getarraysize(.@ids);
        setarray .@ids[.@p], 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                             16, 17, 18, 19, 20, 21, 22, 23, 24;
    }
    // Medium mazes (45x45 average) (15 total)
    if (.@size & MAZE_SIZE_M) {
        .@p = getarraysize(.@ids);
        setarray .@ids[.@p], 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39;
    }
    // Great mazes (60x60 average) (20 total)
    if (.@size & MAZE_SIZE_G) {
        .@p = getarraysize(.@ids);
        setarray .@ids[.@p], 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
                             53, 54, 55, 56, 57, 58, 59;
    }
    // Xtra mazes (75x75 average) (10 total)
    if (.@size & MAZE_SIZE_X) {
        .@p = getarraysize(.@ids);
        setarray .@ids[.@p], 60, 61, 62, 63, 64, 65, 66, 67, 68, 69;
    }
    // Abs. mazes (90x90 average) (6 total)
    if (.@size & MAZE_SIZE_A) {
        .@p = getarraysize(.@ids);
        setarray .@ids[.@p], 70, 71, 72, 73, 74, 75;
    }

    // Get a random maze, but it must not be repeated
    do
    {
        .@r = any_of(.@ids);
        if (MAZE_ID == .@r)
            continue;
        MAZE_ID = .@r;

        .@MAZEMP$=sprintf("030-%02d", MAZE_ID);
        MAZE_MAP$=sprintf("mz%02d@"+getcharid(0), MAZE_ID);

        // Maze is not yet started
        if (.@scope == IOT_CHAR) {
		    MAZE_INST = instance_create("Maze "+MAZE_ID+" "+getcharid(0), getcharid(3), IOT_CHAR);
            // Failed
            if (MAZE_INST < 0) {
                consolebug("Instance \"%s\" already exists! (Error %d)", "Maze "+MAZE_ID+" "+getcharid(0), MAZE_INST);
                continue; // Get a new maze
            }
            // Attach map
	        instance_attachmap(.@MAZEMP$, MAZE_INST, false, MAZE_MAP$);
        } else {
            consolebug("Scope %d not yet supported by maze system", .@scope);
            return 0; // Exit early
        }
    } while (MAZE_INST < 0);
    return MAZE_ID;
}

/////////////////////////////////////////////////////////////////////////////////
// InitMaze(duration=2 hours, random=yes)
// Puts maze to work and send player there.
// Exit must have been configured prior to the maze.
function	script	InitMaze	{
    .@t = getarg(0, 7200);
	instance_set_timeout(.@t, .@t, MAZE_INST);
	instance_init(MAZE_INST);

    // Find random, warpable coordinates
    .@e=0; .@x=0; .@y=0;
    if (getarg(1, true)) {
        .@mx=getmapinfo(MAPINFO_SIZE_X, MAZE_MAP$)-20;
        .@my=getmapinfo(MAPINFO_SIZE_Y, MAZE_MAP$)-20;
    } else {
        .@mx=40; // Wouldn't (30,30) be safer?
        .@my=40;
    }
    do {
        .@x = rand2(20, .@mx);
        .@y = rand2(20, .@my);
        .@e += 1;
        if (.@e > 30) {
            consolebug("Too many failures at Maze \"%s\"! Trying anyway!", MAZE_MAP$);
            break;
        }
    } while (!checknpccell(MAZE_MAP$, .@x, .@y, cell_chkpass));

    warp MAZE_MAP$, .@x, .@y;
    return true;
}

/////////////////////////////////////////////////////////////////////////////////
// RenewMaze(duration=2 hours)
// Renews the map expiration time
function	script	RenewMaze	{
    .@t = getarg(0, 7200);
	instance_set_timeout(.@t, .@t, MAZE_INST);
    return true;
}

/////////////////////////////////////////////////////////////////////////////////
// Configure maze maps as MMO zones
030-01	mapflag	zone	MMO
030-02	mapflag	zone	MMO
030-03	mapflag	zone	MMO
030-04	mapflag	zone	MMO
030-05	mapflag	zone	MMO
030-06	mapflag	zone	MMO
030-07	mapflag	zone	MMO
030-08	mapflag	zone	MMO
030-09	mapflag	zone	MMO
030-10	mapflag	zone	MMO
030-11	mapflag	zone	MMO
030-12	mapflag	zone	MMO
030-13	mapflag	zone	MMO
030-14	mapflag	zone	MMO
030-15	mapflag	zone	MMO
030-16	mapflag	zone	MMO
030-17	mapflag	zone	MMO
030-18	mapflag	zone	MMO
030-19	mapflag	zone	MMO
030-20	mapflag	zone	MMO
030-21	mapflag	zone	MMO
030-22	mapflag	zone	MMO
030-23	mapflag	zone	MMO
030-24	mapflag	zone	MMO
030-25	mapflag	zone	MMO
030-26	mapflag	zone	MMO
030-27	mapflag	zone	MMO
030-28	mapflag	zone	MMO
030-29	mapflag	zone	MMO
030-30	mapflag	zone	MMO
030-31	mapflag	zone	MMO
030-32	mapflag	zone	MMO
030-33	mapflag	zone	MMO
030-34	mapflag	zone	MMO
030-35	mapflag	zone	MMO
030-36	mapflag	zone	MMO
030-37	mapflag	zone	MMO
030-38	mapflag	zone	MMO
030-39	mapflag	zone	MMO
030-40	mapflag	zone	MMO
030-41	mapflag	zone	MMO
030-42	mapflag	zone	MMO
030-43	mapflag	zone	MMO
030-44	mapflag	zone	MMO
030-45	mapflag	zone	MMO
030-46	mapflag	zone	MMO
030-47	mapflag	zone	MMO
030-48	mapflag	zone	MMO
030-49	mapflag	zone	MMO
030-50	mapflag	zone	MMO
030-51	mapflag	zone	MMO
030-52	mapflag	zone	MMO
030-53	mapflag	zone	MMO
030-54	mapflag	zone	MMO
030-55	mapflag	zone	MMO
030-56	mapflag	zone	MMO
030-57	mapflag	zone	MMO
030-58	mapflag	zone	MMO
030-59	mapflag	zone	MMO
030-60	mapflag	zone	MMO
030-61	mapflag	zone	MMO
030-62	mapflag	zone	MMO
030-63	mapflag	zone	MMO
030-64	mapflag	zone	MMO
030-65	mapflag	zone	MMO
030-66	mapflag	zone	MMO
030-67	mapflag	zone	MMO
030-68	mapflag	zone	MMO
030-69	mapflag	zone	MMO
030-70	mapflag	zone	MMO
030-71	mapflag	zone	MMO
030-72	mapflag	zone	MMO
030-73	mapflag	zone	MMO
030-74	mapflag	zone	MMO
030-75	mapflag	zone	MMO

/////////////////////////////////////////////////////////////////////////////////
// Add Treasure chests
030-01,0,0,0	script	#T_030-01	NPC_CHEST,{
    if (!reachable(.x, .y, 3)) end;
    callfunc "TreasureBox", 150; // 1.5% extra chance
    specialeffect(.dir == 0 ? 24 : 25, AREA, getnpcid()); // closed ? opening : closing
    close;
OnInit:
    .distance=3;
    end;
}

030-02,0,0,0	duplicate(#T_030-01)	#T_030-02	NPC_CHEST
030-03,0,0,0	duplicate(#T_030-01)	#T_030-03	NPC_CHEST
030-04,0,0,0	duplicate(#T_030-01)	#T_030-04	NPC_CHEST
030-05,0,0,0	duplicate(#T_030-01)	#T_030-05	NPC_CHEST
030-06,0,0,0	duplicate(#T_030-01)	#T_030-06	NPC_CHEST
030-07,0,0,0	duplicate(#T_030-01)	#T_030-07	NPC_CHEST
030-08,0,0,0	duplicate(#T_030-01)	#T_030-08	NPC_CHEST
030-09,0,0,0	duplicate(#T_030-01)	#T_030-09	NPC_CHEST
030-10,0,0,0	duplicate(#T_030-01)	#T_030-10	NPC_CHEST
030-11,0,0,0	duplicate(#T_030-01)	#T_030-11	NPC_CHEST
030-12,0,0,0	duplicate(#T_030-01)	#T_030-12	NPC_CHEST
030-13,0,0,0	duplicate(#T_030-01)	#T_030-13	NPC_CHEST
030-14,0,0,0	duplicate(#T_030-01)	#T_030-14	NPC_CHEST
030-15,0,0,0	duplicate(#T_030-01)	#T_030-15	NPC_CHEST
030-16,0,0,0	duplicate(#T_030-01)	#T_030-16	NPC_CHEST
030-17,0,0,0	duplicate(#T_030-01)	#T_030-17	NPC_CHEST
030-18,0,0,0	duplicate(#T_030-01)	#T_030-18	NPC_CHEST
030-19,0,0,0	duplicate(#T_030-01)	#T_030-19	NPC_CHEST
030-20,0,0,0	duplicate(#T_030-01)	#T_030-20	NPC_CHEST
030-21,0,0,0	duplicate(#T_030-01)	#T_030-21	NPC_CHEST
030-22,0,0,0	duplicate(#T_030-01)	#T_030-22	NPC_CHEST
030-23,0,0,0	duplicate(#T_030-01)	#T_030-23	NPC_CHEST
030-24,0,0,0	duplicate(#T_030-01)	#T_030-24	NPC_CHEST
030-25,0,0,0	duplicate(#T_030-01)	#T_030-25	NPC_CHEST
030-26,0,0,0	duplicate(#T_030-01)	#T_030-26	NPC_CHEST
030-27,0,0,0	duplicate(#T_030-01)	#T_030-27	NPC_CHEST
030-28,0,0,0	duplicate(#T_030-01)	#T_030-28	NPC_CHEST
030-29,0,0,0	duplicate(#T_030-01)	#T_030-29	NPC_CHEST
030-30,0,0,0	duplicate(#T_030-01)	#T_030-30	NPC_CHEST
030-31,0,0,0	duplicate(#T_030-01)	#T_030-31	NPC_CHEST
030-32,0,0,0	duplicate(#T_030-01)	#T_030-32	NPC_CHEST
030-33,0,0,0	duplicate(#T_030-01)	#T_030-33	NPC_CHEST
030-34,0,0,0	duplicate(#T_030-01)	#T_030-34	NPC_CHEST
030-35,0,0,0	duplicate(#T_030-01)	#T_030-35	NPC_CHEST
030-36,0,0,0	duplicate(#T_030-01)	#T_030-36	NPC_CHEST
030-37,0,0,0	duplicate(#T_030-01)	#T_030-37	NPC_CHEST
030-38,0,0,0	duplicate(#T_030-01)	#T_030-38	NPC_CHEST
030-39,0,0,0	duplicate(#T_030-01)	#T_030-39	NPC_CHEST
030-40,0,0,0	duplicate(#T_030-01)	#T_030-40	NPC_CHEST
030-41,0,0,0	duplicate(#T_030-01)	#T_030-41	NPC_CHEST
030-42,0,0,0	duplicate(#T_030-01)	#T_030-42	NPC_CHEST
030-43,0,0,0	duplicate(#T_030-01)	#T_030-43	NPC_CHEST
030-44,0,0,0	duplicate(#T_030-01)	#T_030-44	NPC_CHEST
030-45,0,0,0	duplicate(#T_030-01)	#T_030-45	NPC_CHEST
030-46,0,0,0	duplicate(#T_030-01)	#T_030-46	NPC_CHEST
030-47,0,0,0	duplicate(#T_030-01)	#T_030-47	NPC_CHEST
030-48,0,0,0	duplicate(#T_030-01)	#T_030-48	NPC_CHEST
030-49,0,0,0	duplicate(#T_030-01)	#T_030-49	NPC_CHEST
030-50,0,0,0	duplicate(#T_030-01)	#T_030-50	NPC_CHEST
030-51,0,0,0	duplicate(#T_030-01)	#T_030-51	NPC_CHEST
030-52,0,0,0	duplicate(#T_030-01)	#T_030-52	NPC_CHEST
030-53,0,0,0	duplicate(#T_030-01)	#T_030-53	NPC_CHEST
030-54,0,0,0	duplicate(#T_030-01)	#T_030-54	NPC_CHEST
030-55,0,0,0	duplicate(#T_030-01)	#T_030-55	NPC_CHEST
030-56,0,0,0	duplicate(#T_030-01)	#T_030-56	NPC_CHEST
030-57,0,0,0	duplicate(#T_030-01)	#T_030-57	NPC_CHEST
030-58,0,0,0	duplicate(#T_030-01)	#T_030-58	NPC_CHEST
030-59,0,0,0	duplicate(#T_030-01)	#T_030-59	NPC_CHEST
030-60,0,0,0	duplicate(#T_030-01)	#T_030-60	NPC_CHEST
030-61,0,0,0	duplicate(#T_030-01)	#T_030-61	NPC_CHEST
030-62,0,0,0	duplicate(#T_030-01)	#T_030-62	NPC_CHEST
030-63,0,0,0	duplicate(#T_030-01)	#T_030-63	NPC_CHEST
030-64,0,0,0	duplicate(#T_030-01)	#T_030-64	NPC_CHEST
030-65,0,0,0	duplicate(#T_030-01)	#T_030-65	NPC_CHEST
030-66,0,0,0	duplicate(#T_030-01)	#T_030-66	NPC_CHEST
030-67,0,0,0	duplicate(#T_030-01)	#T_030-67	NPC_CHEST
030-68,0,0,0	duplicate(#T_030-01)	#T_030-68	NPC_CHEST
030-69,0,0,0	duplicate(#T_030-01)	#T_030-69	NPC_CHEST
030-70,0,0,0	duplicate(#T_030-01)	#T_030-70	NPC_CHEST
030-71,0,0,0	duplicate(#T_030-01)	#T_030-71	NPC_CHEST
030-72,0,0,0	duplicate(#T_030-01)	#T_030-72	NPC_CHEST
030-73,0,0,0	duplicate(#T_030-01)	#T_030-73	NPC_CHEST
030-74,0,0,0	duplicate(#T_030-01)	#T_030-74	NPC_CHEST
030-75,0,0,0	duplicate(#T_030-01)	#T_030-75	NPC_CHEST