1 Star 0 Fork 0

Mrack/ MyShapez

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
building.cpp 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
Mrack 提交于 2024-06-25 19:23 . 111111
#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;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/stucky/MyShapez-new.git
[email protected]:stucky/MyShapez-new.git
stucky
MyShapez-new
MyShapez
master

搜索帮助