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];
|
||||
a8::Vec2 old_pos = hum->GetPos();
|
||||
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);
|
||||
} else {
|
||||
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;
|
||||
bool can_set = true;
|
||||
@ -184,3 +184,34 @@ void Incubator::AutoAllocAndroid()
|
||||
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 AllocAndroid(Human* target, int num);
|
||||
void RecycleAndroid(Human* hum);
|
||||
void ActiveAndroid(Human* hum, Human* android);
|
||||
|
||||
private:
|
||||
bool CanSet(Human* hum, Human* exclude_hum);
|
||||
bool CanSee(Human* hum, Human* exclude_hum);
|
||||
void AutoAllocAndroid();
|
||||
|
||||
private:
|
||||
|
@ -1393,6 +1393,12 @@ void Player::_CMGameOver(f8::MsgHdr& hdr, const cs::CMGameOver& msg)
|
||||
|
||||
void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
|
||||
{
|
||||
if (watch_war_req_timer_) {
|
||||
return;
|
||||
}
|
||||
auto cb =
|
||||
[] (const a8::XParams& param) {
|
||||
#if 0
|
||||
cs::SMWatchWar respmsg;
|
||||
Human* target = room->GetWatchWarTarget(this);
|
||||
if (target) {
|
||||
@ -1402,6 +1408,20 @@ void Player::_CMWatchWar(f8::MsgHdr& hdr, const cs::CMWatchWar& msg)
|
||||
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)
|
||||
|
@ -17,6 +17,7 @@ namespace cs
|
||||
class Room;
|
||||
class Loot;
|
||||
class Obstacle;
|
||||
struct xtimer_list;
|
||||
class Player : public Human
|
||||
{
|
||||
public:
|
||||
@ -134,6 +135,7 @@ private:
|
||||
std::map<int, std::vector<std::tuple<int, int, int>>> box_hash_;
|
||||
std::set<int> receved_box_hash_;
|
||||
long long last_cmmove_frameno_ = 0;
|
||||
xtimer_list* watch_war_req_timer_ = nullptr;
|
||||
|
||||
friend class EntityFactory;
|
||||
};
|
||||
|
@ -923,6 +923,7 @@ Human* Room::GetWatchWarTarget(Human* hum)
|
||||
return member;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Human*> players;
|
||||
std::vector<Human*> humans;
|
||||
for (auto& pair : human_hash_) {
|
||||
@ -934,15 +935,17 @@ Human* Room::GetWatchWarTarget(Human* hum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Human* target = nullptr;
|
||||
if (!players.empty()) {
|
||||
Human* target = players[rand() % players.size()];
|
||||
return target;
|
||||
target = players[rand() % players.size()];
|
||||
} else if (!humans.empty()) {
|
||||
target = humans[rand() % humans.size()];
|
||||
}
|
||||
if (!humans.empty()) {
|
||||
Human* target = humans[rand() % humans.size()];
|
||||
return target;
|
||||
if (target && target->IsAndroid() && a8::HasBitFlag(target->status, CS_Disable)) {
|
||||
incubator_->ActiveAndroid(hum, target);
|
||||
}
|
||||
return nullptr;
|
||||
return target;
|
||||
}
|
||||
|
||||
bool Room::BattleStarted()
|
||||
|
Loading…
x
Reference in New Issue
Block a user