void IonCanonSatellite::process(int step) { AbilityExecutor::process(step); int unitStep = (step + m_initialStep) % GAME_STEP_PER_SECOND; bool process = (unitStep % m_procStepSize) == 0; if(process && m_active) { m_currentAngle += m_rotation; if(m_currentAngle >= 360) m_currentAngle -= 360; setDirection(m_currentAngle); if(m_attackSecX == (getMapX() - 1) && !m_attack) { m_attack = true; int x = m_attackSecX; int y = getMapY(); Building* target = ObjectController::getInstance()->getBuilding(x, y); if(target != nullptr) { m_bullet->setMapCoord(x, y, true); m_bullet->setTarget(target); } } else if(m_steps == 0) { returnToBase(); m_freeState = true; m_active = false; } } }
/** * Loads the craft from a YAML file. * @param node YAML node. * @param mod Mod for the saved game. * @param save Pointer to the saved game. */ void Craft::load(const YAML::Node &node, const Mod *mod, SavedGame *save) { MovingTarget::load(node); _id = node["id"].as<int>(_id); _fuel = node["fuel"].as<int>(_fuel); _damage = node["damage"].as<int>(_damage); size_t j = 0; for (YAML::const_iterator i = node["weapons"].begin(); i != node["weapons"].end(); ++i) { if (_rules->getWeapons() > j) { std::string type = (*i)["type"].as<std::string>(); if (type != "0" && mod->getCraftWeapon(type)) { CraftWeapon *w = new CraftWeapon(mod->getCraftWeapon(type), 0); w->load(*i); _weapons[j] = w; } else { _weapons[j] = 0; } j++; } } _items->load(node["items"]); for (std::map<std::string, int>::iterator i = _items->getContents()->begin(); i != _items->getContents()->end();) { if (std::find(mod->getItemsList().begin(), mod->getItemsList().end(), i->first) == mod->getItemsList().end()) { _items->getContents()->erase(i++); } else { ++i; } } for (YAML::const_iterator i = node["vehicles"].begin(); i != node["vehicles"].end(); ++i) { std::string type = (*i)["type"].as<std::string>(); if (mod->getItem(type)) { Vehicle *v = new Vehicle(mod->getItem(type), 0, 4); v->load(*i); _vehicles.push_back(v); } } _status = node["status"].as<std::string>(_status); _lowFuel = node["lowFuel"].as<bool>(_lowFuel); _mission = node["mission"].as<bool>(_mission); _interceptionOrder = node["interceptionOrder"].as<int>(_interceptionOrder); if (const YAML::Node name = node["name"]) { _name = Language::utf8ToWstr(name.as<std::string>()); } if (const YAML::Node &dest = node["dest"]) { std::string type = dest["type"].as<std::string>(); int id = dest["id"].as<int>(); if (type == "STR_BASE") { returnToBase(); } else if (type == "STR_UFO") { for (std::vector<Ufo*>::iterator i = save->getUfos()->begin(); i != save->getUfos()->end(); ++i) { if ((*i)->getId() == id) { setDestination(*i); break; } } } else if (type == "STR_WAYPOINT") { for (std::vector<Waypoint*>::iterator i = save->getWaypoints()->begin(); i != save->getWaypoints()->end(); ++i) { if ((*i)->getId() == id) { setDestination(*i); break; } } } else if (type == "STR_ALIEN_BASE") { for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end(); ++i) { if ((*i)->getId() == id) { setDestination(*i); break; } } } else { // Backwards compatibility if (type == "STR_ALIEN_TERROR") type = "STR_TERROR_SITE"; for (std::vector<MissionSite*>::iterator i = save->getMissionSites()->begin(); i != save->getMissionSites()->end(); ++i) { if ((*i)->getId() == id && (*i)->getDeployment()->getMarkerName() == type) { setDestination(*i); break; } } } } _takeoff = node["takeoff"].as<int>(_takeoff); _inBattlescape = node["inBattlescape"].as<bool>(_inBattlescape); if (_inBattlescape) setSpeed(0); }