Add syntax for drawing background materials with Map.c

lights3
Armin Burgmeier 2015-07-13 21:52:43 -04:00
parent 51986b68ef
commit 0d806fbcbf
2 changed files with 49 additions and 14 deletions

View File

@ -390,13 +390,18 @@ Blit({Algo=MAPALGO_Scale, OffX=Wdt/2, X=-100, Op=copy_layer});
<row>
<col>Sky</col>
<col>Sky</col>
<col>Draws a sky material. Within the map generator, explicit sky is drawn as IFT (0x80), which is converted to index zero on map drawing. That way, sky can be blitted to other layers without being transparent.</col>
<col>Draws a sky material. Within the map generator, explicit sky is drawn as index 0xff, which is converted to index zero on map drawing. That way, sky can be blitted to other layers without being transparent.</col>
</row>
<row>
<col>Transparent</col>
<col>Transparent</col>
<col>Draws with index 0.</col>
</row>
<row>
<col>FgMatTex:BgMatTex</col>
<col>Water:Tunnel-brickback</col>
<col>Draws with a specified background material. In the example, draws water which, when drained, exposes bricks instead of tunnel behind it. FgMatTex and BgMatTex can be any of the other specifications in this table, except the ones prefixed with ^. However, the specification FgMatTex:Sky is equivalent to ^FgMatTex.</col>
<row>
</table>
</text>
<h>Material-texture masks (string mask_spec)</h>

View File

@ -32,25 +32,55 @@ static const char *DrawFn_Background_Name = "Background";
static const char *DrawFn_Liquid_Name = "Liquid";
static const char *DrawFn_Solid_Name = "Solid";
bool TexColSingle(const char *mattex, uint8_t& col)
{
if (SEqual(mattex, DrawFn_Transparent_Name)) { col = 0; return true; }
if (SEqual(mattex, DrawFn_Sky_Name)) { col = C4M_MaxTexIndex; return true; }
col = ::MapScript.pTexMap->GetIndexMatTex(mattex);
if (col == 0) return false;
return true;
}
bool FnParTexCol(C4String *mattex, uint8_t& fg, uint8_t& bg)
{
// Return index of material-texture definition for a single color
// Defaults to underground (tunnel background) color. Prefix material with ^ to get overground (sky background) color.
// Defaults to underground (tunnel background) color. Prefix material with ^ to get overground (sky background) color,
// or specify as mattex1:mattex2 for foreground-background pair.
if (!mattex || !mattex->GetCStr()) return false;
if (mattex->GetData() == DrawFn_Transparent_Name) { fg = bg = 0; return true; }
if (mattex->GetData() == DrawFn_Sky_Name) {fg = bg = C4M_MaxTexIndex; return true; }
const char *cmattex = mattex->GetCStr();
bool ift = true;
if (*cmattex == '^') { ift=false; ++cmattex; }
uint8_t col = ::MapScript.pTexMap->GetIndexMatTex(cmattex);
if (col == 0) return false;
fg = col;
if (ift)
bg = ::MapScript.pTexMap->DefaultBkgMatTex(fg);
int sep_pos = SCharPos(':', mattex->GetCStr());
if (sep_pos == -1)
{
const char *cmattex = mattex->GetCStr();
bool ift = true;
if (*cmattex == '^') { ift=false; ++cmattex; }
uint8_t col;
if (!TexColSingle(cmattex, col)) return false;
fg = col;
if (ift)
bg = ::MapScript.pTexMap->DefaultBkgMatTex(fg);
else
bg = C4M_MaxTexIndex; // sky
return true;
}
else
bg = C4M_MaxTexIndex; // sky
return true;
{
const char *cmattex = mattex->GetCStr();
std::string fg_mattex(cmattex, cmattex + sep_pos);
std::string bg_mattex(cmattex + sep_pos + 1);
uint8_t fg_col, bg_col;
if (!TexColSingle(fg_mattex.c_str(), fg_col)) return false;
if (!TexColSingle(bg_mattex.c_str(), bg_col)) return false;
fg = fg_col; bg = bg_col;
return true;
}
}
void C4MapScriptMatTexMask::UnmaskSpec(C4String *spec)