MapObject*	CMapObjectManager::getObjectNearBy(int cx,int cy,MapObjectType type)
{
	Rect rect;
	m_pMap->getViewRect(rect);

	float x = 0;
	float y = 0;

	MapObject* pRet = NULL;
	const int minD = 3;     //最小格子距离
	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr)
	{
		MapObject* pObject = *itr;
		if ( pObject  && !pObject->GetDeleted() )
		{
			x = pObject->getPositionX();
			y = pObject->getPositionY();
			int distance = Distance(cx,cy,pObject->GetCellX(),pObject->GetCellY());
			if ( rect.containsPoint(Point(x,y)) && pObject->GetType() == type  && distance < minD )
			{
				pRet = pObject;
				//minD = distance;
			}
		}
	}

	return pRet;
}
int	CMapObjectManager::getObjectsInView(MapObjectType type,MapObjectList& objects)
{
	Rect rect;
	m_pMap->getViewRect(rect);

	float x = 0;
	float y = 0;

	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr)
	{
		MapObject* pObject = *itr;
		if ( pObject && !pObject->GetDeleted() )
		{
			x = pObject->getPositionX();
			y = pObject->getPositionY();

			if ( rect.containsPoint(Point(x,y)) && pObject->GetType() == type )
			{
				objects.push_back(pObject);
			}
		}
	}

	return (int)objects.size();
}
int	CMapObjectManager::getObjects(MapObjectType type,MapObjectList& objects)
{
	objects.clear();
	for ( MapObjectList::iterator itr = m_Objects.begin();itr != m_Objects.end();++itr)
	{
		MapObject* pObject = *itr;
		if ( pObject  && !pObject->GetDeleted() && pObject->GetType() == type )
		{
			objects.push_back(pObject);
		}
	}

	return (int)objects.size();
}
Beispiel #4
0
void DialogueSupervisor::_BeginLine()
{
    // Starts possible events at new line.
    MapMode *map_mode = MapMode::CurrentInstance();
    std::string line_event = _current_dialogue->GetLineBeginEvent(_line_counter);
    if(!line_event.empty() && !map_mode->GetEventSupervisor()->IsEventActive(line_event)) {
        map_mode->GetEventSupervisor()->StartEvent(line_event);
    }

    // The current speaker id
    uint32 speaker_id = _current_dialogue->GetLineSpeaker(_line_counter);

    // Starts possible emote first.
    std::string emote_event = _current_dialogue->GetLineEmote(_line_counter);
    if(!emote_event.empty() && !_emote_triggered) {
        MapSprite* sprite = (speaker_id > 0) ?
            dynamic_cast<MapSprite *>(map_mode->GetObjectSupervisor()->GetObject(speaker_id))
            : NULL;

        if(sprite) {
            sprite->Emote(emote_event, (vt_map::private_map::ANIM_DIRECTIONS)sprite->GetCurrentAnimationDirection());
            _state = DIALOGUE_STATE_EMOTE;
            _emote_triggered = true;
            return;
        }
    }

    _emote_triggered = true;
    _state = DIALOGUE_STATE_LINE;
    _current_options = dynamic_cast<MapDialogueOptions *>(_current_dialogue->GetLineOptions(_line_counter));

    // Initialize the line timer
    if(_current_dialogue->GetLineDisplayTime(_line_counter) >= 0) {
        _line_timer.Initialize(_current_dialogue->GetLineDisplayTime(_line_counter));
        _line_timer.Run();
    }
    // If the line has no timer specified, set the line time to zero and put the timer in the finished state
    else {
        _line_timer.Initialize(0);
        _line_timer.Finish();
    }

    // Setup the text and graphics for the dialogue window
    _dialogue_window.Clear();
    _dialogue_window.GetDisplayTextBox().SetDisplayText(_current_dialogue->GetLineText(_line_counter));

    MapObject *object = speaker_id > 0 ? map_mode->GetObjectSupervisor()->GetObject(speaker_id) : NULL;
    if(object && object->GetType() != SPRITE_TYPE) {
        IF_PRINT_WARNING(MAP_DEBUG) << "dialogue #" << _current_dialogue->GetDialogueID()
            << " referenced a map object which was not a sprite with id: " << speaker_id << std::endl;
        return;
    }

    if(!object) {
        // Clear the speaker name and potential portrait.
        _dialogue_window.GetNameText().Clear();
        _dialogue_window.SetPortraitImage(NULL);
    } else {
        MapSprite *speaker = dynamic_cast<MapSprite *>(object);
        _dialogue_window.GetNameText().SetText(speaker->GetName());
        _dialogue_window.SetPortraitImage(speaker->GetFacePortrait());
    }

    if(_current_options) {
        for(uint32 i = 0; i < _current_options->GetNumberOptions(); ++i)
            _dialogue_window.GetDisplayOptionBox().AddOption(_current_options->GetOptionText(i));

        _dialogue_window.GetDisplayOptionBox().SetSelection(0);
        _state = DIALOGUE_STATE_OPTION;
    }
}
Beispiel #5
0
void MapMode::_UpdateExplore()
{
    // First go to menu mode if the user requested it
    if(_menu_enabled && InputManager->MenuPress()) {
        MenuMode *MM = new MenuMode();
        ModeManager->Push(MM);
        return;
    }

    // Only update the status effect supervisor in Exploration mode
    // and if they are allowed.
    if (_status_effects_enabled)
        _status_effect_supervisor.UpdateEffects();

    // Update the running state of the camera object. Check if the character is running and if so,
    // update the stamina value if the operation is permitted
    _camera->is_running = false;
    if(_camera->moved_position && !_running_disabled && InputManager->CancelState() &&
            (InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState())) {
        if(_unlimited_stamina) {
            _camera->is_running = true;
        } else if(_run_stamina > SystemManager->GetUpdateTime() * 2) {
            _run_stamina -= (SystemManager->GetUpdateTime() * 2);
            _camera->is_running = true;
        } else {
            _run_stamina = 0;
        }
    }
    // Regenerate the stamina at 1/2 the consumption rate
    else if(_run_stamina < 10000) {
        _run_stamina += SystemManager->GetUpdateTime();
        if(_run_stamina > 10000)
            _run_stamina = 10000;
    }

    // If the user requested a confirm event, check if there is a nearby object that the player may interact with
    // Interactions are currently limited to dialogue with sprites and opening of treasures
    if(InputManager->ConfirmPress()) {
        MapObject *obj = _object_supervisor->FindNearestInteractionObject(_camera);

        if(obj != NULL) {
            if(obj->GetType() == PHYSICAL_TYPE) {
                PhysicalObject *phs = reinterpret_cast<PhysicalObject *>(obj);

                if(!phs->GetEventIdWhenTalking().empty()) {
                    _camera->moving = false;
                    _camera->is_running = false;
                    if (!_event_supervisor->IsEventActive(phs->GetEventIdWhenTalking()))
                        _event_supervisor->StartEvent(phs->GetEventIdWhenTalking());
                    return;
                }
            }
            else if(obj->GetType() == SPRITE_TYPE) {
                MapSprite *sp = reinterpret_cast<MapSprite *>(obj);

                if(sp->HasAvailableDialogue()) {
                    _camera->moving = false;
                    _camera->is_running = false;
                    sp->InitiateDialogue();
                    return;
                }
            } else if(obj->GetType() == TREASURE_TYPE) {
                TreasureObject *treasure_object = reinterpret_cast<TreasureObject *>(obj);

                if(!treasure_object->GetTreasure()->IsTaken()) {
                    _camera->moving = false;
                    treasure_object->Open();
                }
            } else if(obj->GetType() == SAVE_TYPE && _save_points_enabled) {
                // Make sure the character will be centered in the save point
                SaveMode *save_mode = new SaveMode(true, obj->GetXPosition(), obj->GetYPosition() - 1.0f);
                ModeManager->Push(save_mode, false, false);
            }
        }
    }

    // Detect movement input from the user
    if(InputManager->UpState() || InputManager->DownState() || InputManager->LeftState() || InputManager->RightState()) {
        _camera->moving = true;
    } else {
        _camera->moving = false;
    }

    // Determine the direction of movement. Priority of movement is given to: up, down, left, right.
    // In the case of diagonal movement, the direction that the sprite should face also needs to be deduced.
    if(_camera->moving == true) {
        if(InputManager->UpState()) {
            if(InputManager->LeftState())
                _camera->SetDirection(MOVING_NORTHWEST);
            else if(InputManager->RightState())
                _camera->SetDirection(MOVING_NORTHEAST);
            else
                _camera->SetDirection(NORTH);
        } else if(InputManager->DownState()) {
            if(InputManager->LeftState())
                _camera->SetDirection(MOVING_SOUTHWEST);
            else if(InputManager->RightState())
                _camera->SetDirection(MOVING_SOUTHEAST);
            else
                _camera->SetDirection(SOUTH);
        } else if(InputManager->LeftState()) {
            _camera->SetDirection(WEST);
        } else if(InputManager->RightState()) {
            _camera->SetDirection(EAST);
        }
    } // if (_camera->moving == true)
} // void MapMode::_UpdateExplore()
Beispiel #6
0
void WorldMap::Click(MapObject& obj)
{
	sf::Vector2i node = GetIndex(obj.GetPos());
	mapGrid[node.y][node.x].second.ChangeType(obj.GetType());
}