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

// is_night()
function	script	is_night	{
    // For convenience, night time is from 00:15 to 00:45, every hour.
    // 2 = GETTIME_MINUTE
    if (gettime(2) >= 15 && gettime(2) < 45)
        return 1;
    return 0;
}

000-0,0,0,0	script	#WeatherCore	NPC_HIDDEN,{
    end;

/*
 * removemapflag("<map name>", <flag>)
 * setmapflag("<map name>", <flag>{, <val>})
 * getmapflag("<map name>", <flag>)

	mf_snow:               16

	mf_jexp:               39
	mf_bexp:               40
*/

OnInit:
    // 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;


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

    // Deserts
    htput(.wcore, "003-1", "desert");
    htput(.wcore, "004-1", "desert");
    htput(.wcore, "004-2", "desert");
    htput(.wcore, "009-1", "desert");
    htput(.wcore, "010-1", "desert");
    htput(.wcore, "010-2", "desert");

    // Woodlands
    htput(.wcore, "005-1", "woodland");
    htput(.wcore, "012-1", "woodland");
    htput(.wcore, "014-1", "woodland");
    htput(.wcore, "014-2", "woodland");
    htput(.wcore, "014-3", "woodland");

    // Icelands
    htput(.wcore, "001-7", "iceland");

    debugmes "[Weather.sys] Total Maps = " + htsize(.wcore);
    // No "end" here, so server starts with weather
OnMinute00:
OnMinute15:
OnMinute30:
OnMinute45:

    .@hti = htiterator(.wcore);
    for(.@key$ = htinextkey(.@hti); hticheck(.@hti); .@key$ = htinextkey(.@hti)) {

        // PvP Maps are immune to weather changes (eg. during sieges)
        // I could use getmapmask, but this is simpler.
        if (getmapflag(.@key$, mf_pvp))
            continue;

        // Local variables: .@key$ .@type .@r
        .@type$=htget(.wcore, .@key$);
        .@r=rand(0,10000);
        .@mk=MASK_NONE;

        // Remove all current masks, and add rain/snow/sand
        if (.@type$ == "desert") {
            if (.@r < 10)
                .@mk=MASK_RAIN;
            else if (.@r < 300)
                .@mk=MASK_SANDSTORM;

        } else if (.@type$ == "woodland") {
            if (.@r < 300)
                .@mk=MASK_RAIN;

        } else if (.@type$ == "iceland") {
            if (.@r < 30)
                .@mk=MASK_RAIN;
            else if (.@r < 300)
                .@mk=MASK_SNOW;

        } else {
            debugmes "Warning warning, blame Saulc! Weather system error on map "+.@key$;
            announce("ERROR BLAME SAULC! WEATHER SYSTEM CORRUPTED. KILLING MAP SERVERS.", bc_all);
            atcommand "@mapexit";
        }

        setmapmask .@key$, .@mk;

        // Is it night time?
        if (is_night()) {
            setmapflag(.@key$, mf_nightenabled);
            addmapmask .@key$, MASK_NIGHT;
        } else if (getmapmask(.@key$) & MASK_NIGHT) {
            removemapflag(.@key$, mf_nightenabled);
            removemapmask .@key$, MASK_NIGHT;
        }

    }
    htidelete(.@hti);

    // During night, there are 20% more monsters on all maps
    if (is_night())
        setbattleflag("mob_count_rate", 120);
    else
        setbattleflag("mob_count_rate", 100);

    debugmes "[Weather.sys] Weather reloaded";
    end;

    // Function to check stuff
    // WeatherSwitch ( MASK )
    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;

// Clear works on any map
OnClear:
    getmapxy(.@key$,.@a,.@b,0);
    setmapmask(.@key$, MASK_NONE);
    end;

}