void Island::setIsSelected(bool isSelected) { _isSelected = isSelected; if (_isSelected) { if (getOwnerTag() == Tag::AI) { state = IslandState::SELECTED_BY_AI; } else { if (getOwnerTag() == Tag::PLAYER) { state = IslandState::SELECTED_BY_PLAYER; } else { state = IslandState::NEUTRAL; } } } else { if (getOwnerTag() == Tag::AI) { state = IslandState::AI; } else { if (getOwnerTag() == Tag::PLAYER) { state = IslandState::PLAYER; } else { state = IslandState::NEUTRAL; } } } updateView(); }
bool SpaceShip::onContactBegin(std::weak_ptr<ICollideable> object, bool fromLeft, bool fromTop) { if (object.lock()->getTag() == EntityTags::PROJECTILE) { auto proj = static_cast<Projectile*>(&*object.lock()); if (proj->getOwnerTag() != EntityTags::VEHICLE) { //mHealth.mHP -= proj->getDamage(); //mHealth.mActive = true; //mHealth.mActiveClock.restart(); proj->kill(); } else return false; } else if (object.lock()->getTag() == EntityTags::PLAYER || object.lock()->getTag()== EntityTags::NPC || (object.lock()->getTag()&EntityTags::VEHICLE) == EntityTags::VEHICLE) { return false; } return true; }
void Island::update() { if (getOwnerTag() == Tag::AI || getOwnerTag() == Tag::PLAYER) { _lastTimeUnitsIncremented -= Time::getDeltatime(); if (_lastTimeUnitsIncremented <= 0) { //add an unit _units = MathUtils::min(_units + 1, _maxUnits); updateView(); //reset time _lastTimeUnitsIncremented = _unitsIncrementStep; } } if (_lastTimeAILaunch>0 && getOwnerTag() == Tag::AI) _lastTimeAILaunch -= Time::getDeltatime(); }
void Island::onShipLands(Ship *ship) { //std::cout << ship->getName() << " Arrived to " << this->getName()<< ":" << ((int)this->getOwnerTag()) << "\n"; if (getOwnerTag() == Tag::NEUTRAL) { this->_units++; this->setOwnerByTag(ship->getOwnerTag()); } else { if (ship->getOwnerTag() != getOwnerTag()) { this->_units--; } if (this->_units <= 0) { this->setOwnerByTag(ship->getOwnerTag()); this->_units = MathUtils::abs(this->_units); } } updateView(); }