1
This commit is contained in:
parent
db1bb9b4a8
commit
8a5388d30e
@ -828,6 +828,9 @@ void Bullet::GetHitCreatures(BulletCheckResult& result)
|
||||
AabbCollider aabb_box;
|
||||
c->GetHitAabbBox(aabb_box);
|
||||
if (c != sender.Get() && !c->dead && TestCollision(room, &aabb_box)) {
|
||||
#ifdef DEBUG
|
||||
a8::XPrintf("bullet hit\n", {});
|
||||
#endif
|
||||
if (meta->_inventory_slot() == IS_C4) {
|
||||
if (!c->IsHuman()) {
|
||||
result.objects.insert(c);
|
||||
|
@ -7,18 +7,15 @@
|
||||
#include "car.h"
|
||||
#include "hero.h"
|
||||
#include "creature.h"
|
||||
#include "bullet.h"
|
||||
#include "global.h"
|
||||
|
||||
GridCell::GridCell()
|
||||
{
|
||||
entitys_.reserve(MAX_ROOM_IDX);
|
||||
creatures_.reserve(MAX_ROOM_IDX);
|
||||
bullets_.reserve(MAX_ROOM_IDX);
|
||||
for (int i = 0; i < MAX_ROOM_IDX; ++i) {
|
||||
entitys_.push_back(std::set<Entity*>());
|
||||
creatures_.push_back(std::set<Creature*>());
|
||||
bullets_.push_back(std::set<Bullet*>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,13 +141,3 @@ bool GridCell::CreatureExists(Creature* c)
|
||||
{
|
||||
return creatures_[c->room->GetRoomIdx()].find(c) != creatures_[c->room->GetRoomIdx()].end();
|
||||
}
|
||||
|
||||
void GridCell::AddBullet(Bullet* bullet)
|
||||
{
|
||||
bullets_[bullet->room->GetRoomIdx()].insert(bullet);
|
||||
}
|
||||
|
||||
void GridCell::RemoveBullet(Bullet* bullet)
|
||||
{
|
||||
bullets_[bullet->room->GetRoomIdx()].erase(bullet);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
class Entity;
|
||||
class Human;
|
||||
class Bullet;
|
||||
class Room;
|
||||
class Creature;
|
||||
|
||||
@ -23,8 +22,6 @@ public:
|
||||
void AddCreature(Creature* c);
|
||||
void RemoveCreature(Creature* c);
|
||||
bool CreatureExists(Creature* c);
|
||||
void AddBullet(Bullet* bullet);
|
||||
void RemoveBullet(Bullet* bullet);
|
||||
void AddPermanentEntity(Entity* entity);
|
||||
void AddRoomEntity(Room* room, Entity* entity);
|
||||
void RemoveRoomEntity(Room* room, Entity* entity);
|
||||
@ -41,5 +38,4 @@ public:
|
||||
private:
|
||||
std::vector<std::set<Entity*>> entitys_;
|
||||
std::vector<std::set<Creature*>> creatures_;
|
||||
std::vector<std::set<Bullet*>> bullets_;
|
||||
};
|
||||
|
@ -117,7 +117,7 @@ void GridService::ClearRoomData(Room* room)
|
||||
void GridService::AddCreature(Creature* c)
|
||||
{
|
||||
int x = (int)c->GetPos().GetX() + cell_width_;
|
||||
int y = (int)c->GetPos().GetY() + cell_width_;
|
||||
int y = (int)c->GetPos().GetZ() + cell_width_;
|
||||
if (BroderOverFlow(x, y)) {
|
||||
A8_ABORT();
|
||||
}
|
||||
@ -138,7 +138,7 @@ void GridService::RemoveCreature(Creature* c)
|
||||
void GridService::MoveCreature(Creature* c)
|
||||
{
|
||||
int new_x = (int)c->GetPos().GetX() + cell_width_;
|
||||
int new_y = (int)c->GetPos().GetY() + cell_width_;
|
||||
int new_y = (int)c->GetPos().GetZ() + cell_width_;
|
||||
int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_;
|
||||
if (BroderOverFlow(new_x, new_y)) {
|
||||
A8_ABORT();
|
||||
@ -167,7 +167,7 @@ void GridService::AddRoomEntity(Room* room, Entity* entity)
|
||||
{
|
||||
assert(!entity->IsEntityType(ET_Player));
|
||||
int x = (int)entity->GetPos().GetX() + cell_width_;
|
||||
int y = (int)entity->GetPos().GetY() + cell_width_;
|
||||
int y = (int)entity->GetPos().GetZ() + cell_width_;
|
||||
if (BroderOverFlow(x, y)) {
|
||||
A8_ABORT();
|
||||
}
|
||||
@ -188,7 +188,7 @@ void GridService::AddPermanentEntity(Entity* entity)
|
||||
{
|
||||
assert(!entity->IsEntityType(ET_Player));
|
||||
int x = (int)entity->GetPos().GetX() + cell_width_;
|
||||
int y = (int)entity->GetPos().GetY() + cell_width_;
|
||||
int y = (int)entity->GetPos().GetZ() + cell_width_;
|
||||
if (BroderOverFlow(x, y)) {
|
||||
A8_ABORT();
|
||||
}
|
||||
@ -375,25 +375,10 @@ void GridService::DeatchHuman(Human* target)
|
||||
target->GetGridList().clear();
|
||||
}
|
||||
|
||||
void GridService::AddBullet(Bullet* bullet)
|
||||
{
|
||||
int x = (int)bullet->GetPos().GetX() + cell_width_;
|
||||
int y = (int)bullet->GetPos().GetY() + cell_width_;
|
||||
if (BroderOverFlow(x, y)) {
|
||||
A8_ABORT();
|
||||
}
|
||||
bullet->SetGridId(x/cell_width_ + (y/cell_width_) * cell_count_per_row_);
|
||||
if (bullet->GetGridId() == 0 || bullet->GetGridId() > max_grid_id_) {
|
||||
A8_ABORT();
|
||||
}
|
||||
cells_[bullet->GetGridId()].AddBullet(bullet);
|
||||
GetAllCells(bullet->room, bullet->GetGridId(), bullet->GetGridList());
|
||||
}
|
||||
|
||||
void GridService::MoveBullet(Bullet* bullet)
|
||||
{
|
||||
int new_x = (int)bullet->GetPos().GetX() + cell_width_;
|
||||
int new_y = (int)bullet->GetPos().GetY() + cell_width_;
|
||||
int new_y = (int)bullet->GetPos().GetZ() + cell_width_;
|
||||
int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_;
|
||||
if (BroderOverFlow(new_x, new_y)) {
|
||||
A8_ABORT();
|
||||
@ -411,14 +396,6 @@ void GridService::MoveBullet(Bullet* bullet)
|
||||
bullet->GetGridList(),
|
||||
inc_grid_list,
|
||||
dec_grid_list);
|
||||
cells_[bullet->GetGridId()].RemoveBullet(bullet);
|
||||
cells_[new_grid_id].AddBullet(bullet);
|
||||
bullet->SetGridId(new_grid_id);
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::DelBullet(Bullet* bullet)
|
||||
{
|
||||
GridCell& cell = cells_[bullet->GetGridId()];
|
||||
cell.RemoveBullet(bullet);
|
||||
}
|
||||
|
@ -24,9 +24,7 @@ class GridService
|
||||
void RemoveCreature(Creature* c);
|
||||
void MoveCreature(Creature* c);
|
||||
|
||||
void AddBullet(Bullet* bullet);
|
||||
void MoveBullet(Bullet* bullet);
|
||||
void DelBullet(Bullet* bullet);
|
||||
|
||||
void AddRoomEntity(Room* room, Entity* entity);
|
||||
void DelRoomEntity(Room* room, Entity* entity);
|
||||
|
Loading…
x
Reference in New Issue
Block a user