bool Soldier::update() { if (state == 'm') { if (update_location() == true) { state = 's'; return true; } else { return false; } } else if (state == 'x') { return false; } else if (state == 's') { return false; } else if (state == 'a') { if (cart_distance((*target).get_location(), get_location()) > range) { cout << "Target is out of range." << endl; state = 's'; return true; } if (cart_distance((*target).get_location(), get_location()) <= range) { if ((*target).is_alive() == true) { cout << "Take that!" << endl; (*target).take_hit(attack_strength, this); state = 'a'; return false; } else if ((*target).is_alive() == false) { cout << "I win." << endl; state = 's'; return true; } } } else { return false; } }
void Person::setup_destination(Cart_Point dest) //Sets up the object to start moving to a destination { //Sets the destination to the inputted object destination = dest; //Calculates delta value Cart_Vector v; v = destination-location; delta = v*(speed/cart_distance(destination,location)); }
void Soldier::start_attack(Person* in_target) { if (is_alive() == true) { Cart_Point a, b; a = (*in_target).get_location(); b = get_location(); if (cart_distance(a, b) <= range) { target = in_target; state = 'a'; cout << "Attacking." << endl; } else if (cart_distance((*in_target).get_location(), get_location()) > range) { cout << "Target is out of range." << endl; } } else cout << "I am dead. You do not have the ability to summon the undead." << endl; }
//Starts attacking another fish void Shark::start_attack(Fish *target) { if (is_alive()) { //If the fish is close enough, attack it if (cart_distance(location, target->get_location()) <= range) { std::cout << display_code << get_id() << ": Chomp!" << std::endl; this->target = target; state = 'a'; target->get_bitten(attack_strength); } else std::cout << display_code << get_id() << ": Fish are friends, not food" << std::endl; } }
//Updates the Tuna bool Shark::update() { switch (state) { case 'x': break; case 's': break; case 'a': //attacking if (cart_distance(location, target->get_location()) > range) //fish is too far away { std::cout << "Darn! It escaped" << std::endl; target = NULL; state = 's'; return true; } else //fish is close enough { std::cout << display_code << get_id() << ": Chomp!" << std::endl; target->get_bitten(attack_strength); if (target->get_state() == 'x') //fish is killed { std::cout << "I triumph" << std::endl; energy += 5; state = 's'; return true; } } break; case 'e': //eating at a coral reef which is impossible break; } return false; }
float cyl_distance(struct cyl_pt pt1, struct cyl_pt pt2){ /*yes, I'm very lazy. It's one of my best traits*/ return cart_distance(cyl_to_cart(pt1), cyl_to_cart(pt2)); }