Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace
- {
- struct BrainAI:
- public BrainLandGenericAI<Zombi>
- {
- float cooldown = 0.f;
- float invoke_cooldown = 60.f;
- float hide_cooldown = 120.f;
- bool is_lead;
- BrainAI(od::Sizeu size, bool is_lead):
- BrainLandGenericAI<Zombi>(size), is_lead(is_lead) {}
- void update(const Zombi& ins, Input& inputs, float dt) override {
- cooldown -= dt;
- updateAI(ins, inputs, dt);
- if(is_lead) {
- invoke_cooldown -= dt;
- hide_cooldown -= dt;
- if(invoke_cooldown <= 0.f) {
- if(ins.state() == Zombi::TakeOut) {
- invoke_cooldown = 60.f * 30;
- hide_cooldown = 60.f * 15;
- }
- else if(ins.state() == Zombi::Dig) {
- inputs.simulateCheck(Input::MouseLeft);
- }
- else {
- inputs.simulateCheck(Input::Action1);
- }
- }
- else if(hide_cooldown <= 0.f) {
- if(ins.state() == Zombi::Hidden) {
- hide_cooldown = 60.f * 15;
- inputs.simulateCheck(Input::Space);
- }
- else if(ins.state() != Zombi::Dig) {
- inputs.simulateCheck(Input::Action1);
- }
- }
- }
- }
- bool tryToAttack(const Zombi& ins, const Focus& focus, Input& inputs) override {
- float dist = focus.distanceTo(ins);
- bool facing = false;
- const bool expert = false;
- const od::Rect& box1 = ins.boundingBox();
- od::Rect box2 = focus.box;
- if(ins.facingx() > 0.f)
- facing = box1.x2 <= box2.x1;
- else
- facing = box1.x1 >= box2.x2;
- float vsep = std::abs(box1.center().y - box2.center().y);
- float scale = ins.size() + 1;
- if(facing && focus.canBeHit(ins.hitbox(ins.Attack)))
- {
- inputs.simulateCheck(Input::MouseLeft);
- return true;
- }
- else if(cooldown <= 0
- && facing
- && focus.canBeHit(ins.hitbox(ins.AttackAlt)))
- {
- inputs.simulateCheck(Input::MouseLeft);
- inputs.simulateCheck(Input::Down);
- cooldown = 600;
- return true;
- }
- else if(dist < 160 * scale
- && vsep < 32 * scale
- && Rand()(0.f, 1.f) < 0.001f * (1 + int(expert)*10))
- {
- inputs.simulateCheck(Input::Space);
- inputs.simulateCheck(Input::Shift);
- return true;
- }
- // else if(mad) {
- // inputs.simulateCheck(Input::Space);
- // inputs.simulateCheck(Input::Shift);
- // }
- return false;
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement