Exemple #1
0
void Garrison::Plot::DeleteGameObject(Map* map)
{
    if (BuildingInfo.Guid.IsEmpty())
        return;

    for (ObjectGuid const& guid : BuildingInfo.Spawns)
    {
        WorldObject* object = nullptr;
        switch (guid.GetHigh())
        {
            case HighGuid::Creature:
                object = map->GetCreature(guid);
                break;
            case HighGuid::GameObject:
                object = map->GetGameObject(guid);
                break;
            default:
                continue;
        }

        if (object)
            object->AddObjectToRemoveList();
    }

    BuildingInfo.Spawns.clear();

    if (GameObject* oldBuilding = map->GetGameObject(BuildingInfo.Guid))
        oldBuilding->Delete();

    BuildingInfo.Guid.Clear();
}
Exemple #2
0
void Sim::MoveShips()
{
	for (int i = 0; i < ARRAYSIZE(mPlayers); ++i)
	{
		for (int j = 0; j < mPlayers[i].NumShips(); ++j)
		{
			if (mPlayers[i].GetShipHasTarget(j))
			{
				WorldObject* ship = mPlayers[i].GetShip(j);
				V2 target = mPlayers[i].GetShipTarget(j);
				V2 direction = (target - ship->pos).Normalize();
				V2 delta = direction * F32(.35f);
				V2 mappos = ToMap(ship->pos + delta);
				ship->GetSpriteInstance()->SetAnimation(MapDeltaToBoatAnimation(delta));
				if (mMap.Flags(mappos) & Map::Flag_Water)
				{
					ship->pos += delta;
					if ((ship->pos - target).LengthSq() < 2)
					{
						mPlayers[i].SetShipHasTarget(j, false);
					}
				}
			}
		}
	}
}
void WorldSession::HandleObjectUpdate()
{
    uint64 GUID;
    uint8 UpdateField;

    RecPckt >> GUID;
    WorldObject* pObject = ObjectHolder<WorldObject>::Find(GUID);

    while (!RecPckt.EndOfPacket())
    {
        RecPckt >> UpdateField;
        switch (UpdateField)
        {
            case UPDATE_FIELD_X:
                uint16 x;
                RecPckt >> x;
                pObject->MoveX(x);
                break;
            case UPDATE_FIELD_Y:
                uint16 y;
                RecPckt >> y;
                pObject->MoveY(y);
                break;
            default:
                break;
        }
    }
}
Exemple #4
0
Corpse* Eluna::CHECK_CORPSE(lua_State* L, int narg)
{
    WorldObject* obj = CHECK_WORLDOBJECT(L, narg);
    if (!obj)
        return NULL;
    return obj->ToCorpse();
}
Exemple #5
0
void DumpWorldToSyncLog( char *_filename )
{
    FILE *file = fopen( _filename, "a" );
    if( !file ) return;

    fprintf( file, "\n\nBegin Final Object Positions\n" );

    for( int i = 0; i < g_app->GetWorld()->m_teams.Size(); ++i )
    {
        Team *team = g_app->GetWorld()->m_teams[i];
        for( int j = 0; j < team->m_fleets.Size(); ++j )
        {
            Fleet *fleet = team->m_fleets[j];
            char *state = fleet->LogState();
            fprintf( file, "%s\n", state );
        }
    }

    for( int i = 0; i < g_app->GetWorld()->m_objects.Size(); ++i )
    {
        if( g_app->GetWorld()->m_objects.ValidIndex(i) )
        {
            WorldObject *obj = g_app->GetWorld()->m_objects[i];
            char *state = obj->LogState();
            fprintf( file, "%s\n", state );
        }
    }

    fclose(file);
}
Exemple #6
0
Creature* Eluna::CHECK_CREATURE(lua_State* L, int narg)
{
    WorldObject* obj = CHECK_WORLDOBJECT(L, narg);
    if(!obj)
        return NULL;
    return obj->ToCreature();
}
Exemple #7
0
GameObject* Eluna::CHECK_GAMEOBJECT(lua_State* L, int narg)
{
    WorldObject* obj = CHECK_WORLDOBJECT(L, narg);
    if(!obj)
        return NULL;
    return obj->ToGameObject();
}
Exemple #8
0
Player* Eluna::CHECK_PLAYER(lua_State* L, int narg)
{
    WorldObject* obj = CHECK_WORLDOBJECT(L, narg);
    if(!obj)
        return NULL;
    return obj->ToPlayer();
}
Exemple #9
0
bool World::move(WorldObject* const worldObject, const int direction,
				 const int maxPower, int& usedPower)
{
	Position p(0,0);
	WorldObject *object;

	WorldObjectList* list;
	if ( maxPower < usedPower)
		return false;
	p.x = worldObject->p->x;
	p.y = worldObject->p->y;

	Direction::computePosition(&p,direction);
	if (checkPosition(&p) == false ) 
		return false;

	list = world[p.x][p.y];
	list->setToFirst();
	while(object = list->getNext())
		if(!object->conditionalMovement(worldObject,direction,maxPower,usedPower))
			return false;
		if(!moveObject(worldObject,direction))
			return false;
	return true;
}
Exemple #10
0
/**
 * Adds current path to WorldObjectManager's list. Note how we copy all the local
 * to a new instance of a path world object.
 */
bool PathTool::addCurrent()
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{
    bool returnValue = true;

    //only add path if it has more than 1 point
    if (mCurrentNumberOfPoints > 1)
    {
        WorldObject* worldObject = new WorldObject();
        worldObject->setName(mName);
        worldObject->setColor(mColor);
        worldObject->setGroup(WorldObject::PATH);

        //instantiate path renderer and associate it with world object
        PathRenderer* pathRenderer = new PathRenderer();
        for (int i = 0; i < mCurrentNumberOfPoints; i++)
        {
            pathRenderer->addPoint(mPoints[i]);
        }
        worldObject->setMeshRenderer(pathRenderer);

        //if object already exists (cannot add) perform cleanup
        if (!WorldObjectManager::getInstance()->addWorldObject(worldObject))
        {
            //note: the path renderer that we associated with this world
            //object will get deleted on the world object's destructor
            delete worldObject;
            returnValue = false;
        }
    }

    return returnValue;
}
Exemple #11
0
int ActionCover::scoreEvaluator(Actor* actor,Action* action)
{
	ActionCover* self = static_cast<ActionCover*>(action);
	Anchor* resAnchor = NULL;

	WorldObject* enemy = actor->getEnemy();
	if (!enemy)
		return 0;

	if (self->m_attackInfo && !self->m_attackInfo->coverState.empty())
	{
		//check if there is anchor hereabout
		Anchors& anchors = Anchor::getAnchors();
		for (size_t i=0; i<anchors.size(); i++)
		{
			Anchor* anchor = anchors[i];
			float distToEnemySq = (anchor->getPos() - enemy->getPos()).lengthSq();
			if (distToEnemySq < MIN_DIST_TO_ENEMY*MIN_DIST_TO_ENEMY)
				continue;

			//.todo: check conditions(i.e. reasonable distance, availability, etc)
			if (anchor->isVacant(actor))
			{
				resAnchor = anchor;
				break;
			}
		}
	}

	if (resAnchor)
		return 5;
	else
		return 0;
}
Exemple #12
0
float ActionCover::anchorRankEvaluator(Anchor* anchor)
{
	float rank = -1.f;
	if (anchor->isVacant(m_owner))
	{
		float dist = anchor->getDistSq(m_owner->getPos());

		WorldObject* enemy = m_owner->getEnemy();
		if (!enemy)
			return rank;
		float distToEnemySq = (anchor->getPos() - enemy->getPos()).lengthSq();
		if (distToEnemySq < MIN_DIST_TO_ENEMY*MIN_DIST_TO_ENEMY)
			return rank;

		if (dist < MAX_DIST_TO_ANCHOR*MAX_DIST_TO_ANCHOR)
		{
			rank = 1.f/dist;

			AnchorStatMap::iterator it = m_anchorStat.find(anchor);
			unsigned int occupancyTime = it!=m_anchorStat.end() ? it->second : 0;
			float occupancyTimeSec = (float) occupancyTime / 1000.f;
			if (m_anchor == anchor && occupancyTimeSec < 10.f)
			{
				rank += 5.f; //persistence
			}
			else if(m_anchor != anchor && occupancyTimeSec < 5.f)
			{
				rank += 5.f - occupancyTimeSec;
			}
		}
	}

	return rank;
};
	//---------------------------------------------------------------------------
	MouseEventResult SelectingObjectsWithMouse::mousePressed( const MouseEvent& _evt )
	{
		World* world = WorldManager::getSingleton().getActiveWorld();
		if(!world)
			return MouseEventResult::NOT_PROCESSED;

		Camera* camera = world->getCamera();
		SceneManagerEx* sm = world->getSceneManager();

		RaySceneQueryExPtr q = sm->createRayQueryEx(_evt.getAbsX(), _evt.getAbsY(), world->getViewportAbsCoord(), camera);
		q->setQueryTypeMask( SceneQueryMask::VOB | SceneQueryMask::INVISIBLE_IN_GAME );
		q->setMaxResults(1);
		RaySceneQueryExResult& result = q->execute();

		world->deselectAll();

		if(!result.empty())
		{
			WorldObject* worldObject = WorldObject::getFromMovableObject(result.front().movable);
			if(worldObject)
				worldObject->select();
		}

		return MouseEventResult::PROCESSED;
	}
Exemple #14
0
void onDisplay() {
	if(showPreformance)
		fps++;
	/* Clear the background as white */
	glClearColor(1.0, 1.0, 1.0, 1.0);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	
	glutSolidCube(1.0);
	glUseProgram(cube.getProgram());
		cube.render();
	glUseProgram(cube2.getProgram());
		cube2.render();
		glTranslatef(0.4f,0.4f,0.4f);
		cube2.render();

	for (int i = 0; i < BALLS; i++) {
		glUseProgram(balls[i].getProgram());
			balls[i].render();
	}
	for (int i = 0; i < DETAIL_GRID*3; i++) {
		glUseProgram(grid[i].getProgram());
			grid[i].render();
	}

	glUseProgram(0);
	PreformanceIRL(1);
	/* Display the result */ 
	glutSwapBuffers();
}
Exemple #15
0
void MoveSplineInitArgs::SetTransportData(Unit& unit)
{
    WorldObject* transport = NULL;
    ObjectGuid _transportGuid = unit.GetTransportGuid();
    switch(_transportGuid.GetHigh())
    {
        case HIGHGUID_PLAYER:
        case HIGHGUID_VEHICLE:
            transport = unit.GetMap()->GetUnit(_transportGuid);
            break;
        case HIGHGUID_MO_TRANSPORT:
            transport = unit.GetMap()->GetTransport(_transportGuid);
            break;
        case HIGHGUID_TRANSPORT:
            transport = unit.GetMap()->GetGameObject(_transportGuid);
            break;
    }

    if (!transport)
    {
        ERROR_LOG("MoveSplineInitArgs: Unsupported transport %s for %s", _transportGuid.GetString().c_str(), unit.GetObjectGuid().GetString().c_str());
        return;
    }
    else
        DEBUG_LOG("MoveSplineInitArgs: Set transport %s for %s", _transportGuid.GetString().c_str(), unit.GetObjectGuid().GetString().c_str());

    transportGuid = _transportGuid.GetRawValue();
    transportSeat = unit.GetTransSeat();
    transportPos = Location(transport->GetPositionX(), transport->GetPositionY(), transport->GetPositionZ(), transport->GetOrientation());
}
// Update the global position of a passenger
void TransportBase::UpdateGlobalPositionOf(ObjectGuid const& passengerGuid, Position const& pos) const
{
    WorldObject* passenger = GetOwner()->GetMap()->GetWorldObject(passengerGuid);

    if (!passenger)
        return;

    Position g = CalculateGlobalPositionOf(pos);

    switch(passenger->GetTypeId())
    {
        case TYPEID_GAMEOBJECT:
        case TYPEID_DYNAMICOBJECT:
            m_owner->GetMap()->Relocation((GameObject*)passenger, g);
            break;
        case TYPEID_UNIT:
            m_owner->GetMap()->Relocation((Creature*)passenger, g);
            // If passenger is vehicle
            if (((Unit*)passenger)->IsVehicle())
                ((Unit*)passenger)->GetVehicleKit()->UpdateGlobalPositions();
            break;
        case TYPEID_PLAYER:
            m_owner->GetMap()->Relocation((Player*)passenger, g);
            // If passenger is vehicle
            if (((Unit*)passenger)->IsVehicle())
                ((Unit*)passenger)->GetVehicleKit()->UpdateGlobalPositions();
            break;
        case TYPEID_CORPSE:
        // TODO - add corpse relocation
        default:
            break;
    }
}
Exemple #17
0
void ClusterBomb::explode()
{
#ifdef DEBUG
//  printf("ClusterBomb just exploded!\n");
#endif
  WorldObject * wo;
  float angle = 6.28318 / BOMB_PIECES;
  Vector a = Vector(1, 0, 0);
  Vector b = Vector(0, 0, 1);
  Vector c = Vector(0, .1, 0);
  float mag = global::factory->getBlueprint(type).getSize().mag() / 4;
  Vector off;
  for (int i = 0; i < BOMB_PIECES; i++)
  {
    wo = new WorldObject(0, 0, DUMMY_SPHERE);
    off = a * mag * sin(i * angle) + b * mag * cos(i * angle) + c;
    wo->setPosition(position + off);
    wo->setVelocity(velocity + off);
    networkManager->network->getPhysicsPtr()->insertWorldObject(wo);
    wo = new WorldObject(0, 0, DUMMY_SPHERE);
    off = a * mag * cos(i * angle) + b * mag * sin(i * angle) - c;
    wo->setPosition(position + off);
    wo->setVelocity(velocity + off);
    networkManager->network->getPhysicsPtr()->insertWorldObject(wo);
  }
}
void World::massiveDamage(const Vec2 &pos, int range, int damage)
{
    // Пробегаем по всем объектам.
    for ( std::list< WorldObject* >::iterator it = items.begin();
          it != items.end();
          ++it )
    {

        // Нас интересуют пони.
        if ( ( *it )->isTargetable() )
        {
            WorldObject* unit = *it;

            // Интересуют только живые пони.
            if ( !unit->isDead() )
            {
                // Находим расстояние до этого пони.
                double distance = unit->getPos().distance(pos);

                // Если зацепили пони.
                if ( distance < range )
                {
                    unit->hit( static_cast< int > ( damage ) );
                }
            }
        }
    }
}
WorldObject *World::getNearestTarget(const Vec2 &pos, int range)
{
    double minRange = 100000000;
    WorldObject *target = nullptr;

    for (std::list<WorldObject *>::iterator it = items.begin();
         it != items.end();
         ++it)
    {
        WorldObject *unit = *it;

        if (!unit->isTargetable())
            continue;

        if (unit->isDead())
            continue;

        double distance = pos.distance(unit->getPos());
        if (distance < range)
        {
            if (distance < minRange)
            {
                minRange = distance;
                target = unit;
            }
        }
    }

    return target;
}
Exemple #20
0
    static bool HandleMmapTestArea(ChatHandler* handler, char const* /*args*/)
    {
        float radius = 40.0f;
        WorldObject* object = handler->GetSession()->GetPlayer();

        // Get Creatures
        std::list<Creature*> creatureList;
        Trinity::AnyUnitInObjectRangeCheck go_check(object, radius);
        Trinity::CreatureListSearcher<Trinity::AnyUnitInObjectRangeCheck> go_search(object, creatureList, go_check);
        Cell::VisitGridObjects(object, go_search, radius);

        if (!creatureList.empty())
        {
            handler->PSendSysMessage("Found %zu Creatures.", creatureList.size());

            uint32 paths = 0;
            uint32 uStartTime = getMSTime();

            float gx, gy, gz;
            object->GetPosition(gx, gy, gz);
            for (std::list<Creature*>::iterator itr = creatureList.begin(); itr != creatureList.end(); ++itr)
            {
                PathGenerator path(*itr);
                path.CalculatePath(gx, gy, gz);
                ++paths;
            }

            uint32 uPathLoadTime = getMSTimeDiff(uStartTime, getMSTime());
            handler->PSendSysMessage("Generated %i paths in %i ms", paths, uPathLoadTime);
        }
        else
            handler->PSendSysMessage("No creatures in %f yard range.", radius);

        return true;
    }
float FighterFightTask::angleToTarget() {
    WorldObject* worldObject = boardComputer()->worldObject();
    glm::vec3 shipDirection = glm::vec3(0, 0, -1);
    glm::vec3 targetDirection = glm::inverse(worldObject->transform().orientation()) * safeNormalize(m_primaryTarget->transform().position() - worldObject->transform().position(), glm::vec3(0, 0, 1));
    float angle = GeometryHelper::angleBetween(shipDirection, targetDirection);
    return glm::degrees(angle);
}
glm::vec3 FighterFightTask::findRandomEvasionPoint() {
    WorldObject* worldObject = boardComputer()->worldObject();
    glm::vec3 point = glm::vec3(RandFloat::rand(-0.25f, 0.25), RandFloat::rand(-0.25f, 0.25), -1);
    point *= 3 * m_minEnemyDistance;
    point = point * worldObject->transform().orientation();
    point += worldObject->transform().position();
    return point;
}
Exemple #23
0
void Symmetry::draw(ShaderProgram*  shader) {
	for (Map::iterator it = originalObjects->begin(); it != originalObjects->end(); ++it) {
		WorldObject * wo = it->second;
		//wo->setPosTrans(transform());
		wo->draw(shader);
		//wo->setPosTrans(glm::mat4(1.0f));
	}
}
Exemple #24
0
void Transport::UnloadStaticPassengers()
{
    while (!_staticPassengers.empty())
    {
        WorldObject* obj = *_staticPassengers.begin();
        obj->AddObjectToRemoveList();   // also removes from _staticPassengers
    }
}
Exemple #25
0
/**
  Walk recursively through a node and switch on all lights.

  \param node World object to search for lights
 */
void GLRenderInstance::applyLights(WorldObject& node)
{
  double M[16];
  int idx=0;

  WorldObject::ChildIterator it;
  for(it=node.childsBegin(); it!=node.childsEnd(); it++)
  {
    glPushMatrix();
    // Set the local transformation
    it->second->localTransform().toList(M);
    glMultMatrixd(M);

    // Check if the object is a light source...
    LightSource* lgt = dynamic_cast<LightSource*>(it->second.get());
    if (lgt!=0)
    {
      // Is it a point light?
      GLPointLight* pntlgt = dynamic_cast<GLPointLight*>(lgt);
      if (pntlgt!=0)
      {
        if (pntlgt->enabled.getValue())
        {
          pntlgt->applyGL(idx);
          glEnable(GL_LIGHT0+idx);
          idx++;
        }
      }
      // Is it a spot light?
      GLSpotLight* spotlgt = dynamic_cast<GLSpotLight*>(lgt);
      if (spotlgt!=0)
      {
        if (spotlgt->enabled.getValue())
        {
          spotlgt->applyGL(idx);
          glEnable(GL_LIGHT0+idx);
          idx++;
        }
      }
      // Is it a distant light?
      GLDistantLight* dstlgt = dynamic_cast<GLDistantLight*>(lgt);
      if (dstlgt!=0)
      {
        if (dstlgt->enabled.getValue())
        {
          dstlgt->applyGL(idx);
          glEnable(GL_LIGHT0+idx);
          idx++;
        }
      }
    }

    // Search the children for lights
    applyLights(*(it->second));
    glPopMatrix();
  }
}
void CollisionManager::perform_collision_bullet(vector<WorldObject*> victims,
        vector<Projectile*> bullets) {
    vector<WorldObject*>::iterator victims_it;
    vector<Projectile*>::iterator bullets_it;

    if (bullets.size() < 1) {
        return;
    }

    if (victims.size() < 1) {
        return;
    }

    for (victims_it = victims.begin(); victims_it != victims.end(); victims_it++) {
        WorldObject* victim = (*victims_it);

        if (!victim->getcollisionable()) {
            continue;
        }

        // check collision for each bullet
        for (bullets_it = bullets.begin(); bullets_it != bullets.end(); bullets_it++) {
            Projectile* bullet = (*bullets_it);

            if ((bullet->getx() >= (victim->getx() - MAX_DISTANCE_FOR_COLLISION))
                    && (bullet->gety() >= (victim->gety() - MAX_DISTANCE_FOR_COLLISION))) {

                int bullet_min_x = bullet->getx();
                int bullet_min_y = bullet->gety();
                int bullet_max_x = bullet->getx() + bullet->getwidth();
                int bullet_max_y = bullet->gety() + bullet->getheight();

                int victim_min_x = victim->getx();
                int victim_min_y = victim->gety();
                int victim_max_x = victim->getx() + victim->getsurface()->w;
                int victim_max_y = victim->gety() + victim->getsurface()->h;

                if (((bullet_max_x > victim_min_x) &&
                        (bullet_max_y > victim_min_y) &&
                        (bullet_min_x < victim_max_x) &&
                        (bullet_min_y < victim_max_y)) ||
                        (bullet_min_x < 0 ||
                         bullet_max_x > DrawEngine::get_screen_width() ||
                         bullet_min_y < 0 ||
                         bullet_max_y > DrawEngine::get_screen_height())) {

                    // remove the bullet
                    GarbageCollector::add_deletion_queue(bullet);
                }
            }

            if ((bullet->getx() > (bullet->getorgx() + 300)) ||
                    (bullet->gety() > (bullet->getorgy() + 300))) {
                // if the bullet has been fired over 300 px, lets delete
                GarbageCollector::add_deletion_queue(bullet);
            }
        }
    }
}
Exemple #27
0
void Instance::releaseIfInactive(void)
{
	WorldObject *op = static_cast<WorldObject*>(objectList->get(id));

	float dist = cam->distanceTo(position)/renderer->lodMult;
	int ai = op->getCorrectAtomic(dist);

	if (ai < 0 && isActive) {
		op->decRefCount();
		isActive = false;
	}
}
Exemple #28
0
void WorldSession::HandleObjectCreate()
{
    uint64 GUID;
    uint32 Entry;
    uint16 x, y;
    RecPckt >> GUID >> Entry >> x >> y;
    WorldObject* pObject = new WorldObject(Entry, GUID);
    pObject->SetPosition(sf::Vector2f(x, y));
    pObject->SetAnimationSpeed(sf::milliseconds(300)); // TODO: Should be part of animation template
    pWorld->Insert(pObject);
    ObjectHolder<WorldObject>::Insert(pObject); // TODO: Type mask
}
void Transport::CleanupsBeforeDelete(bool finalCleanup /*= true*/)
{
    UnloadStaticPassengers();
    while (!_passengers.empty())
    {
        WorldObject* obj = *_passengers.begin();
        obj->m_movementInfo.transport.Reset();
        obj->SetTransport(NULL);
        RemovePassenger(obj);
    }

    GameObject::CleanupsBeforeDelete(finalCleanup);
}
void PacketHandlers::HandleInteractionRequest(Session* sess, SmartPacket& packet)
{
    uint64_t guid = packet.ReadUInt64();

    WorldObject* obj = sObjectAccessor->FindWorldObject(guid);
    if (!obj)
        return;

    // TODO: distance check

    if (obj->GetType() == OTYPE_CREATURE)
        obj->ToCreature()->Interact(sess->GetPlayer());
}