<commit_before>#include "game/city/scenery.h"
#include "game/city/building.h"
#include "framework/logger.h"
#include "game/tileview/tileobject_scenery.h"
#include "game/rules/scenerytiledef.h"
#include "game/gamestate.h"
#include "game/tileview/tile.h"
#include "game/city/city.h"
#include "framework/framework.h"

namespace OpenApoc
{
Scenery::Scenery(SceneryTileDef &tileDef, Vec3<int> pos, sp<Building> bld)
    : tileDef(tileDef), pos(pos), building(bld), damaged(false), falling(false)
{
}

void Scenery::handleCollision(GameState &state, Collision &c)
{
	// FIXME: Proper damage
	//
	// If this tile has a damaged tile, replace it with that. If it's already damaged, destroy as
	// normal
	if (this->falling)
	{
		// Already falling, just continue
		return;
	}
	if (!this->damaged && tileDef.getDamagedTile())
	{
		this->damaged = true;
		return;
	}
	// Don't destroy bottom tiles, else everything will leak out
	if (this->pos.z == 0)
	{
		return;
	}
	this->tileObject->removeFromMap();
	this->tileObject.reset();
	for (auto &s : this->supports)
		s->collapse(state);
}

void Scenery::collapse(GameState &state)
{
	// IF it's already falling or destroyed do nothing
	if (this->falling || !this->tileObject)
		return;

	this->falling = true;

	auto ret = state.city->fallingScenery.insert(shared_from_this());
	if (ret.second == false)
	{
		LogError("Scenery object already in fallingSenery list?");<commit_msg>Don't destroy landing pads, collapse supported stuff when damaged<commit_after>#include "game/city/scenery.h"
#include "game/city/building.h"
#include "framework/logger.h"
#include "game/tileview/tileobject_scenery.h"
#include "game/rules/scenerytiledef.h"
#include "game/gamestate.h"
#include "game/tileview/tile.h"
#include "game/city/city.h"
#include "framework/framework.h"

namespace OpenApoc
{
Scenery::Scenery(SceneryTileDef &tileDef, Vec3<int> pos, sp<Building> bld)
    : tileDef(tileDef), pos(pos), building(bld), damaged(false), falling(false)
{
}

void Scenery::handleCollision(GameState &state, Collision &c)
{
	// FIXME: Proper damage
	//
	// If this tile has a damaged tile, replace it with that. If it's already damaged, destroy as
	// normal
	if (this->falling)
	{
		// Already falling, just continue
		return;
	}
	// Landing pads are immortal (else this completely destroys pathing)
	if (this->tileDef.getIsLandingPad())
	{
		return;
	}
	if (!this->damaged && tileDef.getDamagedTile())
	{
		this->damaged = true;
	}
	else
	{
		// Don't destroy bottom tiles, else everything will leak out
		if (this->pos.z != 0)
		{
			this->tileObject->removeFromMap();
			this->tileObject.reset();
		}
	}
	for (auto &s : this->supports)
		s->collapse(state);
}

void Scenery::collapse(GameState &state)
{
	// IF it's already falling or destroyed do nothing
	if (this->falling || !this->tileObject)
		return;
	// Landing pads can't collapse, and may magically float, otherwise it screws up pathing (same
	// reason why they can't be destroyed when hit)
	if (this->tileDef.getIsLandingPad())
		return;
	this->falling = true;

	auto ret = state.city->fallingScenery.insert(shared_from_this());
	if (ret.second == false)
	{
		LogError("Scenery object already in fallingSenery list?");
{'fraction_non_alphanumeric': 0.14504532666458267, 'fraction_numerical': 0.0012503907471084713, 'mean_word_length': 4.47008547008547, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4784427', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1126, 'n_words': 281}