/** * Checks if the moving target has reached its destination. * @return True if it has, False otherwise. */ bool MovingTarget::reachedDestination() const { if (_dest == 0) { return false; } return ( AreSame(_dest->getLongitude(), _lon) && AreSame(_dest->getLatitude(), _lat) ); }
void BuildNewBaseState::hoverRedraw(void) { double lon, lat; _globe->cartToPolar(_mousex, _mousey, &lon, &lat); _globe->setNewBaseHoverPos(lon,lat); _globe->setNewBaseHover(); if (_globe->getShowRadar() && !(AreSame(_oldlat, lat) && AreSame(_oldlon, lon)) ) { _oldlat=lat; _oldlon=lon; _globe->draw(); } }
/** * Gets the area data for the mission point in the specified zone and coordinates. * @param zone The target zone. * @param target The target coordinates. * @return A MissionArea from which to extract coordinates, textures, or any other pertinent information. */ MissionArea RuleRegion::getMissionPoint(size_t zone, Target *target) const { if (zone < _missionZones.size()) { for (std::vector<MissionArea>::const_iterator i = _missionZones[zone].areas.begin(); i != _missionZones[zone].areas.end(); ++i) { if (i->isPoint() && AreSame(target->getLongitude(), i->lonMin) && AreSame(target->getLatitude(), i->latMin)) { return *i; } } } assert(0 && "Invalid zone number"); return MissionArea(); }
void BuildNewBaseState::hoverRedraw(void) { double lon, lat; _globe->cartToPolar(_mousex, _mousey, &lon, &lat); if (lon == lon && lat == lat) { _globe->setNewBaseHoverPos(lon,lat); _globe->setNewBaseHover(); } if (Options::globeRadarLines && !(AreSame(_oldlat, lat) && AreSame(_oldlon, lon)) ) { _oldlat=lat; _oldlon=lon; _globe->invalidate(); } }
/** * Plays the window popup animation. */ void Window::popup() { if (AreSame(_popupStep, 0.0)) { int sound = SDL_GetTicks() % 3; // this is a hack to avoid calling RNG::generate(0, 2) and skewing our seed. if (soundPopup[sound] != 0) { soundPopup[sound]->play(Mix_GroupAvailable(0)); } } if (_popupStep < 1.0) { _popupStep += POPUP_SPEED; } else { if (_screen) { _state->toggleScreen(); } _state->showAll(); _popupStep = 1.0; _timer->stop(); } _redraw = true; }
/* Defines if the candidate is taboo or not (if any of its changed routes is forbidden). */ bool isTabu(SolutionCandidate& candidate, std::vector<TabuItem>& tabuList) { for (int i=0; i<tabuList.size(); i++) { for (int j=0; j<candidate.numberOfModifications; j++) { if (AreSame(candidate.modifiedRoutes[j], tabuList[i].tabuRoute)) return true; } } return false; }
/** * Calculate meeting point with the target. */ void MovingTarget::calculateMeetPoint() { // Initialize _meetPointLat = _dest->getLatitude(); _meetPointLon = _dest->getLongitude(); MovingTarget *u = dynamic_cast<MovingTarget*>(_dest); if (!u || !u->getDestination()) return; // Speed ratio if (AreSame(u->getSpeedRadian(), 0.0)) return; const double speedRatio = _speedRadian/ u->getSpeedRadian(); if (speedRatio <= 1) return; // The direction pseudovector double nx = cos(u->getLatitude())*sin(u->getLongitude())*sin(u->getDestination()->getLatitude()) - sin(u->getLatitude())*cos(u->getDestination()->getLatitude())*sin(u->getDestination()->getLongitude()), ny = sin(u->getLatitude())*cos(u->getDestination()->getLatitude())*cos(u->getDestination()->getLongitude()) - cos(u->getLatitude())*cos(u->getLongitude())*sin(u->getDestination()->getLatitude()), nz = cos(u->getLatitude())*cos(u->getDestination()->getLatitude())*sin(u->getDestination()->getLongitude() - u->getLongitude()); // Normalize and multiplex with radian speed double nk = _speedRadian/sqrt(nx*nx+ny*ny+nz*nz); nx *= nk; ny *= nk; nz *= nk; // Initialize double path=0, distance; // Finding the meeting point do { _meetPointLat += nx*sin(_meetPointLon) - ny*cos(_meetPointLon); if (abs(_meetPointLat) < M_PI_2) _meetPointLon += nz - (nx*cos(_meetPointLon) + ny*sin(_meetPointLon))*tan(_meetPointLat); else _meetPointLon += M_PI; path += _speedRadian; distance = acos(cos(_lat) * cos(_meetPointLat) * cos(_meetPointLon - _lon) + sin(_lat) * sin(_meetPointLat)); } while (path < M_PI && distance - path*speedRatio > 0); // Correction overflowing angles double lonSign = Sign(_meetPointLon); double latSign = Sign(_meetPointLat); while (abs(_meetPointLon) > M_PI) _meetPointLon -= lonSign * 2 * M_PI; while (abs(_meetPointLat) > M_PI) _meetPointLat -= latSign * 2 * M_PI; if (abs(_meetPointLat) > M_PI_2) { _meetPointLat = latSign * abs(2 * M_PI - abs(_meetPointLat)); _meetPointLon -= lonSign * M_PI; } }
void SDLWaitFrame(void) { static double oldTick=0.0; Uint32 currentTick; double waitTicks; double delay = flc.DelayOverride ? flc.DelayOverride : flc.HeaderSpeed; if ( AreSame(oldTick, 0.0) ) oldTick = SDL_GetTicks(); currentTick=SDL_GetTicks(); waitTicks=(oldTick+=(delay))-currentTick; do { waitTicks = (oldTick + delay - SDL_GetTicks()); if(waitTicks > 0.0) { //SDL_Delay(floor(waitTicks + 0.5)); // biased rounding? mehhh? SDL_Delay(1); } } while (waitTicks > 0.0); } /* SDLWaitFrame */
BOOL CExMapi::OpenNextMessageStore(LPMAPITABLE lpMsgStoreTable, ULONG ulFlags) { if(!m_pSession) return FALSE; if(!lpMsgStoreTable) return FALSE; BOOL doLog = m_pCtrl->IsEnableLog(); if(doLog) { m_logHelper.LogPAB(L"Function OpenNextMessageStore START."); } m_ulMDBFlags = ulFlags; LPSRowSet pRows = NULL; const int nProperties = 1; SizedSPropTagArray(nProperties,Columns)={nProperties,{PR_ENTRYID}}; BOOL bResult = FALSE; try { if(lpMsgStoreTable->SetColumns((LPSPropTagArray)&Columns, 0) == S_OK) { while(TRUE) { bResult = FALSE; if(lpMsgStoreTable->QueryRows(1,0,&pRows) != S_OK) MAPIFreeBuffer(pRows); else if(pRows->cRows!=1) FreeProws(pRows); else { LPMDB pMsgStore = NULL; ULONG cbEntryId = pRows->aRow[0].lpProps[0].Value.bin.cb; LPENTRYID lpEntryId = (ENTRYID*)pRows->aRow[0].lpProps[0].Value.bin.lpb; bResult = (m_pSession->OpenMsgStore(NULL, cbEntryId, lpEntryId, NULL, MDB_NO_DIALOG | MAPI_BEST_ACCESS, &pMsgStore) == S_OK); if(bResult) { if(m_pMsgStore) { //check if new open msg store is the same as opened msg store. if(AreSame(m_pMsgStore,pMsgStore)) { if(doLog) { m_logHelper.LogPAB(L"Message Store is already opend."); } RELEASE(pMsgStore); FreeProws(pRows); continue; } else { RELEASE(m_pMsgStore); m_pMsgStore = pMsgStore; bResult = TRUE; } } else { m_pMsgStore = pMsgStore; } } FreeProws(pRows); } break; } } } catch(_com_error& e) { if(doLog) { m_logHelper.LogPAB(L"OpenNextMessageStore Exception:"); m_logHelper.LogPAB(e.ErrorMessage()); } return FALSE; } if(doLog) { m_logHelper.LogPAB(L"Function OpenNextMessageStore END."); } return bResult; }
/// Match with base's coordinates. bool operator()(const Base *base) const { return AreSame(base->getLongitude(), _lon) && AreSame(base->getLatitude(), _lat); }
/** * Calculates the direction for the UFO based * on the current raw speed and destination. */ void Ufo::calculateSpeed() { MovingTarget::calculateSpeed(); double x = _speedLon; double y = -_speedLat; // This section guards vs. divide-by-zero. if (AreSame(x, 0.0) || AreSame(y, 0.0)) { if (AreSame(x, 0.0) && AreSame(y, 0.0)) { _direction = "STR_NONE_UC"; } else if (AreSame(x, 0.0)) { if (y > 0.f) { _direction = "STR_NORTH"; } else if (y < 0.f) { _direction = "STR_SOUTH"; } } else if (AreSame(y, 0.0)) { if (x > 0.f) { _direction = "STR_EAST"; } else if (x < 0.f) { _direction = "STR_WEST"; } } return; } double theta = atan2(y, x); // radians theta = theta * 180.f / M_PI; // +/- 180 deg. if (22.5f > theta && theta > -22.5f) { _direction = "STR_EAST"; } else if (-22.5f > theta && theta > -67.5f) { _direction = "STR_SOUTH_EAST"; } else if (-67.5f > theta && theta > -112.5f) { _direction = "STR_SOUTH"; } else if (-112.5f > theta && theta > -157.5f) { _direction = "STR_SOUTH_WEST"; } else if (-157.5f > theta || theta > 157.5f) { _direction = "STR_WEST"; } else if (157.5f > theta && theta > 112.5f) { _direction = "STR_NORTH_WEST"; } else if (112.5f > theta && theta > 67.5f) { _direction = "STR_NORTH"; } else { _direction = "STR_NORTH_EAST"; } }
/** * Loads the region type from a YAML file. * @param node YAML node. */ void RuleRegion::load(const YAML::Node &node) { _type = node["type"].as<std::string>(_type); _cost = node["cost"].as<int>(_cost); std::vector< std::vector<double> > areas; areas = node["areas"].as< std::vector< std::vector<double> > >(areas); for (size_t i = 0; i != areas.size(); ++i) { _lonMin.push_back(areas[i][0] * M_PI / 180.0); _lonMax.push_back(areas[i][1] * M_PI / 180.0); _latMin.push_back(areas[i][2] * M_PI / 180.0); _latMax.push_back(areas[i][3] * M_PI / 180.0); } _missionZones = node["missionZones"].as< std::vector<MissionZone> >(_missionZones); if (const YAML::Node &cities = node["cities"]) { for (YAML::const_iterator i = cities.begin(); i != cities.end(); ++i) { // if a city has been added, make sure that it has a zone 3 associated with it, if not, create one for it. if (_missionZones.size() >= CITY_MISSION_ZONE) { MissionArea ma; ma.lonMin = ma.lonMax = (*i)["lon"].as<double>(0.0); ma.latMin = ma.latMax = (*i)["lat"].as<double>(0.0); if (std::find(_missionZones.at(CITY_MISSION_ZONE).areas.begin(), _missionZones.at(CITY_MISSION_ZONE).areas.end(), ma) == _missionZones.at(CITY_MISSION_ZONE).areas.end()) { _missionZones.at(CITY_MISSION_ZONE).areas.push_back(ma); } } City *rule = new City("", 0.0, 0.0); rule->load(*i); _cities.push_back(rule); } // make sure all the zone 3s line up with cities in this region // only applicable if there ARE cities in this region. for (std::vector<MissionArea>::iterator i = _missionZones.at(CITY_MISSION_ZONE).areas.begin(); i != _missionZones.at(CITY_MISSION_ZONE).areas.end();) { bool matching = false; for (std::vector<City*>::iterator j = _cities.begin(); j != _cities.end() && !matching; ++j) { matching = (AreSame((*j)->getLatitude(), ((*i).latMin * M_PI / 180.0)) && AreSame((*j)->getLongitude(), ((*i).lonMin * M_PI / 180.0)) && AreSame((*i).latMax, (*i).latMin) && AreSame((*i).lonMax, (*i).lonMin)); } if (matching) { ++i; } else { i = _missionZones.at(CITY_MISSION_ZONE).areas.erase(i); } } } if (const YAML::Node &weights = node["missionWeights"]) { _missionWeights.load(weights); } _regionWeight = node["regionWeight"].as<size_t>(_regionWeight); _missionRegion = node["missionRegion"].as<std::string>(_missionRegion); }
/** * calculateTrajectory. * @return true when a trajectory is possible. */ bool Projectile::calculateThrow(double accuracy) { Position originVoxel, targetVoxel; bool foundCurve = false; // object blocking - can't throw here if (_action.type == BA_THROW &&_save->getTile(_action.target) && _save->getTile(_action.target)->getMapData(MapData::O_OBJECT) && _save->getTile(_action.target)->getMapData(MapData::O_OBJECT)->getTUCost(MT_WALK) == 255) { return false; } originVoxel = Position(_origin.x*16 + 8, _origin.y*16 + 8, _origin.z*24); originVoxel.z += -_save->getTile(_origin)->getTerrainLevel(); BattleUnit *bu = _save->getTile(_origin)->getUnit(); if(!bu) bu = _save->getTile(Position(_origin.x, _origin.y, _origin.z-1))->getUnit(); originVoxel.z += bu->getHeight() + bu->getFloatHeight(); originVoxel.z -= 3; if (originVoxel.z >= (_origin.z + 1)*24) { _origin.z++; } // determine the target voxel. // aim at the center of the floor targetVoxel = Position(_action.target.x*16 + 8, _action.target.y*16 + 8, _action.target.z*24 + 2); // we try 4 different curvatures to try and reach our goal. double curvature = 1.0; while (!foundCurve && curvature < 5.0) { _save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, false, &_trajectory, bu, curvature, 1.0); if ((int)_trajectory.at(0).x/16 == (int)targetVoxel.x/16 && (int)_trajectory.at(0).y/16 == (int)targetVoxel.y/16 && (int)_trajectory.at(0).z/24 == (int)targetVoxel.z/24) { foundCurve = true; } else { curvature += 1.0; } _trajectory.clear(); } if ( AreSame(curvature, 5.0) ) { return false; } // apply some accuracy modifiers if (accuracy > 1) accuracy = 1; static const double maxDeviation = 0.08; static const double minDeviation = 0; double baseDeviation = (maxDeviation - (maxDeviation * accuracy)) + minDeviation; double deviation = RNG::boxMuller(0, baseDeviation); _trajectory.clear(); // finally do a line calculation and store this trajectory. _save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, true, &_trajectory, bu, curvature, 1.0 + deviation); Position endPoint = _trajectory.at(_trajectory.size() - 1); endPoint.x /= 16; endPoint.y /= 16; endPoint.z /= 24; // check if the item would land on a tile with a blocking object, if so then we let it fly without deviation, it must land on a valid tile in that case if (_save->getTile(endPoint) && _save->getTile(endPoint)->getMapData(MapData::O_OBJECT) && _save->getTile(endPoint)->getMapData(MapData::O_OBJECT)->getTUCost(MT_WALK) == 255) { _trajectory.clear(); // finally do a line calculation and store this trajectory. _save->getTileEngine()->calculateParabola(originVoxel, targetVoxel, true, &_trajectory, bu, curvature, 1.0); } return true; }