1
This commit is contained in:
parent
120d97c1b0
commit
167d9b6fac
@ -39,7 +39,7 @@ void Incubator::AllocAndroid(Human* target, int num)
|
|||||||
Human* hum = hold_humans_[0];
|
Human* hum = hold_humans_[0];
|
||||||
a8::Vec2 old_pos = hum->GetPos();
|
a8::Vec2 old_pos = hum->GetPos();
|
||||||
hum->SetPos(target->GetPos() + dir * (MetaMgr::Instance()->incubator_base_length + rand_len));
|
hum->SetPos(target->GetPos() + dir * (MetaMgr::Instance()->incubator_base_length + rand_len));
|
||||||
if (hum->CollisonDetection() || !CanSet(hum, target)) {
|
if (hum->CollisonDetection() || !CanSee(hum, target)) {
|
||||||
hum->SetPos(old_pos);
|
hum->SetPos(old_pos);
|
||||||
} else {
|
} else {
|
||||||
room->EnableHuman(hum);
|
room->EnableHuman(hum);
|
||||||
@ -125,7 +125,7 @@ void Incubator::RecycleAndroid(Human* hum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Incubator::CanSet(Human* hum, Human* exclude_hum)
|
bool Incubator::CanSee(Human* hum, Human* exclude_hum)
|
||||||
{
|
{
|
||||||
Human* target = hum;
|
Human* target = hum;
|
||||||
bool can_set = true;
|
bool can_set = true;
|
||||||
@ -184,3 +184,34 @@ void Incubator::AutoAllocAndroid()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Incubator::ActiveAndroid(Human* hum, Human* android)
|
||||||
|
{
|
||||||
|
a8::Vec2 center = room->GetGasData().pos_new;
|
||||||
|
float start_distance = a8::RandEx(200, 600);
|
||||||
|
a8::Vec2 start_dir = a8::Vec2::UP;
|
||||||
|
start_dir.Rotate(a8::RandAngle());
|
||||||
|
|
||||||
|
android->SetPos(hum->GetPos());
|
||||||
|
int try_count = 0;
|
||||||
|
while (++try_count < 100) {
|
||||||
|
android->SetPos(center + start_dir * start_distance);
|
||||||
|
if (android->CollisonDetection() && !CanSee(android, hum)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
room->EnableHuman(android);
|
||||||
|
for (auto itr = hold_humans_.begin(); itr != hold_humans_.end(); ++itr) {
|
||||||
|
if (*itr == android) {
|
||||||
|
hold_humans_.erase(itr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
room->BroadcastDebugMsg(a8::Format("active android id:%d pos:%d,%d",
|
||||||
|
{
|
||||||
|
android->GetUniId(),
|
||||||
|
android->GetPos().x,
|
||||||
|
android->GetPos().y
|
||||||
|
}));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -13,9 +13,10 @@ class Incubator
|
|||||||
void UnInit();
|
void UnInit();
|
||||||
void AllocAndroid(Human* target, int num);
|
void AllocAndroid(Human* target, int num);
|
||||||
void RecycleAndroid(Human* hum);
|
void RecycleAndroid(Human* hum);
|
||||||
|
void ActiveAndroid(Human* hum, Human* android);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool CanSet(Human* hum, Human* exclude_hum);
|
bool CanSee(Human* hum, Human* exclude_hum);
|
||||||
void AutoAllocAndroid();
|
void AutoAllocAndroid();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1393,15 +1393,35 @@ void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg)
|
|||||||
|
|
||||||
void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
|
void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
|
||||||
{
|
{
|
||||||
cs::SMWatchWar respmsg;
|
if (watch_war_req_timer_) {
|
||||||
Human* target = room->GetWatchWarTarget(this);
|
return;
|
||||||
if (target) {
|
|
||||||
SendNotifyMsg(respmsg);
|
|
||||||
hdr.hum->FollowTarget(target);
|
|
||||||
} else {
|
|
||||||
respmsg.set_error_code(1);
|
|
||||||
SendNotifyMsg(respmsg);
|
|
||||||
}
|
}
|
||||||
|
auto cb =
|
||||||
|
[] (const a8::XParams& param) {
|
||||||
|
#if 0
|
||||||
|
cs::SMWatchWar respmsg;
|
||||||
|
Human* target = room->GetWatchWarTarget(this);
|
||||||
|
if (target) {
|
||||||
|
SendNotifyMsg(respmsg);
|
||||||
|
hdr.hum->FollowTarget(target);
|
||||||
|
} else {
|
||||||
|
respmsg.set_error_code(1);
|
||||||
|
SendNotifyMsg(respmsg);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
watch_war_req_timer_ = room->xtimer.AddDeadLineTimerAndAttach
|
||||||
|
(
|
||||||
|
NEXT_FRAME_TIMER,
|
||||||
|
a8::XParams()
|
||||||
|
.SetSender(this),
|
||||||
|
cb,
|
||||||
|
&xtimer_attacher.timer_list_,
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
Player* hum = (Player*)param.sender.GetUserData();
|
||||||
|
hum->watch_war_req_timer_ = nullptr;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::_CMLeave(f8::MsgHdr& hdr, const cs::CMLeave& msg)
|
void Player::_CMLeave(f8::MsgHdr& hdr, const cs::CMLeave& msg)
|
||||||
|
@ -17,6 +17,7 @@ namespace cs
|
|||||||
class Room;
|
class Room;
|
||||||
class Loot;
|
class Loot;
|
||||||
class Obstacle;
|
class Obstacle;
|
||||||
|
struct xtimer_list;
|
||||||
class Player : public Human
|
class Player : public Human
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -134,6 +135,7 @@ private:
|
|||||||
std::map<int, std::vector<std::tuple<int, int, int>>> box_hash_;
|
std::map<int, std::vector<std::tuple<int, int, int>>> box_hash_;
|
||||||
std::set<int> receved_box_hash_;
|
std::set<int> receved_box_hash_;
|
||||||
long long last_cmmove_frameno_ = 0;
|
long long last_cmmove_frameno_ = 0;
|
||||||
|
xtimer_list* watch_war_req_timer_ = nullptr;
|
||||||
|
|
||||||
friend class EntityFactory;
|
friend class EntityFactory;
|
||||||
};
|
};
|
||||||
|
@ -923,6 +923,7 @@ Human* Room::GetWatchWarTarget(Human* hum)
|
|||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Human*> players;
|
std::vector<Human*> players;
|
||||||
std::vector<Human*> humans;
|
std::vector<Human*> humans;
|
||||||
for (auto& pair : human_hash_) {
|
for (auto& pair : human_hash_) {
|
||||||
@ -934,15 +935,17 @@ Human* Room::GetWatchWarTarget(Human* hum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Human* target = nullptr;
|
||||||
if (!players.empty()) {
|
if (!players.empty()) {
|
||||||
Human* target = players[rand() % players.size()];
|
target = players[rand() % players.size()];
|
||||||
return target;
|
} else if (!humans.empty()) {
|
||||||
|
target = humans[rand() % humans.size()];
|
||||||
}
|
}
|
||||||
if (!humans.empty()) {
|
if (target && target->IsAndroid() && a8::HasBitFlag(target->status, CS_Disable)) {
|
||||||
Human* target = humans[rand() % humans.size()];
|
incubator_->ActiveAndroid(hum, target);
|
||||||
return target;
|
|
||||||
}
|
}
|
||||||
return nullptr;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Room::BattleStarted()
|
bool Room::BattleStarted()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user