Added citizen lights(only lights, no oclusion might change later). Added custom dim level (for darker nights and tunnels).

develop
Warmist 2013-06-25 19:34:38 +03:00
parent 13228855eb
commit 048395a2cd
3 changed files with 17 additions and 6 deletions

@ -27,7 +27,7 @@ using df::global::gps;
using namespace DFHack;
using df::coord2d;
const float levelDim=0.2f;
const float RootTwo = 1.4142135623730950488016887242097f;
lightSource::lightSource(lightCell power,int radius):power(power),flicker(false)
@ -605,21 +605,20 @@ void lightingEngineViewscreen::doOcupancyAndLights()
}
if(df::global::cursor->x>-30000)
{
//lightSource cursor(lightCell(9.6f,8.4f,0.3f),-1);
//cursor.flicker=false;
int wx=df::global::cursor->x-window_x+vp.first.x;
int wy=df::global::cursor->y-window_y+vp.first.y;
int tile=getIndex(wx,wy);
applyMaterial(tile,matCursor);
}
lightSource citizen(lightCell(0.80f,0.80f,0.90f),6);
//citizen only emit light, if defined
if(matCitizen.isEmiting)
for (int i=0;i<df::global::world->units.active.size();++i)
{
df::unit *u = df::global::world->units.active[i];
coord2d pos=worldToViewportCoord(coord2d(u->pos.x,u->pos.y),vp,window2d);
if(u->pos.z==window_z && isInViewport(pos,vp))
if (DFHack::Units::isCitizen(u) && !u->counters.unconscious)
addLight(getIndex(pos.x,pos.y),citizen);
addLight(getIndex(pos.x,pos.y),matCitizen.makeSource());
}
//buildings
for(size_t i = 0; i < df::global::world->buildings.all.size(); i++)
@ -757,6 +756,10 @@ int lightingEngineViewscreen::parseSpecial(lua_State* L)
LOAD_SPECIAL(FROZEN_LIQUID,matIce);
LOAD_SPECIAL(AMBIENT,matAmbience);
LOAD_SPECIAL(CURSOR,matCursor);
LOAD_SPECIAL(CITIZEN,matCitizen);
lua_getfield(L,-1,"LevelDim");
if(!lua_isnil(L,-1) && lua_isnumber(L,-1))engine->levelDim=lua_tonumber(L,-1);
lua_pop(L,1);
return 0;
}
#undef LOAD_SPECIAL
@ -769,6 +772,8 @@ void lightingEngineViewscreen::defaultSettings()
matCursor=matLightDef(lightCell(0.96f,0.84f,0.03f),11);
matCursor.flicker=true;
matWall=matLightDef(lightCell(0,0,0));
matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6);
levelDim=0.2f;
}
void lightingEngineViewscreen::loadSettings()
{
@ -785,6 +790,7 @@ void lightingEngineViewscreen::loadSettings()
if(ret==LUA_ERRFILE)
{
out.printerr("File not found:%s\n",settingsfile.c_str());
lua_pop(s,1);
}
else if(ret==LUA_ERRSYNTAX)
{
@ -808,6 +814,7 @@ void lightingEngineViewscreen::loadSettings()
Lua::SafeCall(out,s,2,0);
}
}
}
catch(std::exception& e)

@ -108,7 +108,7 @@ struct matLightDef
bool flicker;
lightCell emitColor;
int radius;
matLightDef(){}
matLightDef():isTransparent(false),isEmiting(false),transparency(0,0,0),emitColor(0,0,0),radius(0){}
matLightDef(lightCell transparency,lightCell emit,int rad):isTransparent(true),isEmiting(true),
transparency(transparency),emitColor(emit),radius(rad){}
matLightDef(lightCell emit,int rad):isTransparent(false),isEmiting(true),emitColor(emit),radius(rad),transparency(0,0,0){}
@ -170,6 +170,8 @@ private:
matLightDef matCursor;
matLightDef matWall;
matLightDef matWater;
matLightDef matCitizen;
float levelDim;
//materials
std::map<std::pair<int,int>,matLightDef> matDefs;

@ -49,6 +49,8 @@ special.WATER=makeMaterialDef({0.5,0.5,0.8})
special.FROZEN_LIQUID=makeMaterialDef({0.2,0.7,0.9}) -- ice
special.AMBIENT=makeMaterialDef({0.85,0.85,0.85}) --ambient fog
special.CURSOR=makeMaterialDef({1,1,1},{0.96,0.84,0.03},11, {"flicker"})
special.CITIZEN=makeMaterialDef(nil,{0.80f,0.80f,0.90f},6)
special.LevelDim=0.2 -- darkness. do not set to 0
--TODO dragonfire
--TODO daylight
--materials