ObjectBase* Tile::getObjectAt(int x, int y) { ObjectBase* temp = NULL; if (hasAnAirUnit()) temp = getAirUnit(); else if (hasANonInfantryGroundObject()) temp = getNonInfantryGroundObject(); else if (hasInfantry()) { float closestDistance = INFINITY; Coord atPos, centerPoint; InfantryBase* infantry; atPos.x = x; atPos.y = y; std::list<Uint32>::const_iterator iter; for(iter = assignedInfantryList.begin(); iter != assignedInfantryList.end() ; ++iter) { infantry = (InfantryBase*) currentGame->getObjectManager().getObject(*iter); if(infantry == NULL) continue; centerPoint = infantry->getCenterPoint(); if(distanceFrom(atPos, centerPoint) < closestDistance) { closestDistance = distanceFrom(atPos, centerPoint); temp = infantry; } } } else if (hasAnUndergroundUnit()) temp = getUndergroundUnit(); return temp; }
void Camera::leftView(const vh::Vector3& low, const vh::Vector3& high) { _target = (high + low) / 2; float distance = (high.x - low.x) / 2 + distanceFrom(high.z, low.z, high.y, low.y); _rotation = vh::Vector4(0, 270, 0, distance); }
void Camera::backView(const vh::Vector3& low, const vh::Vector3& high) { _target = (high + low) / 2; float distance = (high.z - low.z) / 2 + distanceFrom(high.x, low.x, high.y, low.y); _rotation = vh::Vector4(0, 180, 0, distance); }
void Camera::bottomView(const vh::Vector3& low, const vh::Vector3& high) { _target = (high + low) / 2; float distance = (high.y - low.y) + distanceFrom(high.x, low.x, high.z, low.z); _rotation = vh::Vector4(270, 0, 0, distance); }
bool CHLDMBot::checkStuck() { static bool bStuck; if ( (bStuck = CBot::checkStuck()) == true ) { if ( m_pWeapons->hasWeapon(HL2DM_WEAPON_PHYSCANNON) ) {// check stuck on object CBotWeapon *currentWeapon = getCurrentWeapon(); if ( ( currentWeapon->getID() == HL2DM_WEAPON_PHYSCANNON ) && ( m_pCarryingObject ) ) { primaryAttack(); } else if ( m_NearestPhysObj && (distanceFrom(m_NearestPhysObj)<100) ) { if ( !m_pSchedules->hasSchedule(SCHED_GRAVGUN_PICKUP) ) { m_pSchedules->freeMemory(); CBotSchedule *pSched = new CBotSchedule(new CBotGravGunPickup(m_pCurrentWeapon,m_NearestPhysObj)); pSched->setID(SCHED_GRAVGUN_PICKUP); m_pSchedules->add(pSched); } } } } return bStuck; }
int main() { Point2d first; Point2d second(3.0, 4.0); first.print(); second.print(); std::cout << "Distance between two points: " << distanceFrom(first, second) << '\n'; return 0; }
// deal with attacking code here // return false if it is impossible to shoot this enemy; i.e. change enemy // return true: if it is possible to shoot this enemy // decide whether or not the bot shoot attack by calling primaryAttack or secondaryAttack bool CHLDMBot :: handleAttack ( CBotWeapon *pWeapon, edict_t *pEnemy ) { if ( pWeapon ) { extern ConVar rcbot_enemyshoot_gravgun_fov; static float fDistance; fDistance = distanceFrom(pEnemy); clearFailedWeaponSelect(); if ( pWeapon->isMelee() ) setMoveTo(CBotGlobals::entityOrigin(pEnemy)); if ( (pWeapon->getID() == HL2DM_WEAPON_PHYSCANNON) && (DotProductFromOrigin(m_vAimVector) < rcbot_enemyshoot_gravgun_fov.GetFloat()) ) return true; // keep enemy / don't shoot : until angle between enemy is less than 20 degrees if ( pWeapon->canUseSecondary() && pWeapon->getAmmo(this,2) && pWeapon->secondaryInRange(fDistance) ) { if ( randomInt(0,1) ) { secondaryAttack(); return true; } } // can use primary if ( pWeapon->canAttack() ) { if ( pWeapon->mustHoldAttack() ) primaryAttack(true); else primaryAttack(); return true; } } else { primaryAttack(); return true; } return false; }
// Is pEdict an enemy? return true if enemy / false if not // if checkWeapons is true, check if current weapon can attack enemy // return false if not bool CHLDMBot :: isEnemy ( edict_t *pEdict,bool bCheckWeapons ) { extern ConVar rcbot_notarget; static int entity_index; entity_index = ENTINDEX(pEdict); // if no target on - listen sever player is a non target if ( rcbot_notarget.GetBool() && (entity_index == 1) ) return false; // not myself if ( pEdict == m_pEdict ) return false; // not a player - false if ( !entity_index || (entity_index > CBotGlobals::maxClients()) ) { if ( !m_pCarryingObject && pEdict->GetUnknown() && (pEdict == m_NearestBreakable) && (CClassInterface::getPlayerHealth(pEdict)>0) ) { if ( distanceFrom(CBotGlobals::entityOrigin(pEdict)) < rcbot_jump_obst_dist.GetFloat() ) { if ( BotFunc_BreakableIsEnemy(m_NearestBreakable,m_pEdict) || ((CBotGlobals::entityOrigin(pEdict) - m_vMoveTo).Length()+48) < (getOrigin() - m_vMoveTo).Length() ) return true; } } return false; } // not alive -- false if ( !CBotGlobals::entityIsAlive(pEdict) ) return false; // team game? if ( CBotGlobals::getTeamplayOn() ) { // same team ? false if ( CBotGlobals::getTeam(pEdict) == getTeam() ) return false; } return true; }
bool CHLDMBot :: willCollide ( edict_t *pEntity, bool *bCanJump, float *fTime ) { static Vector vel; static Vector v_size; static float fDistance; static Vector vOrigin; static float fSpeed; static Vector v_dest; static Vector v_min,v_max; if ( CClassInterface::getVelocity(m_pEdict,&vel) ) { v_min = pEntity->GetCollideable()->OBBMins(); v_max = pEntity->GetCollideable()->OBBMaxs(); v_size = v_max - v_min; fDistance = distanceFrom(pEntity); vOrigin = CBotGlobals::entityOrigin(pEntity); fSpeed = vel.Length(); // speed = dist/time --- time = dist/speed if ( fSpeed > 0 ) { *fTime = fDistance / fSpeed; vel = vel / fSpeed; // normalize v_dest = getOrigin() + (vel*fDistance); if ( v_size.z <= 48 ) // jump height *bCanJump = true; return (vOrigin - v_dest).Length() < (v_size.Length()/2); } } return false; }
void KeyboardNavigation::NearestWindow::inspectWindow (CompWindow *window) { const CompWindow::Geometry &sg = window->serverGeometry(); /* This is a completely unmaintainable expression */ if (window->id() == source->id() || UNDESIRABLE_WINDOW(window, sg)) { DEBUG_LOG("Ignoring window " << window->id()); return; } if (!lateralCollision(window)) { return; } int distance = distanceFrom(window); DEBUG_LOG("Inspected window " << window->id() << " has distance " << distance); if (distance == 0) { if (target == NULL) { target = window; } } else if (distance > 0) { if (target == NULL) { target = window; targetDistance = distance; } else if (distance < targetDistance) { target = window; targetDistance = distance; } } }
// the bot was killed by pKiller void CHLDMBot :: died ( edict_t *pKiller, const char *pszWeapon ) { extern ConVar bot_beliefmulti; // re-initialize stuff per life CBot::died(pKiller, pszWeapon); //if ( randomInt(0,1) ) m_pButtons->attack(); // respawn if ( pKiller ) { if ( CBotGlobals::entityIsValid(pKiller) ) { m_pNavigator->belief(CBotGlobals::entityOrigin(pKiller),getEyePosition(),bot_beliefmulti.GetFloat(),distanceFrom(pKiller),BELIEF_DANGER); } } }
// the bot killed pVictim void CHLDMBot :: killed ( edict_t *pVictim, char *weapon ) { extern ConVar bot_beliefmulti; CBot::killed(pVictim,weapon); // update belief around this waypoint if ( pVictim && CBotGlobals::entityIsValid(pVictim) ) m_pNavigator->belief(CBotGlobals::entityOrigin(pVictim),getEyePosition(),bot_beliefmulti.GetFloat(),distanceFrom(pVictim),BELIEF_SAFETY); }
// update some edicts in my memory if I see them or not bool CHLDMBot :: setVisible ( edict_t *pEntity, bool bVisible ) { static float fDist; const char *szClassname; bool bValid = CBot::setVisible(pEntity,bVisible); fDist = distanceFrom(pEntity); // if no draw effect it is invisible if ( bValid && bVisible && !(CClassInterface::getEffects(pEntity)&EF_NODRAW) ) { szClassname = pEntity->GetClassName(); if ( ( strncmp(szClassname,"item_ammo",9)==0 ) && ( !m_pAmmoKit.get() || (fDist<distanceFrom(m_pAmmoKit.get())) )) { m_pAmmoKit = pEntity; } else if ( ( strncmp(szClassname,"item_health",11)==0 ) && ( !m_pHealthKit.get() || (fDist<distanceFrom(m_pHealthKit.get())) )) { //if ( getHealthPercent() < 1.0f ) // updateCondition(CONDITION_CHANGED); m_pHealthKit = pEntity; } else if ( ( strcmp(szClassname,"item_battery")==0 ) && ( !m_pBattery.get() || (fDist<distanceFrom(m_pBattery.get())) )) { m_pBattery = pEntity; } else if ( ( (strcmp(szClassname,"func_breakable")==0 ) || (strncmp(szClassname,"prop_physics",12)==0) ) && (CClassInterface::getPlayerHealth(pEntity)>0) && ( !m_NearestBreakable.get() || (fDist<distanceFrom(m_NearestBreakable.get())) )) { m_NearestBreakable = pEntity; } else if ( (pEntity != m_pNearestButton) && ( strcmp(szClassname,"func_button")==0 ) ) { if ( !m_pNearestButton.get() || (fDist<distanceFrom(m_pNearestButton.get())) ) m_pNearestButton = pEntity; } // covered above /*else if ( (pEntity != m_pNearestBreakable) && ( strcmp(szClassname,"func_breakable")==0 ) ) { if ( !m_pNearestBreakable.get() || (fDist<distanceFrom(m_pNearestBreakable.get())) ) m_pNearestBreakable = pEntity; }*/ else if ( (pEntity != m_pAmmoCrate ) && ( strcmp(szClassname,"item_ammo_crate") == 0 ) ) { if ( !m_pAmmoCrate.get() || (fDist<distanceFrom(m_pAmmoCrate.get())) ) m_pAmmoCrate = pEntity; } else if ( (pEntity != m_FailedPhysObj) && ( strncmp(szClassname,"prop_physics",12)==0 ) && ( !m_NearestPhysObj.get() || (fDist<distanceFrom(m_NearestPhysObj.get())) )) { //if ( !m_bCarryingObject ) // updateCondition(CONDITION_CHANGED); m_NearestPhysObj = pEntity; } else if ( ( strncmp(szClassname,"item_suitcharger",16)==0 ) && ( !m_pCharger.get() || (fDist<distanceFrom(m_pCharger.get())) )) { if ( m_pCharger.get() ) { // less juice than the current one I see if ( CClassInterface::getAnimCycle(m_pCharger) < CClassInterface::getAnimCycle(pEntity) ) { return bValid; } } if ( m_pPlayerInfo->GetArmorValue() < 50 ) updateCondition(CONDITION_CHANGED); m_pCharger = pEntity; } else if ( ( strncmp(szClassname,"item_healthcharger",18)==0 ) && ( !m_pHealthCharger.get() || (fDist<distanceFrom(m_pHealthCharger.get())) )) { if ( m_pHealthCharger.get() ) { // less juice than the current one I see - forget it if ( CClassInterface::getAnimCycle(m_pHealthCharger) < CClassInterface::getAnimCycle(pEntity) ) { return bValid; } } if ( getHealthPercent() < 1.0f ) updateCondition(CONDITION_CHANGED); // update tasks m_pHealthCharger = pEntity; } else if ( ( strncmp(szClassname,"weapon_",7)==0 ) && ( !m_pNearbyWeapon.get() || (fDist<distanceFrom(m_pNearbyWeapon.get())) )) { /*static CWeapon *pWeapon; pWeapon = CWeapons::getWeapon(pEntity->GetClassName()); if ( pWeapon && !m_pWeapons->hasWeapon(pWeapon->getID()) ) updateCondition(CONDITION_CHANGED);*/ m_pNearbyWeapon = pEntity; } } else { if ( m_pAmmoKit == pEntity ) m_pAmmoKit = NULL; else if ( m_pAmmoCrate == pEntity ) m_pAmmoCrate = NULL; else if ( m_pHealthKit == pEntity ) m_pHealthKit = NULL; else if ( m_pBattery == pEntity ) m_pBattery = NULL; else if ( m_NearestPhysObj == pEntity ) m_NearestPhysObj = NULL; else if ( m_pCharger == pEntity ) m_pCharger = NULL; else if ( m_pHealthCharger == pEntity ) m_pHealthCharger = NULL; else if ( m_NearestBreakable == pEntity ) m_NearestBreakable = NULL; else if ( m_pNearbyWeapon == pEntity ) m_pNearbyWeapon = NULL; else if ( m_pNearestButton == pEntity ) m_pNearestButton = NULL; //else if ( m_pNearestBreakable == pEntity ) // m_pNearestBreakable = NULL; } return bValid; }
void CHLDMBot :: modThink () { m_fIdealMoveSpeed = CClassInterface::getMaxSpeed(m_pEdict); // update hitbox hull //m_pEdict->GetCollideable()->GetCollisionOrigin(); if ( !CBotGlobals::entityIsValid(m_NearestPhysObj) ) m_NearestPhysObj = NULL; if ( !CBotGlobals::entityIsValid(m_FailedPhysObj) ) m_FailedPhysObj = NULL; //if ( m_pWeapons ) // m_pWeapons->update(); //if ( m_fFixWeaponTime < engine->Time() ) //{ m_pCurrentWeapon = CClassInterface::getCurrentWeapon(m_pEdict); // m_fFixWeaponTime = engine->Time() + 1.0f; //} if ( m_pCurrentWeapon ) CClassInterface::getWeaponClip(m_pCurrentWeapon,&m_iClip1,&m_iClip2); if ( CClassInterface::onLadder(m_pEdict) != NULL ) { setMoveLookPriority(MOVELOOK_OVERRIDE); setLookAtTask(LOOK_WAYPOINT); m_pButtons->holdButton(IN_FORWARD,0,1,0); setMoveLookPriority(MOVELOOK_MODTHINK); } if ( (m_fCurrentDanger >= 20.0f) && (CClassInterface::auxPower(m_pEdict) > 90.f ) && (m_flSprintTime < engine->Time())) { m_pButtons->holdButton(IN_SPEED,0,1,0); } else if (( m_fCurrentDanger < 1 ) || (CClassInterface::auxPower(m_pEdict) < 5.0f )) { m_flSprintTime = engine->Time() + randomFloat(5.0f,20.0f); } if ( m_fLastSeeEnemy && ((m_fLastSeeEnemy + 5.0)<engine->Time()) ) { CBotWeapon *pWeapon = getCurrentWeapon(); if ( pWeapon && (pWeapon->getClip1(this)==0) && (pWeapon->getAmmo(this) > 0 ) ) { m_fLastSeeEnemy = 0; m_pButtons->tap(IN_RELOAD); } } if ( m_NearestPhysObj.get() ) { bool bCarry = false; edict_t *pEntity = m_NearestPhysObj.get(); if ( m_pCurrentWeapon && !strcmp("weapon_physcannon",m_pCurrentWeapon->GetClassName()) ) { m_pCarryingObject = CClassInterface::gravityGunObject(m_pCurrentWeapon); bCarry = (CClassInterface::gravityGunObject(m_pCurrentWeapon) == m_NearestPhysObj.get()); } if ( !bCarry && (distanceFrom(pEntity) < rcbot_jump_obst_dist.GetFloat()) ) { bool bCanJump = false; float fTime = 0; if ( willCollide(pEntity,&bCanJump,&fTime) ) { if ( bCanJump && (fTime < 1.5f) ) // one second to jump { if ( randomInt(0,1) ) jump(); } } } } }
// time to think about something new to do void CHLDMBot :: getTasks (unsigned int iIgnore) { static CBotUtilities utils; static CBotUtility *next; static CBotWeapon *gravgun; static CBotWeapon *crossbow; static CWeapon *pWeapon; static bool bCheckCurrent; if ( !hasSomeConditions(CONDITION_CHANGED) && !m_pSchedules->isEmpty() ) return; removeCondition(CONDITION_CHANGED); bCheckCurrent = true; // important for checking current schedule gravgun = m_pWeapons->getWeapon(CWeapons::getWeapon(HL2DM_WEAPON_PHYSCANNON)); // If I have the grav gun, think about picking something up if ( gravgun ) { edict_t *pent = INDEXENT(gravgun->getWeaponIndex()); if ( CBotGlobals::entityIsValid(pent) ) { ADD_UTILITY(BOT_UTIL_HL2DM_GRAVIGUN_PICKUP,(!m_pEnemy||(m_pCurrentWeapon&&(strcmp("weapon_physcannon",m_pCurrentWeapon->GetClassName())))) && gravgun && gravgun->hasWeapon() && (m_NearestPhysObj.get()!=NULL) && (gravgun->getWeaponIndex() > 0) && (CClassInterface::gravityGunObject(INDEXENT(gravgun->getWeaponIndex()))==NULL),0.9f); } } if ( (crossbow = m_pWeapons->getWeapon(CWeapons::getWeapon(HL2DM_WEAPON_CROSSBOW))) != NULL ) { if ( crossbow->hasWeapon() && !crossbow->outOfAmmo(this) ) ADD_UTILITY(BOT_UTIL_SNIPE,true,0.91f); } // low on health? Pick some up if there's any near by ADD_UTILITY(BOT_UTIL_HL2DM_USE_HEALTH_CHARGER,(m_pHealthCharger.get() != NULL) && (CClassInterface::getAnimCycle(m_pHealthCharger)<1.0f) && (getHealthPercent()<1.0f),(1.0f-getHealthPercent())); ADD_UTILITY(BOT_UTIL_FIND_NEAREST_HEALTH,(m_pHealthKit.get()!=NULL) && (getHealthPercent()<1.0f),1.0f-getHealthPercent()); // low on armor? ADD_UTILITY(BOT_UTIL_HL2DM_FIND_ARMOR,(m_pBattery.get() !=NULL) && (getArmorPercent()<1.0f),(1.0f-getArmorPercent())*0.75f); ADD_UTILITY(BOT_UTIL_HL2DM_USE_CHARGER,(m_pCharger.get() !=NULL) && (CClassInterface::getAnimCycle(m_pCharger)<1.0f) && (getArmorPercent()<1.0f),(1.0f-getArmorPercent())*0.75f); ADD_UTILITY(BOT_UTIL_HL2DM_USE_CRATE,(m_pAmmoCrate.get()!=NULL) && (m_fUseCrateTime < engine->Time()),1.0f); // low on ammo? ammo nearby? ADD_UTILITY(BOT_UTIL_FIND_NEAREST_AMMO,(m_pAmmoKit.get() !=NULL) && (getAmmo(0)<5),0.01f*(100-getAmmo(0))); // always able to roam around ADD_UTILITY(BOT_UTIL_ROAM,true,0.01f); // I have an enemy ADD_UTILITY(BOT_UTIL_FIND_LAST_ENEMY,wantToFollowEnemy() && !m_bLookedForEnemyLast && m_pLastEnemy && CBotGlobals::entityIsValid(m_pLastEnemy) && CBotGlobals::entityIsAlive(m_pLastEnemy),getHealthPercent()*(getArmorPercent()+0.1)); if ( !hasSomeConditions(CONDITION_SEE_CUR_ENEMY) && hasSomeConditions(CONDITION_SEE_LAST_ENEMY_POS) && m_pLastEnemy && m_fLastSeeEnemy && ((m_fLastSeeEnemy + 10.0) > engine->Time()) && m_pWeapons->hasWeapon(HL2DM_WEAPON_FRAG) ) { float fDistance = distanceFrom(m_vLastSeeEnemyBlastWaypoint); if ( ( fDistance > BLAST_RADIUS ) && ( fDistance < 1500 ) ) { CWeapon *pWeapon = CWeapons::getWeapon(HL2DM_WEAPON_FRAG); CBotWeapon *pBotWeapon = m_pWeapons->getWeapon(pWeapon); ADD_UTILITY(BOT_UTIL_THROW_GRENADE, pBotWeapon && (pBotWeapon->getAmmo(this) > 0) ,1.0f-(getHealthPercent()*0.2)); } } if ( m_pNearbyWeapon.get() ) { pWeapon = CWeapons::getWeapon(m_pNearbyWeapon.get()->GetClassName()); if ( pWeapon && !m_pWeapons->hasWeapon(pWeapon->getID()) ) { ADD_UTILITY(BOT_UTIL_PICKUP_WEAPON, true , 0.6f + pWeapon->getPreference()*0.1f); } } utils.execute(); while ( (next = utils.nextBest()) != NULL ) { if ( !m_pSchedules->isEmpty() && bCheckCurrent ) { if ( m_CurrentUtil != next->getId() ) m_pSchedules->freeMemory(); else break; } bCheckCurrent = false; if ( executeAction(next->getId()) ) { m_CurrentUtil = next->getId(); if ( m_fUtilTimes[next->getId()] < engine->Time() ) m_fUtilTimes[next->getId()] = engine->Time() + randomFloat(0.1f,2.0f); // saves problems with consistent failing if ( CClients::clientsDebugging(BOT_DEBUG_UTIL) ) { CClients::clientDebugMsg(BOT_DEBUG_UTIL,g_szUtils[next->getId()],this); } break; } } utils.freeMemory(); }
void UnitBase::attack() { if(numWeapons) { Coord targetCenterPoint; Coord centerPoint = getCenterPoint(); bool bAirBullet; if(target.getObjPointer() != NULL) { targetCenterPoint = target.getObjPointer()->getClosestCenterPoint(location); bAirBullet = target.getObjPointer()->isAFlyingUnit(); } else { targetCenterPoint = currentGameMap->getTile(attackPos)->getCenterPoint(); bAirBullet = false; } int currentBulletType = bulletType; Sint32 currentWeaponDamage = currentGame->objectData.data[itemID][originalHouseID].weapondamage; if(getItemID() == Unit_Trooper) { // Troopers change weapon type depending on distance float distance = distanceFrom(centerPoint, targetCenterPoint); if(distance > 2*TILESIZE) { currentBulletType = Bullet_SmallRocket; } } if(primaryWeaponTimer == 0) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); primaryWeaponTimer = getWeaponReloadTime(); secondaryWeaponTimer = 15; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } if((numWeapons == 2) && (secondaryWeaponTimer == 0) && (isBadlyDamaged() == false)) { bulletList.push_back( new Bullet( objectID, ¢erPoint, &targetCenterPoint, currentBulletType, currentWeaponDamage, bAirBullet) ); playAttackSound(); secondaryWeaponTimer = -1; if(attackPos && getItemID() != Unit_SonicTank && currentGameMap->getTile(attackPos)->isSpiceBloom()) { setDestination(location); forced = false; attackPos.invalidate(); } // shorten deviation time if(deviationTimer > 0) { deviationTimer = std::max(0,deviationTimer - MILLI2CYCLES(20*1000)); } } } }
vguard<TreeBranchLength> Tree::distanceFromRoot() const { return distanceFrom (root()); }
GarbageCentral::GarbageCentral(const Reader& r) { if (! r.relations.empty()) { auto it = begin(r.relations); auto it_road = r.links.find(Link(it->road_id)); auto it_node1 = r.nodes.find(Node(it->node1_id)); auto it_node2 = r.nodes.find(Node(it->node2_id)); treat_plant = new TreatmentPlant(it_node1->node_id, "Central", it_node1->x, it_node1->y, it_node1->z); GDPointer gd1 = GDPointer(treat_plant); graph.addVertex(gd1); minX = it_node1->x; minY = it_node1->y; minZ = it_node1->z; maxX = it_node1->x; maxY = it_node1->y; maxZ = it_node1->y; deposits.push_back(new GarbageDeposit(it_node2->node_id, it_node2->x, it_node2->y, it_node2->z)); GDPointer gd2 = GDPointer(deposits[0]); graph.addVertex(gd2); if (it_node2->x < minX) minX = it_node2->x; else if (it_node2->x > maxX) maxX = it_node2->x; if (it_node2->y < minY) minY = it_node2->y; else if (it_node2->y > maxY) maxY = it_node2->y; if (it_node2->z < minZ) minZ = it_node2->z; else if (it_node2->z > maxZ) maxZ = it_node2->z; double distance = it_node1->distanceFrom(*it_node2); roads.push_back(new Road(it_road->link_id, it_road->link_name, distance, rand() % 70)); RoadPointer road_ptr = RoadPointer(roads[0]); if (it_road->two_way) { graph.addEdge(gd1, gd2, road_ptr); graph.addEdge(gd2, gd1, road_ptr); } else graph.addEdge(gd1, gd2, road_ptr); it++; for (; it != end(r.relations); it++) { it_road = r.links.find(Link(it->road_id)); it_node1 = r.nodes.find(Node(it->node1_id)); it_node2 = r.nodes.find(Node(it->node2_id)); int pos; pos = depositPosition(it_node1->node_id); if (pos == -1) { deposits.push_back(new GarbageDeposit(it_node1->node_id, it_node1->x, it_node1->y, it_node1->z)); pos = deposits.size() - 1; } gd1 = GDPointer(deposits[pos]); graph.addVertex(gd1); if (it_node1->x < minX) minX = it_node1->x; else if (it_node1->x > maxX) maxX = it_node1->x; if (it_node1->y < minY) minY = it_node1->y; else if (it_node1->y > maxY) maxY = it_node1->y; if (it_node1->z < minZ) minZ = it_node1->z; else if (it_node1->z > maxZ) maxZ = it_node1->z; pos = depositPosition(it_node2->node_id); if (pos == -1) { deposits.push_back(new GarbageDeposit(it_node2->node_id, it_node2->x, it_node2->y, it_node2->z)); pos = deposits.size() - 1; } gd2 = GDPointer(deposits[pos]); graph.addVertex(gd2); if (it_node2->x < minX) minX = it_node2->x; else if (it_node2->x > maxX) maxX = it_node2->x; if (it_node2->y < minY) minY = it_node2->y; else if (it_node2->y > maxY) maxY = it_node2->y; if (it_node2->z < minZ) minZ = it_node2->z; else if (it_node2->z > maxZ) maxZ = it_node2->z; double distance = it_node1->distanceFrom(*it_node2); pos = roadPosition(it_road->link_id); if(pos == -1){ roads.push_back(new Road(it_road->link_id, it_road->link_name, distance, rand() % 70)); pos = roads.size() - 1; } road_ptr = RoadPointer(roads[pos]); if (it_road->two_way) { graph.addEdge(gd1, gd2, road_ptr); graph.addEdge(gd2, gd1, road_ptr); } else graph.addEdge(gd1, gd2, road_ptr); } sortDeposits(); } ifstream in("trucks.txt"); int cap; if (in.good()) { while (in >> cap) { trucks.push_back(GarbageTruck(cap)); } } }