@@ -100,12 +100,19 @@ void TileEngine::calculateSunShading(Tile *tile)
100100 // At night/dusk sun isn't dropping shades blocked by roofs
101101 if (_save->getGlobalShade () <= 4 )
102102 {
103- if (verticalBlockage (_save->getTile (Position (tile->getPosition ().x , tile->getPosition ().y , _save->getMapSizeZ () - 1 )), tile, DT_NONE ))
103+ int block = 0 ;
104+ int x = tile->getPosition ().x ;
105+ int y = tile->getPosition ().y ;
106+ for (int z = _save->getMapSizeZ ()-1 ; z > tile->getPosition ().z ; z--)
107+ {
108+ block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , DT_NONE );
109+ block += blockage (_save->getTile (Position (x, y, z)), MapData::O_OBJECT , DT_NONE , Pathfinding::DIR_DOWN );
110+ }
111+ if (block>0 )
104112 {
105113 power -= 2 ;
106114 }
107115 }
108-
109116 tile->addLight (power, layer);
110117}
111118
@@ -1090,6 +1097,8 @@ BattleUnit *TileEngine::hit(const Position ¢er, int power, ItemDamageType ty
10901097 return bu;
10911098}
10921099
1100+ static unsigned char expmap[14400 ];
1101+
10931102/* *
10941103 * Handles explosions.
10951104 *
@@ -1293,21 +1302,26 @@ void TileEngine::explode(const Position ¢er, int power, ItemDamageType type,
12931302
12941303 // blockage by terrain is deducted from the explosion power
12951304 power_ -= 10 ; // explosive damage decreases by 10 per tile
1296- if (origin->getPosition ().z != tileZ) power_ -= vertdec; // 3d explosion factor
1305+ if (origin->getPosition ().z != tileZ)
1306+ power_ -= vertdec; // 3d explosion factor
1307+
12971308 if (type == DT_IN )
12981309 {
12991310 int dir;
13001311 Pathfinding::vectorToDirection (origin->getPosition () - dest->getPosition (), dir);
13011312 if (dir != -1 && dir %2 ) power_ -= 5 ; // diagonal movement costs an extra 50% for fire.
13021313 }
1303- if (l>1.1 ) power_-= (horizontalBlockage (origin, dest, type) + verticalBlockage (origin, dest, type)) * 2 ;
1314+ if (l>0.5 ) power_-= horizontalBlockage (origin, dest, type, l<1.5 ) * 2 ;
1315+ if (l>0.5 ) power_-= verticalBlockage (origin, dest, type, l<1.5 ) * 2 ;
13041316 }
13051317 }
13061318 }
13071319 // now detonate the tiles affected with HE
13081320
13091321 if (type == DT_HE )
13101322 {
1323+ for (int i=0 ;i<14400 ;i++) expmap[i]=0 ;
1324+
13111325 for (std::set<Tile*>::iterator i = tilesAffected.begin (); i != tilesAffected.end (); ++i)
13121326 {
13131327 if (detonate (*i))
@@ -1317,6 +1331,11 @@ void TileEngine::explode(const Position ¢er, int power, ItemDamageType type,
13171331 if (j)
13181332 applyGravity (j);
13191333 }
1334+
1335+ FILE *ptr_fp;
1336+ ptr_fp = fopen (" test.txt" , " wb" );
1337+ fwrite (expmap, 14400 , 1 , ptr_fp);
1338+ fclose (ptr_fp);
13201339 }
13211340
13221341 calculateSunShading (); // roofs could have been destroyed
@@ -1334,12 +1353,12 @@ bool TileEngine::detonate(Tile* tile)
13341353{
13351354 int explosive = tile->getExplosive ();
13361355 if (explosive == 0 ) return false ; // no damage applied for this tile
1337-
13381356 tile->setExplosive (0 ,true );
13391357 bool objective = false ;
13401358 Tile* tiles[9 ];
13411359 static const int parts[9 ]={0 ,1 ,2 ,0 ,1 ,2 ,3 ,3 ,3 }; // 6th is the object of current
13421360 Position pos = tile->getPosition ();
1361+ expmap[pos.z *60 *60 +pos.y *60 +pos.x ] = explosive;
13431362
13441363 tiles[0 ] = _save->getTile (Position (pos.x , pos.y , pos.z +1 )); // ceiling
13451364 tiles[1 ] = _save->getTile (Position (pos.x +1 , pos.y , pos.z )); // east wall
@@ -1352,16 +1371,18 @@ bool TileEngine::detonate(Tile* tile)
13521371// tile->setSmoke(std::max(1, std::min(tile->getSmoke() + RNG::generate(0,2), 15)));
13531372
13541373 int remainingPower, fireProof, fuel;
1355- bool destroyed, bigwalldestroyed = true ;
1374+ bool destroyed, bigwalldestroyed = true , skipnorthwest = false ;
13561375 for (int i = 8 ; i >=0 ; --i)
13571376 {
13581377 if (!tiles[i] || !tiles[i]->getMapData (parts[i]))
13591378 continue ; // skip out of map and emptiness
13601379 int bigwall = tiles[i]->getMapData (parts[i])->getBigWall ();
13611380 if (i > 6 && !( (bigwall==1 ) || (bigwall==8 ) || (i==8 && bigwall==6 ) || (i==7 && bigwall==7 )))
13621381 continue ;
1363- if (!bigwalldestroyed && parts[i]==0 ) // when ground shouldn't be destroyed
1382+ if ((bigwall!=0 )) skipnorthwest = true ;
1383+ if (!bigwalldestroyed && i<6 ) // when ground shouldn't be destroyed
13641384 continue ;
1385+ if (skipnorthwest && (i == 2 || i == 1 )) continue ;
13651386 remainingPower = explosive;
13661387 destroyed = false ;
13671388 int volume = 0 ;
@@ -1454,13 +1475,12 @@ Tile *TileEngine::checkForTerrainExplosions()
14541475
14551476/* *
14561477 * Calculates the amount of power that is blocked going from one tile to another on a different level.
1457- * Can cross more than one level. Only floor tiles are taken into account.
14581478 * @param startTile The tile where the power starts.
14591479 * @param endTile The adjacent tile where the power ends.
14601480 * @param type The type of power/damage.
14611481 * @return Amount of blockage of this power.
14621482 */
1463- int TileEngine::verticalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type)
1483+ int TileEngine::verticalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type, bool skipObject )
14641484{
14651485 int block = 0 ;
14661486
@@ -1472,45 +1492,38 @@ int TileEngine::verticalBlockage(Tile *startTile, Tile *endTile, ItemDamageType
14721492
14731493 int x = startTile->getPosition ().x ;
14741494 int y = startTile->getPosition ().y ;
1495+ int z = startTile->getPosition ().z ;
14751496
14761497 if (direction < 0 ) // down
14771498 {
1478- for (int z = startTile->getPosition ().z ; z > endTile->getPosition ().z ; z--)
1479- {
1480- block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1499+ block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1500+ if (!skipObject)
14811501 block += blockage (_save->getTile (Position (x, y, z)), MapData::O_OBJECT , type, Pathfinding::DIR_DOWN );
1482- }
14831502 if (x != endTile->getPosition ().x || y != endTile->getPosition ().y )
14841503 {
14851504 x = endTile->getPosition ().x ;
14861505 y = endTile->getPosition ().y ;
14871506 int z = startTile->getPosition ().z ;
1488- block += horizontalBlockage (startTile, _save->getTile (Position (x, y, z)), type);
1489- for (; z > endTile->getPosition ().z ; z--)
1490- {
1491- block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1507+ block += horizontalBlockage (startTile, _save->getTile (Position (x, y, z)), type, skipObject);
1508+ block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1509+ if (!skipObject)
14921510 block += blockage (_save->getTile (Position (x, y, z)), MapData::O_OBJECT , type);
1493- }
14941511 }
14951512 }
14961513 else if (direction > 0 ) // up
14971514 {
1498- for (int z = startTile->getPosition ().z + 1 ; z <= endTile->getPosition ().z ; z++)
1499- {
1500- block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1501- block += blockage (_save->getTile (Position (x, y, z)), MapData::O_OBJECT , type, Pathfinding::DIR_UP );
1502- }
1515+ block += blockage (_save->getTile (Position (x, y, z+1 )), MapData::O_FLOOR , type);
1516+ if (!skipObject)
1517+ block += blockage (_save->getTile (Position (x, y, z+1 )), MapData::O_OBJECT , type, Pathfinding::DIR_UP );
15031518 if (x != endTile->getPosition ().x || y != endTile->getPosition ().y )
15041519 {
15051520 x = endTile->getPosition ().x ;
15061521 y = endTile->getPosition ().y ;
1507- int z = startTile->getPosition ().z ;
1508- block += horizontalBlockage (startTile, _save->getTile (Position (x, y, z)), type);
1509- for (z = startTile->getPosition ().z + 1 ; z <= endTile->getPosition ().z ; z++)
1510- {
1511- block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1522+ int z = startTile->getPosition ().z +1 ;
1523+ block += horizontalBlockage (startTile, _save->getTile (Position (x, y, z)), type, skipObject);
1524+ block += blockage (_save->getTile (Position (x, y, z)), MapData::O_FLOOR , type);
1525+ if (!skipObject)
15121526 block += blockage (_save->getTile (Position (x, y, z)), MapData::O_OBJECT , type);
1513- }
15141527 }
15151528 }
15161529
@@ -1524,7 +1537,7 @@ int TileEngine::verticalBlockage(Tile *startTile, Tile *endTile, ItemDamageType
15241537 * @param type The type of power/damage.
15251538 * @return Amount of blockage.
15261539 */
1527- int TileEngine::horizontalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type)
1540+ int TileEngine::horizontalBlockage (Tile *startTile, Tile *endTile, ItemDamageType type, bool skipObject )
15281541{
15291542 static const Position oneTileNorth = Position (0 , -1 , 0 );
15301543 static const Position oneTileEast = Position (1 , 0 , 0 );
@@ -1636,6 +1649,8 @@ int TileEngine::horizontalBlockage(Tile *startTile, Tile *endTile, ItemDamageTyp
16361649 break ;
16371650 }
16381651
1652+ if (skipObject) return block; //
1653+
16391654 block += blockage (startTile,MapData::O_OBJECT , type, direction);
16401655 if (type != DT_NONE )
16411656 {
0 commit comments