Ejemplo n.º 1
0
//fixme: low walls not being replaced
//Replaces an existing object depending on the 2 tile heights
void CustomHouseDesign::AddOrReplace( CUSTOM_HOUSE_ELEMENT& elem )
{
    int floor_num = z_to_custom_house_table( elem.z );
    if ( floor_num == -1 )
        return;
    char adding_height = Core::tileheight( elem.graphic );

    u32 xidx = elem.xoffset + xoff;
    u32 yidx = elem.yoffset + yoff;
    if ( !ValidLocation( xidx, yidx ) )
        return;
    HouseFloorZColumn *column = &Elements[floor_num].data.at( xidx ).at( yidx );
    for ( HouseFloorZColumn::iterator itr = column->begin(),
            itrend = column->end();
            itr != itrend; ++itr )
    {
        char existing_height = Core::tileheight( itr->graphic );

        if ( ( ( existing_height == 0 ) && ( adding_height == 0 ) ) || //replace floor with floor
                ( ( existing_height != 0 ) && ( adding_height != 0 ) ) )  //or nonfloor with nonfloor

        {
            column->erase( itr );
            floor_sizes[floor_num]--;
            Add( elem );
            return;
        }
    }

    //no replacement, just add
    Add( elem );
}
Ejemplo n.º 2
0
bool CustomHouseDesign::Erase( u32 xoffset, u32 yoffset, u8 z, int minheight )
{
    int floor_num = z_to_custom_house_table( z );
    if ( floor_num == -1 )
        return false;

    u32 xidx = xoffset + xoff;
    u32 yidx = yoffset + yoff;
    if ( !ValidLocation( xidx, yidx ) )
        return false;

    HouseFloorZColumn *column = &Elements[floor_num].data.at( xidx ).at( yidx );
    for ( HouseFloorZColumn::iterator itr = column->begin(),
            itrend = column->end();
            itr != itrend; ++itr )
    {
        char height = Core::tileheight( itr->graphic );
        if ( ( itr->z == z ) && ( height >= minheight ) )
        {
            column->erase( itr );
            floor_sizes[floor_num]--;
            return true;
        }
    }
    return false;
}
Ejemplo n.º 3
0
inline Location Location::OfCoords (std::string coords) {
	ASSERT(ValidLocation(coords));
	uint x = coords[0] >= 'a' ? coords[0] - 'a' : coords[0] - 'A';
	uint y = coords[1] - '0';
	if (coords.size() > 2)
		y = y * 10 + coords[2] - '0';
	return Location(++x, y);
}
Ejemplo n.º 4
0
inline bool Location::ValidLocation(const std::string& location) {
	if (location.size() == 0 || location.size() > 3)
		return false;
	uint x = location[0] >= 'a' ? location[0] - 'a' : location[0] - 'A';
	uint y = location[1] - '0';
	if (location.size() > 2)
		y = y * 10 + location[2] - '0';
	return ValidLocation(++x, y);
}
Ejemplo n.º 5
0
void NavMgr::AddJump(const BrowseRecord &from, const BrowseRecord &to)
{
    if (ValidLocation(from)) {
        // keep previous location only if it's not at position 0, and it is not equal to from
        if (m_cur > 0 && !(m_jumps[m_cur].filename == from.filename && m_jumps[m_cur].lineno == from.lineno)) {
            m_cur++;
        }
        m_jumps.resize(m_cur);
        m_jumps.push_back(from);
    }
    if (ValidLocation(to)) {
        // only add if there's an actual jump
        if (!m_jumps.empty() && !(m_jumps[m_cur].filename == to.filename && m_jumps[m_cur].lineno == to.lineno)) {
            m_cur++;
            m_jumps.resize(m_cur);
            m_jumps.push_back(to);
        }
    }
}
Ejemplo n.º 6
0
void CustomHouseDesign::ReplaceDirtFloor( u32 x, u32 y )
{
    int floor_num = 1; //dirt always goes on floor 1 (z=7)

    if ( x + xoff == 0 || y + yoff == 0 || y + yoff == height ) //don't replace dirt at far-west and far-north sides, check height for y + 1
        return;

    bool floor_exists = false;

    u32 xidx = x + xoff;
    u32 yidx = y + yoff;
    if ( !ValidLocation( xidx, yidx ) )
        return;
    HouseFloorZColumn *column = &Elements[floor_num].data.at( xidx ).at( yidx );
    for ( HouseFloorZColumn::iterator itr = column->begin(),
            itrend = column->end();
            itr != itrend; ++itr )
    {
        if ( Core::tileheight( itr->graphic ) == 0 ) //a floor tile exists
        {
            floor_exists = true;
            break;
        }
    }

    if ( floor_exists == false ) //add a dirt tile
    {
        CUSTOM_HOUSE_ELEMENT elem;
        elem.graphic = DIRTY_TILE;
        elem.xoffset = x;
        elem.yoffset = y;
        elem.z = 7;

        Add( elem );
    }
}
Ejemplo n.º 7
0
bool CustomHouseDesign::EraseGraphicAt( u16 graphic, u32 xoffset, u32 yoffset, u8 z )
{
    int floor_num = z_to_custom_house_table( z );
    if ( floor_num == -1 )
        return false;

    u32 xidx = xoffset + xoff;
    u32 yidx = yoffset + yoff;
    if ( !ValidLocation( xidx, yidx ) )
        return false;
    HouseFloorZColumn *column = &Elements[floor_num].data.at( xidx ).at( yidx );
    for ( HouseFloorZColumn::iterator itr = column->begin(),
            itrend = column->end();
            itr != itrend; ++itr )
    {
        if ( itr->graphic == graphic )
        {
            column->erase( itr );
            floor_sizes[floor_num]--;
            return true;
        }
    }
    return false;
}
Ejemplo n.º 8
0
inline bool Location::ValidPosition(uint pos) {
	uint x, y;
	ToCoords(pos, x, y);
	return ValidLocation(x, y);
}
Ejemplo n.º 9
0
inline uint Location::ToTablePos(uint x, uint y) {
	ASSERT (ValidLocation(x, y));
	return y * (kBoardSizeAligned) + x;
}
Ejemplo n.º 10
0
inline uint Location::ToTablePos(uint x, uint y) {
	ASSERT (ValidLocation(x, y));
	return (y+kGuardsSize-1) * (kBoardSizeAligned) + x+ (kGuardsSize -1);
}
Ejemplo n.º 11
0
bool Location::ValidPosition(uint pos) {
    int x, y;
    Dim::ToCoords(pos, x, y);
    return ValidLocation(x, y);
}