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 57e68aaee9
commit 3957fac531
3 changed files with 17 additions and 6 deletions

@ -27,7 +27,7 @@ using df::global::gps;
using namespace DFHack; using namespace DFHack;
using df::coord2d; using df::coord2d;
const float levelDim=0.2f;
const float RootTwo = 1.4142135623730950488016887242097f; const float RootTwo = 1.4142135623730950488016887242097f;
rect2d getMapViewport() rect2d getMapViewport()
@ -572,21 +572,20 @@ void lightingEngineViewscreen::doOcupancyAndLights()
} }
if(df::global::cursor->x>-30000) if(df::global::cursor->x>-30000)
{ {
lightSource cursor(lightCell(0.96f,0.84f,0.03f),11);
cursor.flicker=false;
int wx=df::global::cursor->x-window_x+vp.first.x; int wx=df::global::cursor->x-window_x+vp.first.x;
int wy=df::global::cursor->y-window_y+vp.first.y; int wy=df::global::cursor->y-window_y+vp.first.y;
int tile=getIndex(wx,wy); int tile=getIndex(wx,wy);
applyMaterial(tile,matCursor); 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) for (int i=0;i<df::global::world->units.active.size();++i)
{ {
df::unit *u = df::global::world->units.active[i]; df::unit *u = df::global::world->units.active[i];
coord2d pos=worldToViewportCoord(coord2d(u->pos.x,u->pos.y),vp,window2d); coord2d pos=worldToViewportCoord(coord2d(u->pos.x,u->pos.y),vp,window2d);
if(u->pos.z==window_z && isInViewport(pos,vp)) if(u->pos.z==window_z && isInViewport(pos,vp))
if (DFHack::Units::isCitizen(u) && !u->counters.unconscious) if (DFHack::Units::isCitizen(u) && !u->counters.unconscious)
addLight(getIndex(pos.x,pos.y),citizen); addLight(getIndex(pos.x,pos.y),matCitizen.makeSource());
} }
//buildings //buildings
for(size_t i = 0; i < df::global::world->buildings.all.size(); i++) for(size_t i = 0; i < df::global::world->buildings.all.size(); i++)
@ -724,6 +723,10 @@ int lightingEngineViewscreen::parseSpecial(lua_State* L)
LOAD_SPECIAL(FROZEN_LIQUID,matIce); LOAD_SPECIAL(FROZEN_LIQUID,matIce);
LOAD_SPECIAL(AMBIENT,matAmbience); LOAD_SPECIAL(AMBIENT,matAmbience);
LOAD_SPECIAL(CURSOR,matCursor); 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; return 0;
} }
#undef LOAD_SPECIAL #undef LOAD_SPECIAL
@ -736,6 +739,8 @@ void lightingEngineViewscreen::defaultSettings()
matCursor=matLightDef(lightCell(0.96f,0.84f,0.03f),11); matCursor=matLightDef(lightCell(0.96f,0.84f,0.03f),11);
matCursor.flicker=true; matCursor.flicker=true;
matWall=matLightDef(lightCell(0,0,0)); matWall=matLightDef(lightCell(0,0,0));
matCitizen=matLightDef(lightCell(0.8f,0.8f,0.9f),6);
levelDim=0.2f;
} }
void lightingEngineViewscreen::loadSettings() void lightingEngineViewscreen::loadSettings()
{ {
@ -752,6 +757,7 @@ void lightingEngineViewscreen::loadSettings()
if(ret==LUA_ERRFILE) if(ret==LUA_ERRFILE)
{ {
out.printerr("File not found:%s\n",settingsfile.c_str()); out.printerr("File not found:%s\n",settingsfile.c_str());
lua_pop(s,1);
} }
else if(ret==LUA_ERRSYNTAX) else if(ret==LUA_ERRSYNTAX)
{ {
@ -775,6 +781,7 @@ void lightingEngineViewscreen::loadSettings()
Lua::SafeCall(out,s,2,0); Lua::SafeCall(out,s,2,0);
} }
} }
} }
catch(std::exception& e) catch(std::exception& e)

@ -111,7 +111,7 @@ struct matLightDef
bool flicker; bool flicker;
lightCell emitColor; lightCell emitColor;
int radius; 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), matLightDef(lightCell transparency,lightCell emit,int rad):isTransparent(true),isEmiting(true),
transparency(transparency),emitColor(emit),radius(rad){} transparency(transparency),emitColor(emit),radius(rad){}
matLightDef(lightCell emit,int rad):isTransparent(false),isEmiting(true),emitColor(emit),radius(rad),transparency(0,0,0){} matLightDef(lightCell emit,int rad):isTransparent(false),isEmiting(true),emitColor(emit),radius(rad),transparency(0,0,0){}
@ -173,6 +173,8 @@ private:
matLightDef matCursor; matLightDef matCursor;
matLightDef matWall; matLightDef matWall;
matLightDef matWater; matLightDef matWater;
matLightDef matCitizen;
float levelDim;
//materials //materials
std::map<std::pair<int,int>,matLightDef> matDefs; 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.FROZEN_LIQUID=makeMaterialDef({0.2,0.7,0.9}) -- ice
special.AMBIENT=makeMaterialDef({0.85,0.85,0.85}) --ambient fog 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.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 dragonfire
--TODO daylight --TODO daylight
--materials --materials