////////////////////////////////////////////////////////////////////////////////
//    Scorched3D (c) 2000-2011, 2026
//
//    This file is part of Scorched3D.
//
//    Scorched3D is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    Scorched3D is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along
//    with this program; if not, write to the Free Software Foundation, Inc.,
//    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
////////////////////////////////////////////////////////////////////////////////

#include <landscapemap/NapalmMap.hpp>
#include <common/DefinesAssert.hpp>
#include <memory.h>

NapalmMap::NapalmMap() : entries_( nullptr ) {}

NapalmMap::~NapalmMap()
{
	delete[] entries_;
	entries_ = nullptr;
}

fixed &NapalmMap::getNapalmHeight(int w, int h) 
{
	DIALOG_ASSERT(entries_);

	if ( 0 <= w && 0 <= h && w <= width_ && h <= height_ ) { return entries_[w + h * ( width_ + 1 )]; }

	static fixed tmp(1000);
	tmp = fixed(1000);
	return tmp;
}

void NapalmMap::create(int width, int height)
{
	width_ = width;
    height_ = height;
	delete [] entries_;

	entries_ = new fixed[(width_ + 1) * (height_ + 1)];
	clear();
}

void NapalmMap::clear()
{
	if (entries_)
	{
		memset(entries_, 0, sizeof(fixed) * (width_ + 1) * (height_ + 1));
	}
}
