CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.59k stars 4.17k forks source link

Lots of light source problems #3002

Closed i2amroy closed 9 years ago

i2amroy commented 11 years ago

1) Even the weakest light sources generate a 3x3 square, ideally this should go down to a single square 2) Lit torches don't generate light while on the ground 3) PDA: flashlight doesn't generate light while on the ground 4) Candles only generate light while on the ground, they are worthless in your inventory

It seems like a new "luminance" system was started to be implemented, but never actually finished. Ideally we could convert everything over to something like this (maybe have things on the ground have luminance halved? that seems about what flashlights do right now). Hopefully that will remove all of these hardcodd inconsistencies that are present right now.

i2amroy commented 11 years ago

For the candle problem specifically I've managed to narrow the problem down to one of three commits. https://github.com/CleverRaven/Cataclysm-DDA/commit/28b1bb51ec2778b4337219062a1f7111d9e619c4 https://github.com/CleverRaven/Cataclysm-DDA/commit/910215c7a26a8d01bcc4cf0b2119b52a26ad85bf https://github.com/CleverRaven/Cataclysm-DDA/commit/662a977f2a47b233e025cc114edc9f1a8a5df552

atomicdryad commented 11 years ago

Afaik held items aren't iterated through in lightmap. player::active_light() is a horriblar mess that cheerfully sets it's own rules, while iterating through inventory for each of it's hardcoded items. It returns the luminance of brightest item.

The rules for flashlight etc allow them to dim based on charge, however; brightness = max(100, charges * 5); flashlight (max 100) has a linear dropoff at 20% batt firekatana (?!) has max 50 charges, so it has max 100 brightness and drops off at 40% mana or whatever

LIGHT_20 tag is why dropping a flashlight dims it. Candles do squat until you drop em because they're not in the function, and torches only work when held because they have no light tag.

I'm fiddling with it: Ripped out all special rules except cbm and teleglow, gave it generic logic for everything else. Flashlight as an example:

This would go into a bool item::light(float& bright, int & width, int & direction) function so player can figure out how bright it is, and map can use the same rules. (item.light.* would override for special cases like spotlights etc).

And this would be a possible benefit to a virtual base class for objects, since monsters have their own rules too, and the light_emission struct seems to cover everything. (And a swarm of spiderbots with mini spotlights would be....amusing at night)

As far as no single square lights, I'll try adding a special case for apply_light_source: <= 1 would just light the coordinate. <= 2 would become 1.5 or something, since there's a noticable difference between 1 and 2 but not 2 and 3

kevingranade commented 11 years ago

This is legacy stuff that hasn't been cleaned up yea. Everything on equal footing sounds great. What do you mean by a baseclass? One class that everything inherits from, or a class that handles lighting, an object of which is embedded in everything? The second we can shoehorn in as needed, the first would require a planned inheritance heirarchy and a kind of ridiculous amout of refactoring. I'm not saying I don't want to do it, but that needs a lot of up front planning, which we haven't done much of in the past.

kevingranade commented 10 years ago

I think these are sorted out, need to verify.

KA101 commented 10 years ago

Last data I had: the Atomic Nightlight puts out a 3x3 square when on the ground