-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathweather.cpp
128 lines (120 loc) · 3.36 KB
/
weather.cpp
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
#include "weather.h"
#include "game.h"
#include <vector>
#define PLAYER_OUTSIDE (g->m.is_outside(g->u.posx, g->u.posy) && g->levz >= 0)
#define THUNDER_CHANCE 50
#define LIGHTNING_CHANCE 600
void weather_effect::glare(game *g)
{
if (g->is_in_sunlight(g->u.posx, g->u.posy))
g->u.infect(DI_GLARE, bp_eyes, 1, 2, g);
}
void weather_effect::wet(game *g)
{
if (!g->u.is_wearing(itm_coat_rain) && !g->u.has_trait(PF_FEATHERS) &&
PLAYER_OUTSIDE && one_in(2))
g->u.add_morale(MORALE_WET, -1, -30);
// Put out fires and reduce scent
for (int x = g->u.posx - SEEX * 2; x <= g->u.posx + SEEX * 2; x++) {
for (int y = g->u.posy - SEEY * 2; y <= g->u.posy + SEEY * 2; y++) {
if (g->m.is_outside(x, y)) {
field *fd = &(g->m.field_at(x, y));
if (fd->type == fd_fire)
fd->age += 15;
if (g->scent(x, y) > 0)
g->scent(x, y)--;
}
}
}
}
void weather_effect::very_wet(game *g)
{
if (!g->u.is_wearing(itm_coat_rain) && !g->u.has_trait(PF_FEATHERS) &&
PLAYER_OUTSIDE)
g->u.add_morale(MORALE_WET, -1, -60);
// Put out fires and reduce scent
for (int x = g->u.posx - SEEX * 2; x <= g->u.posx + SEEX * 2; x++) {
for (int y = g->u.posy - SEEY * 2; y <= g->u.posy + SEEY * 2; y++) {
if (g->m.is_outside(x, y)) {
field *fd = &(g->m.field_at(x, y));
if (fd->type == fd_fire)
fd->age += 45;
if (g->scent(x, y) > 0)
g->scent(x, y)--;
}
}
}
}
void weather_effect::thunder(game *g)
{
very_wet(g);
if (one_in(THUNDER_CHANCE)) {
if (g->levz >= 0)
g->add_msg("You hear a distant rumble of thunder.");
else if (!g->u.has_trait(PF_BADHEARING) && one_in(1 - 3 * g->levz))
g->add_msg("You hear a rumble of thunder from above.");
}
}
void weather_effect::lightning(game *g)
{
thunder(g);
if (one_in(LIGHTNING_CHANCE)) {
std::vector<point> strike;
for (int x = g->u.posx - SEEX * 2; x <= g->u.posx + SEEX * 2; x++) {
for (int y = g->u.posy - SEEY * 2; y <= g->u.posy + SEEY * 2; y++) {
if (g->m.move_cost(x, y) == 0 && g->m.is_outside(x, y))
strike.push_back(point(x, y));
}
}
point hit;
if (strike.size() > 0) {
hit = strike[rng(0, strike.size() - 1)];
g->add_msg("Lightning strikes nearby!");
g->explosion(hit.x, hit.y, 10, 0, one_in(4));
}
}
}
void weather_effect::light_acid(game *g)
{
wet(g);
if (int(g->turn) % 10 == 0 && PLAYER_OUTSIDE)
g->add_msg("The acid rain stings, but is harmless for now...");
}
void weather_effect::acid(game *g)
{
if (PLAYER_OUTSIDE) {
g->add_msg("The acid rain burns!");
if (one_in(6))
g->u.hit(g, bp_head, 0, 0, 1);
if (one_in(10)) {
g->u.hit(g, bp_legs, 0, 0, 1);
g->u.hit(g, bp_legs, 1, 0, 1);
}
if (one_in(8)) {
g->u.hit(g, bp_feet, 0, 0, 1);
g->u.hit(g, bp_feet, 1, 0, 1);
}
if (one_in(6))
g->u.hit(g, bp_torso, 0, 0, 1);
if (one_in(8)) {
g->u.hit(g, bp_arms, 0, 0, 1);
g->u.hit(g, bp_arms, 1, 0, 1);
}
}
if (g->levz >= 0) {
for (int x = g->u.posx - SEEX * 2; x <= g->u.posx + SEEX * 2; x++) {
for (int y = g->u.posy - SEEY * 2; y <= g->u.posy + SEEY * 2; y++) {
if (!g->m.has_flag(diggable, x, y) && !g->m.has_flag(noitem, x, y) &&
g->m.move_cost(x, y) > 0 && g->m.is_outside(x, y) && one_in(400))
g->m.add_field(g, x, y, fd_acid, 1);
}
}
}
for (int i = 0; i < g->z.size(); i++) {
if (g->m.is_outside(g->z[i].posx, g->z[i].posy)) {
if (!g->z[i].has_flag(MF_ACIDPROOF))
g->z[i].hurt(1);
}
}
very_wet(g);
}