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
|
// 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;
break;
} while (true);
.@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);
return 0;
}
// Attach map
instance_attachmap(.@MAZEMP$, .@inst, false, MAZE_MAP$);
} else {
consolebug("Scope %d not yet supported by maze system", .@scope);
return 0;
}
return MAZE_ID;
}
/////////////////////////////////////////////////////////////////////////////////
// InitMaze(duration=2 hours)
// 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;
.@mx=getmapinfo(MAPINFO_SIZE_X, MAZE_MAP$)-20;
.@my=getmapinfo(MAPINFO_SIZE_Y, MAZE_MAP$)-20;
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
|