代码拉取完成,页面将自动刷新
#include "Building.h"
#include "config.h"
#include "GameMap.h"
Building::Building()
{
shape.name = NONE;
state = TickableStatus::EMPTY;
running_ms = 0;
timer.Reset();
}
Building::Building(GridVec _pos, int _name, int _direction)
{
pos = _pos;
name = _name;
direction = _direction;
shape.name = NONE;
state = TickableStatus::EMPTY;
running_ms = 0;
timer.Reset();
}
bool Building::operator==(const Building &b) const
{
return (pos.i == b.pos.i && pos.j == b.pos.j);
}
bool Building::operator!=(const Building &b) const
{
return !(this == &b);
}
bool Building::IsPlace(const GridVec &click, int picdirection, GameMap &gamemap)
{
// miner重载
// 如果超出地图范围,返回false
if (click.i < 0 || click.i >= GameInfo::HEIGHT || click.j < 0 || click.j >= GameInfo::WIDTH)
{
return false;
}
// 如果在矿地上,或有障碍物,返回false
if (gamemap.GetResource(click))
{
return false;
}
// 如果有其他建筑,返回false
std::vector<GridVec> allpos = BuildingAllPos();
for (auto pos : allpos)
{
if (gamemap.GetBuilding(pos))
{
return false;
}
}
return true;
}
bool Building::CanSend(GridVec source, int directionout, int shapename, GameMap &map)
{
// TODO
if (name == BuildingType::HUB || name == BuildingType::TRASH)
{
return false;
}
GridVec target = map.GetTatget(source, directionout);
if (target.i < 0 || target.i >= GameInfo::HEIGHT || target.j < 0 || target.j >= GameInfo::WIDTH)
{
return false;
}
if (map.GetBuilding(target) == nullptr)
{
return false;
}
if (map.GetBuilding(target)->CanReceive(target, directionout, shapename))
{
return true;
}
return false;
}
void Building::Send(GridVec source, int directionout, int shapename, GameMap &map)
{
// TODO
GridVec target = map.GetTatget(source, directionout);
map.GetBuilding(target)->Receive(target, directionout, shapename);
shape.name = NONE;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。