Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1.  
  2. namespace
  3. {
  4.  
  5. struct BrainAI:
  6.     public BrainLandGenericAI<Zombi>
  7. {
  8.     float cooldown = 0.f;
  9.     float invoke_cooldown = 60.f;
  10.     float hide_cooldown = 120.f;
  11.     bool  is_lead;
  12.    
  13.     BrainAI(od::Sizeu size, bool is_lead):
  14.         BrainLandGenericAI<Zombi>(size), is_lead(is_lead) {}
  15.    
  16.     void update(const Zombi& ins, Input& inputs, float dt) override {
  17.         cooldown -= dt;
  18.         updateAI(ins, inputs, dt);
  19.        
  20.         if(is_lead) {
  21.             invoke_cooldown -= dt;
  22.             hide_cooldown -= dt;
  23.            
  24.             if(invoke_cooldown <= 0.f) {
  25.                 if(ins.state() == Zombi::TakeOut) {
  26.                     invoke_cooldown = 60.f * 30;
  27.                     hide_cooldown = 60.f * 15;
  28.                 }
  29.                 else if(ins.state() == Zombi::Dig) {
  30.                     inputs.simulateCheck(Input::MouseLeft);
  31.                 }
  32.                 else {
  33.                     inputs.simulateCheck(Input::Action1);
  34.                 }
  35.             }
  36.             else if(hide_cooldown <= 0.f) {
  37.                 if(ins.state() == Zombi::Hidden) {
  38.                     hide_cooldown = 60.f * 15;
  39.                     inputs.simulateCheck(Input::Space);
  40.                 }
  41.                 else if(ins.state() != Zombi::Dig) {
  42.                     inputs.simulateCheck(Input::Action1);
  43.                 }
  44.             }
  45.         }
  46.     }
  47.    
  48.     bool tryToAttack(const Zombi& ins, const Focus& focus, Input& inputs) override {
  49.        
  50.         float dist = focus.distanceTo(ins);
  51.         bool facing = false;
  52.         const bool expert = false;
  53.        
  54.         const od::Rect& box1 = ins.boundingBox();
  55.         od::Rect box2 = focus.box;
  56.        
  57.         if(ins.facingx() > 0.f)
  58.             facing = box1.x2 <= box2.x1;
  59.         else
  60.             facing = box1.x1 >= box2.x2;
  61.        
  62.         float vsep  = std::abs(box1.center().y - box2.center().y);
  63.         float scale = ins.size() + 1;
  64.        
  65.         if(facing && focus.canBeHit(ins.hitbox(ins.Attack)))
  66.         {
  67.             inputs.simulateCheck(Input::MouseLeft);
  68.             return true;
  69.         }
  70.         else if(cooldown <= 0
  71.              && facing
  72.              && focus.canBeHit(ins.hitbox(ins.AttackAlt)))
  73.         {
  74.             inputs.simulateCheck(Input::MouseLeft);
  75.             inputs.simulateCheck(Input::Down);
  76.             cooldown = 600;
  77.             return true;
  78.         }
  79.         else if(dist < 160 * scale
  80.              && vsep < 32 * scale
  81.              && Rand()(0.f, 1.f) < 0.001f * (1 + int(expert)*10))
  82.         {
  83.             inputs.simulateCheck(Input::Space);
  84.             inputs.simulateCheck(Input::Shift);
  85.             return true;
  86.         }
  87. //        else if(mad) {
  88. //            inputs.simulateCheck(Input::Space);
  89. //            inputs.simulateCheck(Input::Shift);
  90. //        }
  91.         return false;
  92.     }
  93. };
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement