Adjusted PXS code for cases of PXS-density > C4M_Solid (#944).

scancodes-fix
Sven Eberhardt 2013-03-30 14:05:12 +01:00
parent 749ddb09aa
commit 1f78ee3a88
2 changed files with 17 additions and 13 deletions

View File

@ -755,8 +755,7 @@ void C4Landscape::DrawMaterialRect(int32_t mat, int32_t tx, int32_t ty, int32_t
int32_t cx,cy;
for (cy=ty; cy<ty+hgt; cy++)
for (cx=tx; cx<tx+wdt; cx++)
if ( (MatDensity(mat)>GetDensity(cx,cy))
|| ((MatDensity(mat)==GetDensity(cx,cy)) && (MatDigFree(mat)<=MatDigFree(GetMat(cx,cy)))) )
if ( (MatDensity(mat)>=GetDensity(cx,cy)))
SetPix(cx,cy,Mat2PixColDefault(mat)+GBackIFT(cx,cy));
}
@ -792,7 +791,7 @@ bool C4Landscape::InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t
assert(tx); assert(ty);
int32_t mdens;
if (!MatValid(mat)) return false;
mdens=MatDensity(mat);
mdens=Min(MatDensity(mat), C4M_Solid);
if (!mdens) return true;
// Bounds
@ -810,7 +809,7 @@ bool C4Landscape::InsertMaterial(int32_t mat, int32_t *tx, int32_t *ty, int32_t
else
{
// Move up above same density
while (mdens==GetDensity(*tx,*ty))
while (mdens==Min(GetDensity(*tx,*ty),C4M_Solid))
{
(*ty)--; if (*ty<0) return false;
// Primitive slide (1)
@ -2144,14 +2143,14 @@ bool FindTunnelHeight(int32_t cx, int32_t &ry, int32_t hgt)
// Check upwards
if (cy1>=0)
{
if (GBackIFT(cx,cy1) && MatDensity(GBackMat(cx,cy1)) < 25)
if (GBackIFT(cx,cy1) && MatDensity(GBackMat(cx,cy1)) < C4M_Liquid)
{ rl1++; if (rl1>=hgt) { ry=cy1+hgt/2; return true; } }
else rl1=0;
}
// Check downwards
if (cy2+1<GBackHgt)
{
if (GBackIFT(cx,cy2) && MatDensity(GBackMat(cx,cy2)) < 25)
if (GBackIFT(cx,cy2) && MatDensity(GBackMat(cx,cy2)) < C4M_Liquid)
{ rl2++; if (rl2>=hgt) { ry=cy2-hgt/2; return true; } }
else rl2=0;
}
@ -2634,6 +2633,8 @@ bool ConstructionCheck(C4PropList * PropList, int32_t iX, int32_t iY, C4Object *
// Finds the next pixel position moving to desired slide.
bool C4Landscape::FindMatPath(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide)
{
assert(mdens<=C4M_Solid); // mdens normalized in InsertMaterial
int32_t cslide;
bool fLeft=true,fRight=true;
@ -2667,6 +2668,7 @@ bool C4Landscape::FindMatPath(int32_t &fx, int32_t &fy, int32_t ydir, int32_t md
// Finds the closest immediate slide position.
bool C4Landscape::FindMatSlide(int32_t &fx, int32_t &fy, int32_t ydir, int32_t mdens, int32_t mslide)
{
assert(mdens<=C4M_Solid); // mdens normalized in InsertMaterial and mrfInsertCheck
int32_t cslide;
bool fLeft=true,fRight=true;
@ -3120,8 +3122,7 @@ uint8_t *C4Landscape::GetBridgeMatConversion(int for_material)
conv_map = new uint8_t[256];
for (int32_t i=0; i<256; ++i)
{
if ( (MatDensity(for_material)>GetPixDensity(i))
|| ((MatDensity(for_material)==GetPixDensity(i)) && (MatDigFree(for_material)<=MatDigFree(GetPixMat(i)))) )
if ( (MatDensity(for_material)>=GetPixDensity(i)))
{
// bridge pixel OK here. change pixel; keep IFT.
conv_map[i] = (i & IFT) + Mat2PixColDefault(for_material);

View File

@ -502,8 +502,8 @@ bool C4MaterialMap::CrossMapMaterials(const char* szEarthMaterial) // Called aft
// natural stuff: material conversion here?
if (pMatPXS && pMatPXS->sInMatConvert.getLength() && SEqualNoCase(pMatPXS->sInMatConvert.getData(), pMatLS ? pMatLS->Name : C4TLS_MatSky))
pReaction = &DefReactConvert;
// the rest is happening for same/higher densities only
else if ((MatDensity(iMatPXS) <= MatDensity(iMatLS)) && pMatPXS && pMatLS)
// non-sky reactions
else if (pMatPXS && pMatLS)
{
// incindiary vs extinguisher
if ((pMatPXS->Incindiary && pMatLS->Extinguisher) || (pMatPXS->Extinguisher && pMatLS->Incindiary))
@ -514,8 +514,11 @@ bool C4MaterialMap::CrossMapMaterials(const char* szEarthMaterial) // Called aft
// corrosive vs corrode
else if (pMatPXS->Corrosive && pMatLS->Corrode)
pReaction = &DefReactCorrode;
// otherwise, when hitting same or higher density: Material insertion
else
// liquid hitting liquid or solid: Material insertion
else if (DensityLiquid(MatDensity(iMatPXS)) && DensitySemiSolid(MatDensity(iMatLS)))
pReaction = &DefReactInsert;
// solid hitting solid: Material insertion
else if (DensitySolid(MatDensity(iMatPXS)) && DensitySolid(MatDensity(iMatLS)))
pReaction = &DefReactInsert;
}
// assign the function; or NULL for no reaction
@ -813,7 +816,7 @@ bool mrfInsertCheck(int32_t &iX, int32_t &iY, C4Real &fXDir, C4Real &fYDir, int3
// Move by mat path/slide
int32_t iSlideX = iX, iSlideY = iY;
if (::Landscape.FindMatSlide(iSlideX,iSlideY,Sign(GravAccel),::MaterialMap.Map[iPxsMat].Density,::MaterialMap.Map[iPxsMat].MaxSlide))
if (::Landscape.FindMatSlide(iSlideX,iSlideY,Sign(GravAccel),Min(::MaterialMap.Map[iPxsMat].Density, C4M_Solid),::MaterialMap.Map[iPxsMat].MaxSlide))
{
if (iPxsMat == iLsMat)
{ iX = iSlideX; iY = iSlideY; fXDir = 0; return false; }