7 float sqavg(float[] nums
) {
13 return pow(sum
, 1. / nums
.length
);
20 return sum
/ nums
.length
;
23 void do_colour(ref Map map
, list
!Being mons
) {
30 Lightcell
[][] base
= new Lightcell
[][](map_x
, map_y
);
31 const Lightmap umap
= mons
.front
.lightmap
;
34 if (!mon
.light_source
) {
38 auto loc
= Vector2n(mon
.lightmap
.top_edge
, mon
.lightmap
.left_edge
);
39 foreach (lightrow
; mon
.lightmap
.get_lights
) {
40 foreach (light
; lightrow
) {
41 if (light
.lit
&& umap
[loc
].visible
) {
42 base
[loc
.y
][loc
.x
].value
+= mon
.lightmap
[loc
].light
;
43 base
[loc
.y
][loc
.x
].nums
++;
44 base
[loc
.y
][loc
.x
].r
+= mon
.lightclr
.r
;
45 base
[loc
.y
][loc
.x
].g
+= mon
.lightclr
.g
;
46 base
[loc
.y
][loc
.x
].b
+= mon
.lightclr
.b
;
52 loc
.x
-= 1 + 2*mon
.fov_dist
;
56 foreach (y
; 0 .. map_y
) {
57 foreach (x
; 0 .. map_x
) {
58 if (base
[y
][x
].nums
== 0) {
59 map
[y
, x
].bgcolour
= RGBColour(0, 0, 0);
63 float f1
= pow(base
[y
][x
].value
, .8) / 4.3;
64 float f
= f1
/ (f1
+1); //smaxf;
65 // map[y, x].bgcolour = RGBColour(pow(f/2, 1.5), pow(f/1.4, 3), pow(f/16, 2));
66 //map[y, x].bgcolour = RGBColour(f*1.1, f, f/9);
67 with (base
[y
][x
]) map
[y
, x
].bgcolour
= RGBColour(cast(ubyte)(f
*r
/nums
), cast(ubyte)(f
*g
/nums
), cast(ubyte)(f
*b
/nums
)); //f*r/nums, f*g/nums, f*b/nums);
69 //writefln("Set bg to %s", map[y, x].bgcolour);