summaryrefslogtreecommitdiff
path: root/npc/functions/weather.txt
blob: 3cf872c82cae9e3e5b69a975a70a3c5684ae6151 (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
// TMW2 scripts.
// Authors:
//    Jesusalva
// Description:
//    Controls world seasons. RESPECT MASK_* VARS ON CONSTANTS DB

-	script	#WeatherCore	NPC_HIDDEN,{
    end;

OnInit:
    // This is weather startup
    .@init=true;
    // Bind commands
    bindatcmd "wsnow", "#WeatherCore::OnSnow", 80, 80, 1;
    bindatcmd "wrain", "#WeatherCore::OnRain", 80, 80, 1;
    bindatcmd "wsand", "#WeatherCore::OnSand", 80, 80, 1;
    bindatcmd "wevil", "#WeatherCore::OnEvil", 80, 80, 1;
    bindatcmd "wnight", "#WeatherCore::OnNight", 80, 80, 1;
    bindatcmd "wclear", "#WeatherCore::OnClear", 80, 80, 1;
    bindatcmd "wreset", "#WeatherCore::OnReset", 99, 99, 1;
    bindatcmd "wset",   "#WeatherCore::OnManual", 99, 99, 1;


    // Determine which maps are subject to weather, and how weather works:
    // eg. it should never snow on a desert, or happen a sandstorm on icelands.
    .wcore = htnew;

    // Deserts
    htput(.wcore, "001-1", CLIMATE_DESERT);
    htput(.wcore, "002-1", CLIMATE_DESERT);
    htput(.wcore, "003-2", CLIMATE_DESERT);
    htput(.wcore, "004-1", CLIMATE_DESERT);
    htput(.wcore, "006-1", CLIMATE_DESERT);
    htput(.wcore, "023-1", CLIMATE_DESERT);
    htput(.wcore, "041-1", CLIMATE_DESERT);
    htput(.wcore, "042-1", CLIMATE_DESERT);
    htput(.wcore, "043-1", CLIMATE_DESERT);

    // Woodlands
    htput(.wcore, "007-1", CLIMATE_WOODLAND);
    htput(.wcore, "008-1", CLIMATE_WOODLAND);
    htput(.wcore, "009-1", CLIMATE_WOODLAND);
    htput(.wcore, "010-1", CLIMATE_WOODLAND);
    htput(.wcore, "011-1", CLIMATE_WOODLAND);
    htput(.wcore, "012-1", CLIMATE_WOODLAND);
    htput(.wcore, "013-1", CLIMATE_WOODLAND);
    htput(.wcore, "014-1", CLIMATE_WOODLAND);
    htput(.wcore, "015-1", CLIMATE_WOODLAND);
    htput(.wcore, "016-1", CLIMATE_WOODLAND);
    htput(.wcore, "017-1", CLIMATE_WOODLAND);
    htput(.wcore, "018-1", CLIMATE_WOODLAND);
    htput(.wcore, "025-1", CLIMATE_WOODLAND);
    htput(.wcore, "026-1", CLIMATE_WOODLAND);
    htput(.wcore, "027-1", CLIMATE_WOODLAND);
    htput(.wcore, "028-1", CLIMATE_WOODLAND);
    htput(.wcore, "029-1", CLIMATE_WOODLAND);
    htput(.wcore, "051-1", CLIMATE_WOODLAND); // ?
    htput(.wcore, "052-1", CLIMATE_WOODLAND);
    htput(.wcore, "055-1", CLIMATE_WOODLAND);
    htput(.wcore, "057-1", CLIMATE_WOODLAND);

    // Icelands
    htput(.wcore, "019-1", CLIMATE_ICELAND);
    htput(.wcore, "020-1", CLIMATE_ICELAND);
    htput(.wcore, "030-1", CLIMATE_ICELAND);
    htput(.wcore, "031-1", CLIMATE_ICELAND);
    htput(.wcore, "033-1", CLIMATE_ICELAND);
    htput(.wcore, "034-1", CLIMATE_ICELAND);
    htput(.wcore, "045-1", CLIMATE_ICELAND);
    htput(.wcore, "046-1", CLIMATE_ICELAND);
    htput(.wcore, "047-1", CLIMATE_ICELAND);

    // Special
    htput(.wcore, "099-1", CLIMATE_NONE);


    debugmes("[Weather.sys] Total Maps = " + htsize(.wcore));
    end;

    ///////////////////////////////////////////////////////////////////
    // "#WeatherCore"::climate(mapid)
    public function climate {
        .@v = htget(.wcore, getarg(0), CLIMATE_NONE);
        return .@v;
    }

    // "#WeatherCore"::weather(weather{, mapid})
    public function weather {
        .@mk=getarg(0);
        .@m$=getarg(1, getmapname());
        return getmapmask(.@m$) & .@mk;
    }


    ///////////////////////////////////////////////////////////////////
    // Function to check stuff
    // WeatherSwitch ( MASK, MAP )
    function WeatherSwitch {
        // Get map
        getmapxy(.@key$,.@a,.@b,0);

        // Sanitize
        .@m$ = htget(.wcore, .@key$, "Not found");

        // Change Weather or abort
        if (.@m$ == "Not found")
            dispbottom l("Command not permitted on this map! Check npc/functions/weather.conf");
        else
            addmapmask(.@key$, getarg(0));
        return;
    }

// Some commands, for GMs manually override weather
OnRain:
    WeatherSwitch(MASK_RAIN);
    end;

OnSand:
    WeatherSwitch(MASK_SANDSTORM);
    end;

OnSnow:
    WeatherSwitch(MASK_SNOW);
    end;

OnNight:
    WeatherSwitch(MASK_NIGHT);
    end;

OnEvil:
    WeatherSwitch(MASK_EVILSANCTUM);
    end;

OnManual:
    if (!.@atcmd_numparameters) {
        dispbottom l("Syntax: @wset <map_mask>");
        end;
    }

    // Never allow negative numbers, or to disable map mask 1 (never, EVER, do such insane thing)
	.@rq = atoi(.@atcmd_parameters$[0]);
    if (.@rq <= 1 || .@rq % 2 == 1) {
        dispbottom l("Invalid map mask");
        end;
    }

    // <Insert a helpful comment here>
    getmapxy(.@key$,.@a,.@b,0);
    .@mk=getmapmask(.@key$);
    .@mk=.@mk^.@rq;
    setmapmask(.@key$, .@mk);
    end;

// Clear works on any map
OnClear:
    getmapxy(.@key$,.@a,.@b,0);
    .@mk=getmapmask(.@key$);
    if (.@mk & MASK_RAIN)
        .@mk=.@mk^MASK_RAIN;
    if (.@mk & MASK_SANDSTORM)
        .@mk=.@mk^MASK_SANDSTORM;
    if (.@mk & MASK_SNOW)
        .@mk=.@mk^MASK_SNOW;
    if (.@mk & MASK_NIGHT)
        .@mk=.@mk^MASK_NIGHT;
    setmapmask(.@key$, .@mk);
    end;

// Reset the whole map, including season, event and weather masks
OnReset:
    getmapxy(.@key$,.@a,.@b,0);
    setmapmask(.@key$, MASK_NONE);
    end;

}