forked from crawl/crawl
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcloud.cc
1908 lines (1682 loc) · 57.3 KB
/
cloud.cc
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file
* @brief Functions related to clouds.
*
* Creating a cloud module so all the cloud stuff can be isolated.
**/
#include "AppHdr.h"
#include "cloud.h"
#include <algorithm>
#include "areas.h"
#include "colour.h"
#include "coordit.h"
#include "dungeon.h"
#include "godconduct.h"
#include "libutil.h" // testbits
#include "los.h"
#include "mapmark.h"
#include "melee_attack.h"
#include "message.h"
#include "mon-behv.h"
#include "mon-death.h"
#include "mon-place.h"
#include "religion.h"
#include "shout.h"
#include "spl-util.h"
#include "state.h"
#include "stringutil.h"
#include "terrain.h"
#include "tiledef-main.h"
#include "unwind.h"
/// A portrait of a cloud_type.
struct cloud_data
{
/// A (relatively) short name for the cloud. May be referenced from lua.
const char* terse_name;
/// Another name for the cloud. If nullptr, defaults to terse name.
const char* verbose_name;
/// The colour of the cloud in console.
colour_t colour;
/// The associated "beam" (effect) for this cloud type.
beam_type beam_effect;
/// How much damage a cloud is expected to do in one turn, minimum.
int expected_base_damage;
/// The amount of additional random damage a cloud is expected to maybe do.
int expected_random_damage;
};
/// A map from cloud_type to cloud_data.
static const cloud_data clouds[] = {
// CLOUD_NONE,
{ "?", "?", // terse, verbose name
},
// CLOUD_FIRE,
{ "flame", "roaring flames", // terse, verbose name
COLOUR_UNDEF, // colour
BEAM_FIRE, // beam_effect
15, 46, // base, expected random damage
},
// CLOUD_MEPHITIC,
{ "noxious fumes", nullptr, // terse, verbose name
GREEN, // colour
BEAM_MEPHITIC, // beam_effect
0, 19, // base, expected random damage
},
// CLOUD_COLD,
{ "freezing vapour", "freezing vapours", // terse, verbose name
COLOUR_UNDEF, // colour
BEAM_COLD, // beam_effect
15, 46, // base, expected random damage
},
// CLOUD_POISON,
{ "poison gas", nullptr, // terse, verbose name
LIGHTGREEN, // colour
BEAM_POISON, // beam_effect
0, 37, // base, expected random damage
},
// CLOUD_BLACK_SMOKE,
{ "black smoke", nullptr, // terse, verbose name
DARKGREY, // colour
},
// CLOUD_GREY_SMOKE,
{ "grey smoke", nullptr, // terse, verbose name
LIGHTGREY, // colour
},
// CLOUD_BLUE_SMOKE,
{ "blue smoke", nullptr, // terse, verbose name
LIGHTBLUE, // colour
},
// CLOUD_PURPLE_SMOKE,
{ "purple smoke", nullptr, // terse, verbose name
MAGENTA, // colour
},
// CLOUD_TLOC_ENERGY,
{ "translocational energy", nullptr, // terse, verbose name
MAGENTA, // colour
},
// CLOUD_FOREST_FIRE,
{ "spreading flames", "a forest fire", // terse, verbose name
COLOUR_UNDEF, // colour
BEAM_FIRE, // beam_effect
15, 46 // base, expected random damage
},
// CLOUD_STEAM,
{ "steam", "a cloud of scalding steam", // terse, verbose name
LIGHTGREY, // colour
BEAM_STEAM, // beam_effect
0, 25,
},
#if TAG_MAJOR_VERSION == 34
// CLOUD_GLOOM,
{ "gloom", "thick gloom", // terse, verbose name
MAGENTA, // colour
},
#endif
// CLOUD_INK,
{ "ink", nullptr, // terse, verbose name
DARKGREY, // colour
BEAM_INK, // beam_effect
},
// CLOUD_PETRIFY,
{ "calcifying dust", nullptr, // terse, verbose name
WHITE, // colour
BEAM_PETRIFYING_CLOUD, // beam_effect
},
// CLOUD_HOLY_FLAMES,
{ "blessed fire", nullptr, // terse, verbose name
ETC_HOLY, // colour
BEAM_HOLY_FLAME, // beam_effect
15, 46, // base, expected random damage
},
// CLOUD_MIASMA,
{ "foul pestilence", "dark miasma", // terse, verbose name
DARKGREY, // colour
BEAM_MIASMA, // beam_effect
},
// CLOUD_MIST,
{ "thin mist", nullptr, // terse, verbose name
ETC_MIST, // colour
},
// CLOUD_CHAOS,
{ "seething chaos", nullptr, // terse, verbose name
ETC_RANDOM, // colour
BEAM_CHAOS, // beam_effect
},
// CLOUD_RAIN,
{ "rain", "the rain", // terse, verbose name
ETC_MIST, // colour
},
// CLOUD_MUTAGENIC,
{ "mutagenic fog", nullptr, // terse, verbose name
ETC_MUTAGENIC, // colour
},
// CLOUD_MAGIC_TRAIL,
{ "magical condensation", nullptr, // terse, verbose name
ETC_MAGIC, // colour
},
// CLOUD_TORNADO,
{ "raging winds", nullptr, // terse, verbose name
ETC_TORNADO, // colour
},
// CLOUD_DUST_TRAIL,
{ "sparse dust", nullptr, // terse, verbose name
ETC_EARTH, // colour
},
// CLOUD_SPECTRAL,
{ "spectral mist", nullptr, // terse, verbose name
ETC_ELECTRICITY, // colour
BEAM_NONE, // beam_effect
0, 25, // base, expected random damage
},
// CLOUD_ACID,
{ "acidic fog", nullptr, // terse, verbose name
YELLOW, // colour
BEAM_ACID, // beam_effect
15, 46, // base, random expected damage
},
// CLOUD_STORM,
{ "thunder", "a thunderstorm", // terse, verbose name
ETC_DARK, // colour
BEAM_ELECTRICITY, // beam_effect
60, 46, // base, random expected damage
},
// CLOUD_NEGATIVE_ENERGY,
{ "negative energy", nullptr, // terse, verbose name
ETC_INCARNADINE, // colour
BEAM_NEG, // beam_effect
15, 46, // base, random expected damage
},
};
COMPILE_CHECK(ARRAYSZ(clouds) == NUM_CLOUD_TYPES);
static int _actor_cloud_damage(const actor *act, const cloud_struct &cloud,
bool maximum_damage);
static int _actual_spread_rate(cloud_type type, int spread_rate)
{
if (spread_rate >= 0)
return spread_rate;
switch (type)
{
#if TAG_MAJOR_VERSION == 34
case CLOUD_GLOOM:
return 50;
#endif
case CLOUD_STEAM:
case CLOUD_GREY_SMOKE:
case CLOUD_BLACK_SMOKE:
return 22;
case CLOUD_RAIN:
case CLOUD_INK:
return 11;
default:
return 0;
}
}
static beam_type _cloud2beam(cloud_type flavour)
{
if (flavour == CLOUD_RANDOM)
return BEAM_RANDOM;
return clouds[flavour].beam_effect;
}
#ifdef ASSERTS
static bool _killer_whose_match(kill_category whose, killer_type killer)
{
switch (whose)
{
case KC_YOU:
return killer == KILL_YOU_MISSILE || killer == KILL_YOU_CONF;
case KC_FRIENDLY:
return killer == KILL_MON_MISSILE || killer == KILL_YOU_CONF
|| killer == KILL_MON;
case KC_OTHER:
return killer == KILL_MON_MISSILE || killer == KILL_MISCAST
|| killer == KILL_MISC || killer == KILL_MON;
case KC_NCATEGORIES:
die("kill category not matching killer type");
}
return false;
}
#endif
static void _los_cloud_changed(const coord_def& p, cloud_type t)
{
if (is_opaque_cloud_type(t))
los_terrain_changed(p);
}
static void _new_cloud(int cloud, cloud_type type, const coord_def& p,
int decay, kill_category whose, killer_type killer,
mid_t source, uint8_t spread_rate, int colour,
string name, string tile, int excl_rad)
{
ASSERT(env.cloud[cloud].type == CLOUD_NONE);
ASSERT(_killer_whose_match(whose, killer));
cloud_struct& c = env.cloud[cloud];
if (type == CLOUD_RANDOM_SMOKE)
type = random_smoke_type();
c.type = type;
c.decay = decay;
c.pos = p;
c.whose = whose;
c.killer = killer;
c.source = source;
c.spread_rate = spread_rate;
c.colour = colour;
c.name = name;
c.excl_rad = excl_rad;
if (!tile.empty())
{
tileidx_t index;
if (!tile_main_index(tile.c_str(), &index))
{
mprf(MSGCH_ERROR, "Invalid tile requested for cloud: '%s'.", tile.c_str());
tile = "";
}
}
c.tile = tile;
env.cgrid(p) = cloud;
env.cloud_no++;
_los_cloud_changed(p, type);
}
static void _place_new_cloud(cloud_type cltype, const coord_def& p, int decay,
kill_category whose, killer_type killer,
mid_t source,
int spread_rate = -1, int colour = -1,
string name = "",
string tile = "", int excl_rad = -1)
{
if (env.cloud_no >= MAX_CLOUDS)
return;
ASSERT(!cell_is_solid(p));
// Find slot for cloud.
for (int ci = 0; ci < MAX_CLOUDS; ci++)
{
if (env.cloud[ci].type == CLOUD_NONE) // i.e., is empty
{
_new_cloud(ci, cltype, p, decay, whose, killer, source, spread_rate,
colour, name, tile, excl_rad);
break;
}
}
}
static int _spread_cloud(const cloud_struct &cloud)
{
const int spreadch = cloud.decay > 30 ? 80 :
cloud.decay > 20 ? 50 :
30;
int extra_decay = 0;
for (adjacent_iterator ai(cloud.pos); ai; ++ai)
{
if (random2(100) >= spreadch)
continue;
if (!in_bounds(*ai)
|| env.cgrid(*ai) != EMPTY_CLOUD
|| cell_is_solid(*ai)
|| is_sanctuary(*ai) && !is_harmless_cloud(cloud.type))
{
continue;
}
if (cloud.type == CLOUD_INK && !feat_is_watery(grd(*ai)))
continue;
int newdecay = cloud.decay / 2 + 1;
if (newdecay >= cloud.decay)
newdecay = cloud.decay - 1;
_place_new_cloud(cloud.type, *ai, newdecay, cloud.whose, cloud.killer,
cloud.source, cloud.spread_rate, cloud.colour,
cloud.name, cloud.tile, cloud.excl_rad);
extra_decay += 8;
}
return extra_decay;
}
static void _spread_fire(const cloud_struct &cloud)
{
int make_flames = one_chance_in(5);
for (adjacent_iterator ai(cloud.pos); ai; ++ai)
{
if (!in_bounds(*ai)
|| env.cgrid(*ai) != EMPTY_CLOUD
|| is_sanctuary(*ai))
{
continue;
}
// burning trees produce flames all around
if (!cell_is_solid(*ai) && make_flames)
{
_place_new_cloud(CLOUD_FIRE, *ai, cloud.decay/2+1, cloud.whose,
cloud.killer, cloud.source, cloud.spread_rate,
cloud.colour, cloud.name, cloud.tile, cloud.excl_rad);
}
// forest fire doesn't spread in all directions at once,
// every neighbouring square gets a separate roll
if (!feat_is_tree(grd(*ai)) || x_chance_in_y(19, 20))
continue;
if (env.markers.property_at(*ai, MAT_ANY, "veto_fire") == "veto")
continue;
if (you.see_cell(*ai))
mpr("The forest fire spreads!");
destroy_wall(*ai);
_place_new_cloud(cloud.type, *ai, random2(30)+25, cloud.whose,
cloud.killer, cloud.source, cloud.spread_rate,
cloud.colour, cloud.name, cloud.tile, cloud.excl_rad);
if (cloud.whose == KC_YOU)
{
did_god_conduct(DID_KILL_PLANT, 1);
did_god_conduct(DID_FIRE, 6);
}
else if (cloud.whose == KC_FRIENDLY && !crawl_state.game_is_arena())
did_god_conduct(DID_KILL_PLANT, 1);
}
}
static void _cloud_interacts_with_terrain(const cloud_struct &cloud)
{
if (cloud.type != CLOUD_FIRE && cloud.type != CLOUD_FOREST_FIRE)
return;
for (adjacent_iterator ai(cloud.pos); ai; ++ai)
{
const coord_def p(*ai);
if (in_bounds(p)
&& feat_is_watery(grd(p))
&& !cell_is_solid(p)
&& env.cgrid(p) == EMPTY_CLOUD
&& one_chance_in(7))
{
_place_new_cloud(CLOUD_STEAM, p, cloud.decay / 2 + 1,
cloud.whose, cloud.killer, cloud.source, 22);
}
}
}
/**
* How fast should a given cloud fade away this turn?
*
* @param cloud_idx The cloud in question.
* @return The rate at which the cloud's "decay" should decrease
* this turn.
*/
static int _cloud_dissipation_rate(const cloud_struct &cloud)
{
int dissipate = you.time_taken;
// If a player-created cloud is out of LOS, it dissipates much faster.
if (cloud.source == MID_PLAYER && !you.see_cell_no_trans(cloud.pos))
dissipate *= 4;
switch (cloud.type)
{
// Fire clouds dissipate faster over water.
case CLOUD_FIRE:
case CLOUD_FOREST_FIRE:
if (feat_is_watery(grd(cloud.pos)))
return dissipate * 4;
break;
// rain and cold clouds dissipate faster over lava.
case CLOUD_COLD:
case CLOUD_RAIN:
case CLOUD_STORM:
if (grd(cloud.pos) == DNGN_LAVA)
return dissipate * 4;
break;
// Ink cloud shouldn't appear outside of water.
case CLOUD_INK:
if (!feat_is_watery(grd(cloud.pos)))
return dissipate * 40;
break;
default:
break;
}
return dissipate;
}
static void _dissipate_cloud(int cloudidx)
{
cloud_struct &cloud = env.cloud[cloudidx];
// Apply calculated rate to the actual cloud.
cloud.decay -= _cloud_dissipation_rate(cloud);
if (cloud.type == CLOUD_FOREST_FIRE)
_spread_fire(cloud);
else if (x_chance_in_y(cloud.spread_rate, 100))
{
cloud.spread_rate -= div_rand_round(cloud.spread_rate, 10);
cloud.decay -= _spread_cloud(cloud);
}
// Check for total dissipation and handle accordingly.
if (cloud.decay < 1)
delete_cloud(cloudidx);
}
static void _handle_spectral_cloud(const cloud_struct& cloud)
{
if (actor_at(cloud.pos) || !actor_by_mid(cloud.source))
return;
int countn = 0;
for (distance_iterator di(cloud.pos, false, false, 2); di; ++di)
{
if (monster_at(*di) && monster_at(*di)->type == MONS_SPECTRAL_THING)
countn++;
}
int rate[5] = {650, 175, 45, 20, 0};
int chance = rate[(min(4, countn))];
if (!x_chance_in_y(chance, you.time_taken * 600))
return;
monster_type basetype =
random_choose_weighted(4, MONS_ANACONDA,
6, MONS_HYDRA,
3, MONS_SNAPPING_TURTLE,
2, MONS_ALLIGATOR_SNAPPING_TURTLE,
100, RANDOM_MONSTER,
0);
if (basetype == RANDOM_MONSTER && one_chance_in(4))
{
do
{
basetype = pick_random_zombie();
}
while (mons_class_flag(basetype, M_NO_GEN_DERIVED)
|| !monster_habitable_grid(basetype, grd(cloud.pos)));
}
monster* agent = monster_by_mid(cloud.source);
create_monster(mgen_data(MONS_SPECTRAL_THING,
(cloud.whose == KC_OTHER ?
BEH_HOSTILE :
BEH_FRIENDLY),
actor_by_mid(cloud.source), 1,
SPELL_SPECTRAL_CLOUD, cloud.pos,
(agent ? agent->foe : MHITYOU), MG_FORCE_PLACE,
GOD_NO_GOD, basetype));
}
void manage_clouds()
{
for (int i = 0; i < MAX_CLOUDS; ++i)
{
cloud_struct& cloud = env.cloud[i];
if (cloud.type == CLOUD_NONE)
continue;
#ifdef ASSERTS
if (cell_is_solid(cloud.pos))
{
die("cloud %s in %s at (%d,%d)", cloud_type_name(cloud.type).c_str(),
dungeon_feature_name(grd(cloud.pos)), cloud.pos.x, cloud.pos.y);
}
#endif
// This was initially 40, but that was far too spammy.
if (cloud.type == CLOUD_STORM
&& x_chance_in_y(you.time_taken, 400) && !actor_at(cloud.pos))
{
const bool you_see = you.see_cell(cloud.pos);
if (you_see && !you_worship(GOD_QAZLAL))
mpr("Lightning arcs down from a storm cloud!");
noisy(spell_effect_noise(SPELL_LIGHTNING_BOLT), cloud.pos,
you_see || you_worship(GOD_QAZLAL) ? nullptr
: "You hear a mighty clap of thunder!");
}
else if (cloud.type == CLOUD_SPECTRAL)
_handle_spectral_cloud(cloud);
_cloud_interacts_with_terrain(cloud);
_dissipate_cloud(i);
}
}
static void _maybe_leave_water(const cloud_struct& c)
{
ASSERT_IN_BOUNDS(c.pos);
// Rain clouds can occasionally leave shallow water or deepen it:
// If we're near lava, chance of leaving water is lower;
// if we're near deep water already, chance of leaving water
// is slightly higher.
if (!one_chance_in((5 + count_neighbours(c.pos, DNGN_LAVA)) -
count_neighbours(c.pos, DNGN_DEEP_WATER)))
{
return;
}
dungeon_feature_type feat = grd(c.pos);
if (grd(c.pos) == DNGN_FLOOR)
feat = DNGN_SHALLOW_WATER;
else if (grd(c.pos) == DNGN_SHALLOW_WATER && you.pos() != c.pos
&& one_chance_in(3) && !crawl_state.game_is_sprint())
{
// Don't drown the player!
feat = DNGN_DEEP_WATER;
}
if (grd(c.pos) != feat)
{
if (you.pos() == c.pos && you.ground_level())
mpr("The rain has left you waist-deep in water!");
temp_change_terrain(c.pos, feat, random_range(500, 1000),
TERRAIN_CHANGE_FLOOD);
}
}
void delete_cloud_at(coord_def p)
{
const int cloudno = env.cgrid(p);
if (cloudno != EMPTY_CLOUD)
delete_cloud(cloudno);
}
void delete_cloud(int cloud)
{
cloud_struct& c = env.cloud[cloud];
if (c.type == CLOUD_NONE)
return;
cloud_type t = c.type;
if (c.type == CLOUD_RAIN)
_maybe_leave_water(c);
c.type = CLOUD_NONE;
c.decay = 0;
c.whose = KC_OTHER;
c.killer = KILL_NONE;
c.spread_rate = 0;
c.colour = -1;
c.name = "";
c.tile = "";
env.cgrid(c.pos) = EMPTY_CLOUD;
_los_cloud_changed(c.pos, t);
c.pos.reset();
env.cloud_no--;
}
void move_cloud_to(coord_def src, coord_def dst)
{
const int cloudno = env.cgrid(src);
move_cloud(cloudno, dst);
}
// The current use of this function is for shifting in the abyss, so
// that clouds get moved along with the rest of the map.
void move_cloud(int cloud, const coord_def& newpos)
{
ASSERT(!cell_is_solid(newpos));
if (cloud == EMPTY_CLOUD)
return;
const coord_def oldpos = env.cloud[cloud].pos;
env.cgrid(oldpos) = EMPTY_CLOUD;
env.cgrid(newpos) = cloud;
env.cloud[cloud].pos = newpos;
_los_cloud_changed(oldpos, env.cloud[cloud].type);
_los_cloud_changed(newpos, env.cloud[cloud].type);
}
#if 0
static void _validate_clouds()
{
for (rectangle_iterator ri(0); ri; ri++)
{
int c = env.cgrid(*ri);
if (c == EMPTY_CLOUD)
continue;
ASSERT(env.cloud[c].pos == *ri);
}
for (int c = 0; c < MAX_CLOUDS; c++)
if (env.cloud[c].type != CLOUD_NONE)
ASSERT(env.cgrid(env.cloud[c].pos) == c);
}
#endif
void swap_clouds(coord_def p1, coord_def p2)
{
if (p1 == p2)
return;
int c1 = env.cgrid(p1);
int c2 = env.cgrid(p2);
bool affects_los = false;
if (c1 != EMPTY_CLOUD)
{
env.cloud[c1].pos = p2;
if (is_opaque_cloud(env.cloud[c1].type))
affects_los = true;
}
if (c2 != EMPTY_CLOUD)
{
env.cloud[c2].pos = p1;
if (is_opaque_cloud(env.cloud[c2].type))
affects_los = true;
}
env.cgrid(p1) = c2;
env.cgrid(p2) = c1;
if (affects_los)
{
los_terrain_changed(p1);
los_terrain_changed(p2);
}
}
// Places a cloud with the given stats assuming one doesn't already
// exist at that point.
void check_place_cloud(cloud_type cl_type, const coord_def& p, int lifetime,
const actor *agent, int spread_rate, int colour,
string name, string tile, int excl_rad)
{
if (!in_bounds(p) || env.cgrid(p) != EMPTY_CLOUD)
return;
if (cl_type == CLOUD_INK && !feat_is_watery(grd(p)))
return;
place_cloud(cl_type, p, lifetime, agent, spread_rate, colour, name, tile,
excl_rad);
}
static bool _is_weak_cloud(int cl)
{
if (cl == EMPTY_CLOUD)
return true;
cloud_struct& cloud = env.cloud[cl];
return cloud.type >= CLOUD_GREY_SMOKE && cloud.type <= CLOUD_STEAM
|| cloud.type == CLOUD_BLACK_SMOKE
|| cloud.type == CLOUD_MIST
|| cloud.decay <= 20; // soon gone
}
static bool cloud_is_stronger(cloud_type ct, int cl)
{
if (_is_weak_cloud(cl))
return true;
cloud_struct& cloud = env.cloud[cl];
if (ct == CLOUD_POISON && cloud.type == CLOUD_MEPHITIC)
return true; // allow upgrading meph
if (ct == CLOUD_TORNADO)
return true; // visual/AI only
return false;
}
// Places a cloud with the given stats. May delete old clouds to
// make way if there are too many on level. Will overwrite an old
// cloud under some circumstances.
void place_cloud(cloud_type cl_type, const coord_def& ctarget, int cl_range,
const actor *agent, int _spread_rate, int colour,
string name, string tile, int excl_rad)
{
if (is_sanctuary(ctarget) && !is_harmless_cloud(cl_type))
return;
if (cl_type == CLOUD_INK && !feat_is_watery(grd(ctarget)))
return;
ASSERT(!cell_is_solid(ctarget));
kill_category whose = KC_OTHER;
killer_type killer = KILL_MISC;
mid_t source = MID_NOBODY;
if (agent && agent->is_player())
whose = KC_YOU, killer = KILL_YOU_MISSILE, source = MID_PLAYER;
else if (agent && agent->is_monster())
{
if (agent->as_monster()->friendly())
whose = KC_FRIENDLY;
else
whose = KC_OTHER;
killer = KILL_MON_MISSILE;
source = agent->mid;
}
int cl_new = -1;
const int target_cgrid = env.cgrid(ctarget);
if (target_cgrid != EMPTY_CLOUD)
{
// There's already a cloud here. See if we can overwrite it.
if (cloud_is_stronger(cl_type, target_cgrid))
{
// Delete this cloud and replace it.
cl_new = target_cgrid;
delete_cloud(target_cgrid);
}
else // Guess not.
return;
}
const int spread_rate = _actual_spread_rate(cl_type, _spread_rate);
// Too many clouds.
if (env.cloud_no >= MAX_CLOUDS)
{
// Default to random in case there's no low quality clouds.
int cl_del = random2(MAX_CLOUDS);
for (int ci = 0; ci < MAX_CLOUDS; ci++)
if (_is_weak_cloud(ci))
{
cl_del = ci;
break;
}
delete_cloud(cl_del);
cl_new = cl_del;
}
// Create new cloud.
if (cl_new != -1)
{
_new_cloud(cl_new, cl_type, ctarget, cl_range * 10,
whose, killer, source, spread_rate, colour, name, tile,
excl_rad);
return;
}
// Find slot for cloud.
for (int ci = 0; ci < MAX_CLOUDS; ci++)
{
if (env.cloud[ci].type == CLOUD_NONE) // ie is empty
{
_new_cloud(ci, cl_type, ctarget, cl_range * 10, whose, killer,
source, spread_rate, colour, name, tile, excl_rad);
break;
}
}
}
bool is_opaque_cloud_type(cloud_type ctype)
{
return ctype >= CLOUD_OPAQUE_FIRST && ctype <= CLOUD_OPAQUE_LAST;
}
bool is_opaque_cloud(int cloud_idx)
{
if (cloud_idx == EMPTY_CLOUD)
return false;
return is_opaque_cloud_type(env.cloud[cloud_idx].type);
}
cloud_type cloud_type_at(const coord_def &c)
{
const int cloudno = env.cgrid(c);
return cloudno == EMPTY_CLOUD ? CLOUD_NONE
: env.cloud[cloudno].type;
}
bool cloud_is_yours_at(const coord_def &pos)
{
const int cloudidx = env.cgrid(pos);
return cloudidx != EMPTY_CLOUD && YOU_KILL(env.cloud[ cloudidx ].killer);
}
cloud_type random_smoke_type()
{
return random_choose(CLOUD_GREY_SMOKE, CLOUD_BLUE_SMOKE,
CLOUD_BLACK_SMOKE, CLOUD_PURPLE_SMOKE);
}
int max_cloud_damage(cloud_type cl_type, int power)
{
cloud_struct cloud;
cloud.type = cl_type;
cloud.decay = power * 10;
return _actor_cloud_damage(&you, cloud, true);
}
// Returns true if the cloud type has negative side effects beyond
// plain damage and inventory destruction effects.
static bool _cloud_has_negative_side_effects(cloud_type cloud)
{
switch (cloud)
{
case CLOUD_MEPHITIC:
case CLOUD_MIASMA:
case CLOUD_MUTAGENIC:
case CLOUD_CHAOS:
case CLOUD_PETRIFY:
case CLOUD_ACID:
case CLOUD_NEGATIVE_ENERGY:
return true;
default:
return false;
}
}
static int _cloud_damage_calc(int size, int n_average, int extra,
bool maximum_damage)
{
return maximum_damage?
extra + size - 1
: random2avg(size, n_average) + extra;
}
// Calculates the base damage that the cloud does to an actor without
// considering resistances and time spent in the cloud.
static int _cloud_base_damage(const actor *act,
const cloud_struct &cloud,
bool maximum_damage)
{
switch (cloud.type)
{
case CLOUD_RAIN:
// Only applies to fiery actors: see _actor_cloud_resist.
return _cloud_damage_calc(9, 1, 0, maximum_damage);
case CLOUD_FIRE:
case CLOUD_FOREST_FIRE:
case CLOUD_COLD:
case CLOUD_HOLY_FLAMES:
case CLOUD_ACID:
case CLOUD_NEGATIVE_ENERGY:
// Yes, we really hate players, damn their guts.
//
// XXX: Some superior way of linking cloud damage to cloud
// power would be nice, so we can dispense with these hacky
// special cases.
if (act->is_player())
return _cloud_damage_calc(23, 3, 10, maximum_damage);
else
return _cloud_damage_calc(16, 3, 6, maximum_damage);
case CLOUD_STORM:
// Four times the damage, because it's a quarter as often.
if (act->is_player())
return _cloud_damage_calc(92, 3, 40, maximum_damage);
else
return _cloud_damage_calc(64, 3, 24, maximum_damage);
case CLOUD_MEPHITIC:
return _cloud_damage_calc(3, 1, 0, maximum_damage);
case CLOUD_POISON:
return _cloud_damage_calc(10, 1, 0, maximum_damage);
case CLOUD_MIASMA:
return _cloud_damage_calc(12, 3, 0, maximum_damage);
case CLOUD_STEAM:
return _cloud_damage_calc(16, 2, 0, maximum_damage);
case CLOUD_SPECTRAL:
return _cloud_damage_calc(15, 3, 4, maximum_damage);
default:
return 0;
}
}
// Returns true if the actor is immune to cloud damage, inventory item
// destruction, and all other cloud-type-specific side effects (i.e.
// apart from cloud interaction with invisibility).
//
// Note that actor_cloud_immune may be false even if the actor will
// not be harmed by the cloud. The cloud may have positive
// side-effects on the actor.
bool actor_cloud_immune(const actor *act, const cloud_struct &cloud)
{
if (is_harmless_cloud(cloud.type))
return true;
const bool player = act->is_player();
if (!player
&& (you_worship(GOD_FEDHAS)
&& fedhas_protects(act->as_monster())
|| testbits(act->as_monster()->flags, MF_DEMONIC_GUARDIAN))
&& (cloud.whose == KC_YOU || cloud.whose == KC_FRIENDLY)
&& (act->as_monster()->friendly() || act->as_monster()->neutral()))
{
return true;
}
// Qazlalites get immunity to their own clouds.
if (player && YOU_KILL(cloud.killer) && in_good_standing(GOD_QAZLAL))
return true;
#if TAG_MAJOR_VERSION == 34
if (player && you.species == SP_DJINNI
&& (cloud.type == CLOUD_FIRE
|| cloud.type == CLOUD_FOREST_FIRE
|| cloud.type == CLOUD_HOLY_FLAMES))
{
return true;
}
#endif
switch (cloud.type)
{
case CLOUD_FIRE:
case CLOUD_FOREST_FIRE:
if (!player)
return act->res_fire() >= 3;
return you.duration[DUR_FIRE_SHIELD]
|| you.mutation[MUT_FLAME_CLOUD_IMMUNITY];
case CLOUD_HOLY_FLAMES:
return act->res_holy_energy(cloud.agent()) > 0;
case CLOUD_COLD:
if (!player)
return act->res_cold() >= 3;
return you.mutation[MUT_FREEZING_CLOUD_IMMUNITY];
case CLOUD_MEPHITIC:
return act->res_poison() > 0 || act->is_unbreathing();
case CLOUD_POISON:
return act->res_poison() > 0;
case CLOUD_STEAM:
return act->res_steam() > 0;