add AllocSeat function
This commit is contained in:
parent
b8c85a3959
commit
2b379e1055
@ -5,20 +5,21 @@
|
||||
#include "room.h"
|
||||
#include "metamgr.h"
|
||||
#include "loot.h"
|
||||
#include "perfmonitor.h"
|
||||
|
||||
Car::Car()
|
||||
Car::Car():MoveableEntity()
|
||||
{
|
||||
|
||||
++PerfMonitor::Instance()->entity_num[ET_Car];
|
||||
}
|
||||
|
||||
Car::~Car()
|
||||
{
|
||||
|
||||
--PerfMonitor::Instance()->entity_num[ET_Car];
|
||||
}
|
||||
|
||||
void Car::Initialize()
|
||||
{
|
||||
|
||||
MoveableEntity::Initialize();
|
||||
}
|
||||
|
||||
void Car::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
|
||||
@ -95,11 +96,16 @@ void Car::GetOn(Human* passenger)
|
||||
return;
|
||||
}
|
||||
}
|
||||
int seat = AllocSeat();
|
||||
if (seat < 0) {
|
||||
return;
|
||||
}
|
||||
passengers_.insert(passenger);
|
||||
if (!driver_) {
|
||||
driver_ = passenger;
|
||||
}
|
||||
passenger->SetCar(this);
|
||||
passenger->SetSeat(seat);
|
||||
passenger->SetPos(GetPos());
|
||||
{
|
||||
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff
|
||||
@ -118,3 +124,22 @@ void Car::GetOn(Human* passenger)
|
||||
room->frame_event.AddCarChg(passenger);
|
||||
SyncAroundPlayers(__FILE__, __LINE__, __func__);
|
||||
}
|
||||
|
||||
int Car::AllocSeat()
|
||||
{
|
||||
int seat = -1;
|
||||
for (int i = 0; i < meta->int_param2; ++i) {
|
||||
bool found = false;
|
||||
for (auto hum : passengers_) {
|
||||
if (hum->GetSeat() == i) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
seat = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return seat;
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ class Car : public MoveableEntity
|
||||
void GetDown(Human* passenger);
|
||||
void GetOn(Human* passenger);
|
||||
|
||||
private:
|
||||
int AllocSeat();
|
||||
|
||||
private:
|
||||
bool later_removed_ = false;
|
||||
Human* driver_ = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user