Example #1
0
// The destructor frees all the modes still on the stack
ModeEngine::~ModeEngine()
{
    IF_PRINT_WARNING(MODE_MANAGER_DEBUG)
            << "MODE MANAGER: ModeEngine destructor invoked" << std::endl;
    // Delete any game modes on the stack
    while(!_game_stack.empty()) {
        delete _game_stack.back();
        _game_stack.pop_back();
    }

    // Delete any game modes on the push stack
    while(!_push_stack.empty()) {
        delete _push_stack.back();
        _push_stack.pop_back();
    }

    delete _help_window;
}
void IndicatorSupervisor::AddHealingIndicator(uint32 amount, bool hit_points) {
	const Color low_green(0.0f, 1.0f, 0.60f, 1.0f);
	const Color mid_green(0.0f, 1.0f, 0.30f, 1.0f);
	const Color high_green(0.0f, 1.0f, 0.15f, 1.0f);

	const Color low_blue(0.0f, 0.60f, 1.0f, 1.0f);
	const Color mid_blue(0.0f, 0.30f, 1.0f, 1.0f);
	const Color high_blue(0.0f, 0.15f, 1.0f, 1.0f);

	if (amount == 0) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function was given a zero value argument" << std::endl;
		return;
	}

	std::string text = NumberToString(amount);
	TextStyle style;

	// TODO: use different colors/shades of green for different degrees of damage. There's a
	// bug in rendering colored text that needs to be addressed first.
	float healing_percent = static_cast<float>(amount / _actor->GetMaxHitPoints());
	if (healing_percent < 0.10f) {
		style.font = "text24";
		style.color = hit_points ? low_green : low_blue;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}
	else if (healing_percent < 0.20f) {
		style.font = "text24";
		style.color = hit_points ? mid_green : mid_blue;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}
	else if (healing_percent < 0.30f) {
		style.font = "text24";
		style.color = hit_points ? high_green : high_blue;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}
	else { // (healing_percent >= 0.30f)
		style.font = "text24";
		style.color = hit_points ? Color::green : Color::blue;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}

	_wait_queue.push_back(new IndicatorText(_actor, text, style, HEALING_INDICATOR));
}
Example #3
0
uint16 CalculateOppositeDirection(const uint16 direction) {
	switch (direction) {
		case NORTH:      return SOUTH;
		case SOUTH:      return NORTH;
		case WEST:       return EAST;
		case EAST:       return WEST;
		case NW_NORTH:   return SE_SOUTH;
		case NW_WEST:    return SE_EAST;
		case NE_NORTH:   return SW_SOUTH;
		case NE_EAST:    return SW_WEST;
		case SW_SOUTH:   return NE_NORTH;
		case SW_WEST:    return NE_EAST;
		case SE_SOUTH:   return NW_NORTH;
		case SE_EAST:    return NW_WEST;
		default:
			IF_PRINT_WARNING(MAP_DEBUG) << "invalid direction argument: " << direction << endl;
			return SOUTH;
	}
}
Example #4
0
bool DecrementIntensity(GLOBAL_INTENSITY &intensity, uint8 amount)
{
    if(amount == 0)
        return false;
    if((intensity <= GLOBAL_INTENSITY_NEG_EXTREME) || (intensity >= GLOBAL_INTENSITY_TOTAL))
        return false;

    // This check protects against overflow conditions
    if(amount > (GLOBAL_INTENSITY_TOTAL * 2)) {
        IF_PRINT_WARNING(GLOBAL_DEBUG) << "attempted to decrement intensity by an excessive amount: " << amount << std::endl;
        intensity = GLOBAL_INTENSITY_NEG_EXTREME;
        return true;
    }

    intensity = GLOBAL_INTENSITY(intensity - amount);
    if(intensity <= GLOBAL_INTENSITY_INVALID)
        intensity = GLOBAL_INTENSITY_NEG_EXTREME;
    return true;
}
void DialogueSupervisor::AnnounceDialogueUpdate(uint32 dialogue_id) {
	map<uint32, vector<uint32> >::iterator entry = _sprite_references.find(dialogue_id);

	// Note that we don't print a warning if no entry was found, because the case where a dialogue exists
	// but is not referenced by any sprites is a valid one
	if (entry == _sprite_references.end())
		return;

	// Update the dialogue status of all sprites that reference this dialogue
	for (uint32 i = 0; i < entry->second.size(); i++) {
		MapSprite* referee = static_cast<MapSprite*>(MapMode::CurrentInstance()->GetObjectSupervisor()->GetObject(entry->second[i]));
		if (referee == NULL) {
			IF_PRINT_WARNING(MAP_DEBUG) << "map sprite: " << entry->second[i] << " references dialogue: " << dialogue_id << " but sprite object did not exist"<< endl;
		}
		else {
			referee->UpdateDialogueStatus();
		}
	}
}
void AudioSource::Reset()
{
    owner = NULL;

    if(IsValid() == false) {
        return;
    }

    alSourcei(source, AL_LOOPING, AL_FALSE);
    alSourcef(source, AL_GAIN, 1.0f);
    alSourcei(source, AL_SAMPLE_OFFSET, 0);		// This line will cause AL_INVALID_ENUM error in linux/Solaris. It is normal.
    alSourcei(source, AL_BUFFER, 0);

    if(AudioManager->CheckALError()) {
#ifdef WIN32
        IF_PRINT_WARNING(AUDIO_DEBUG) << "resetting source failed: " << AudioManager->CreateALErrorString() << std::endl;
#endif
    }
}
Example #7
0
void ResidentZone::AddPotentialResident(VirtualSprite* sprite) {
	if (sprite == NULL) {
		IF_PRINT_WARNING(MAP_DEBUG) << "function received NULL argument" << endl;
		return;
	}

	// Check that sprite is not already a resident
	if (IsSpriteResident(sprite) == true) {
		return;
	}

	// Check that the sprite's context is compatible with this zone and is located within the zone boundaries
	if (sprite->GetContext() & _active_contexts) {
		if (IsInsideZone(sprite->GetXPosition(), sprite->GetYPosition())) {
			_entering_residents.insert(sprite);
			_residents.insert(sprite);
		}
	}
}
Example #8
0
void TreasureObject::Open()
{
    if(!_treasure) {
        PRINT_ERROR << "Can't open treasure with invalid treasure content." << std::endl;
        return;
    }

    if(_treasure->IsTaken()) {
        IF_PRINT_WARNING(MAP_DEBUG) << "attempted to retrieve an already taken treasure: " << _object_id << std::endl;
        return;
    }

    // Test whether events should be triggered
    if (_events.empty())
        _events_triggered = true;

    SetCurrentAnimation(TREASURE_OPENING_ANIM);
    _is_opening = true;
}
Example #9
0
void VideoEngine::MakeScreenshot(const std::string &filename)
{
    private_video::ImageMemory buffer;

    // Retrieve the width and height of the viewport.
    GLint viewport_dimensions[4]; // viewport_dimensions[2] is the width, [3] is the height
    glGetIntegerv(GL_VIEWPORT, viewport_dimensions);

    // Buffer to store the image before it is flipped
    buffer.width = viewport_dimensions[2];
    buffer.height = viewport_dimensions[3];
    buffer.pixels = malloc(buffer.width * buffer.height * 3);
    buffer.rgb_format = true;

    // Read the viewport pixel data
    glReadPixels(viewport_dimensions[0], viewport_dimensions[1],
                 buffer.width, buffer.height, GL_RGB, GL_UNSIGNED_BYTE, buffer.pixels);

    if(CheckGLError() == true) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "an OpenGL error occured: " << CreateGLErrorString() << std::endl;

        free(buffer.pixels);
        buffer.pixels = NULL;
        return;
    }

    // Vertically flip the image, then swap the flipped and original images
    void *buffer_temp = malloc(buffer.width * buffer.height * 3);
    for(uint32 i = 0; i < buffer.height; ++i) {
        memcpy((uint8 *)buffer_temp + i * buffer.width * 3,
               (uint8 *)buffer.pixels + (buffer.height - i - 1) * buffer.width * 3, buffer.width * 3);
    }
    void *temp = buffer.pixels;
    buffer.pixels = buffer_temp;
    buffer_temp = temp;

    buffer.SaveImage(filename);

    free(buffer_temp);
    free(buffer.pixels);
    buffer.pixels = NULL;
}
Example #10
0
void DialogueSupervisor::AddSpeaker(const std::string& speaker_id, const std::string& name, const std::string& portrait)
{
    if(_speakers.find(speaker_id) != _speakers.end()) {
        PRINT_WARNING << "Speaker already existed with requested id: " << speaker_id << std::endl;
        return;
    }

    Speaker new_speaker;
    new_speaker.name = MakeUnicodeString(name);
    if(!portrait.empty()) {
        if(!new_speaker.portrait.Load(portrait)) {
            IF_PRINT_WARNING(COMMON_DEBUG) << "invalid image filename for new portrait: " << portrait << std::endl;
        }
        // Make sure the portrait doesn't go over the screen edge.
        if(new_speaker.portrait.GetHeight() > 130.0f)
            new_speaker.portrait.SetHeightKeepRatio(130.0f);
    }

    _speakers[speaker_id] = new_speaker;
}
Example #11
0
void WriteScriptDescriptor::CloseFile() {
	if (IsFileOpen() == false) {
		IF_PRINT_WARNING(SCRIPT_DEBUG)
			<< "SCRIPT ERROR: in WriteScriptDescriptor::CloseFile(), could not close the "
			<< "file because it was not open." << std::endl;
		return;
	}

	if (SCRIPT_DEBUG && IsErrorDetected()) {
		PRINT_WARNING << "SCRIPT WARNING: In WriteScriptDescriptor::CloseFile(), the file " << _filename
			<< " had error messages remaining. They are as follows:" << std::endl
		    << _error_messages.str() << std::endl;
	}

	_outfile.close();
	_error_messages.clear();
	_open_tables.clear();
	_access_mode = SCRIPT_CLOSED;
	ScriptManager->_RemoveOpenFile(this);
}
Example #12
0
void AudioEngine::PlaySound(const std::string &filename)
{
    std::map<std::string, AudioCacheElement>::iterator element = _audio_cache.find(filename);

    if(element == _audio_cache.end()) {
        // Don't check the current game mode to prevent the sound unloading in certain cases.
        // We'll let the audio cache handle it all atm.
        if(!LoadSound(filename)) {
            IF_PRINT_WARNING(AUDIO_DEBUG)
                    << "could not play sound from cache because "
                    "the sound could not be loaded" << std::endl;
            return;
        } else {
            element = _audio_cache.find(filename);
        }
    }

    element->second.audio->Play();
    element->second.last_update_time = SDL_GetTicks();
}
bool TextureController::_SaveTempTextures() {
	bool success = true;

	for (map<string, ImageTexture*>::iterator i = _images.begin(); i != _images.end(); i++) {
		ImageTexture *image = i->second;

		// Check that this is a temporary texture and if so, save it to disk as a .png file
		if (image->tags.find("<T>") != string::npos) {
			IF_PRINT_DEBUG(VIDEO_DEBUG) << " saving temporary texture " << image->filename << endl;
			ImageMemory buffer;
			buffer.CopyFromImage(image);
			string path = GetUserDataPath(true);
			if (buffer.SaveImage(path + image->filename + ".png", true) == false) {
				success = false;
				IF_PRINT_WARNING(VIDEO_DEBUG) << "call to ImageMemory::SaveImage() failed" << endl;
			}
		}
	}
	return success;
}
Example #14
0
void DialogueSupervisor::BeginDialogue(uint32 dialogue_id)
{
    SpriteDialogue *dialogue = GetDialogue(dialogue_id);

    if(dialogue == NULL) {
        PRINT_WARNING << "Could not begin dialogue because none existed for id: " << dialogue_id << std::endl
            << "Did you register the dialogue using 'AddDialogue()'?" << std::endl;
        return;
    }

    if(_current_dialogue != NULL) {
        IF_PRINT_WARNING(COMMON_DEBUG) << "beginning a new dialogue while another dialogue is still active" << std::endl;
    }

    _line_counter = 0;
    _current_dialogue = dialogue;
    _emote_triggered = false;
    _BeginLine();
    MapMode::CurrentInstance()->PushState(STATE_DIALOGUE);
}
Example #15
0
void TextBox::Draw()
{
    if(_text.empty())
        return;

    if(_initialized == false) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "function failed because the textbox was not initialized:\n" << _initialization_errors << std::endl;
        return;
    }

    // Don't draw text window if parent window is hidden
    if(_owner && _owner->GetState() == VIDEO_MENU_STATE_HIDDEN)
        return;

    VideoManager->PushState();

    VideoManager->SetDrawFlags(_xalign, _yalign, VIDEO_BLEND, 0);

    /*
    // TODO: this block of code (scissoring for textboxes) does not work properly

    if (_owner) {
    	rect.Intersect(_owner->GetScissorRect());
    }
    rect.Intersect(VideoManager->GetScissorRect());
    VideoManager->EnableScissoring(_owner || VideoManager->IsScissoringEnabled());
    if (VideoManager->IsScissoringEnabled()) {
    	VideoManager->SetScissorRect(_scissor_rect);
    }
    */

    // Set the draw cursor, draw flags, and draw the text
    VideoManager->Move(0.0f, _text_ypos);
    VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, VIDEO_BLEND, 0);
    _DrawTextLines(_text_xpos, _text_ypos, _scissor_rect);

    if(GUIManager->DEBUG_DrawOutlines())
        _DEBUG_DrawOutline();

    VideoManager->PopState();
} // void TextBox::Draw()
Example #16
0
AudioMemory::AudioMemory(AudioInput *input) :
    AudioInput(),
    _audio_data(nullptr),
    _data_position(0)
{
    _filename = input->GetFilename();
    _samples_per_second = input->GetSamplesPerSecond();
    _bits_per_sample = input->GetBitsPerSample();
    _number_channels = static_cast<uint8_t>(input->GetNumberChannels());
    _total_number_samples = input->GetTotalNumberSamples();
    _sample_size = input->GetSampleSize();
    _play_time = input->GetPlayTime();
    _data_size = input->GetDataSize();

    _audio_data = new uint8_t[input->GetDataSize()];
    bool all_data_read = false;
    input->Read(_audio_data, input->GetTotalNumberSamples(), all_data_read);
    if(all_data_read == false) {
        IF_PRINT_WARNING(AUDIO_DEBUG) << "failed to read entire audio data stream for file: " << _filename << std::endl;
    }
}
Example #17
0
bool TextTexture::Reload()
{
    // Regenerate text image if it is not already loaded in a texture sheet
    if(texture_sheet == NULL)
        return Regenerate();

    ImageMemory buffer;
    if(TextManager->_RenderText(string, style, buffer) == false)
        return false;

    if(texture_sheet->CopyRect(x, y, buffer) == false) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "call to TextureSheet::CopyRect() failed" << std::endl;
        free(buffer.pixels);
        buffer.pixels = NULL;
        return false;
    }

    free(buffer.pixels);
    buffer.pixels = NULL;
    return true;
}
Example #18
0
bool BattleTarget::IsValid(bool permit_dead_targets) {
	// No dead enemies can be selected here.
	if (IsTargetPoint(_type)) {
		if (!_actor)
			return false;
		bool enemy_actor = _actor->IsEnemy();

		if (_point >= _actor->GetAttackPoints().size())
			return false;
		// We extra check the actor HP since the state might desynced on purpose.
		else if (!_actor->IsAlive() || _actor->GetHitPoints() == 0)
			return !enemy_actor && permit_dead_targets;
		else if (_actor->GetState() == ACTOR_STATE_DYING)
			return !enemy_actor && permit_dead_targets;
		else
			return true;
	}
	else if (IsTargetActor(_type) == true) {
		if (!_actor)
			return false;
		bool enemy_actor = _actor->IsEnemy();

		if (!_actor->IsAlive() || _actor->GetHitPoints() == 0)
			return !enemy_actor && permit_dead_targets;
		else if (_actor->GetState() == ACTOR_STATE_DYING)
			return !enemy_actor && permit_dead_targets;
		else
			return true;
	}
	else if (IsTargetParty(_type)) {
		if (!_party)
			return false;
		else
			return true;
	}
	else {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _type << std::endl;
		return false;
	}
}
Example #19
0
void TradeInterface::_UpdateAvailableTradeDealTypes()
{
    _trade_deal_types = 0;

    // Determine what types of objects the shop deals in based on the managed object list
    std::map<uint32, ShopObject *>* trade_objects = ShopMode::CurrentInstance()->GetAvailableTrade();
    for(std::map<uint32, ShopObject *>::iterator it = trade_objects->begin(); it != trade_objects->end(); ++it) {
        vt_global::GLOBAL_OBJECT object_type = it->second->GetObject()->GetObjectType();
        switch(object_type) {
        case GLOBAL_OBJECT_ITEM:
            _trade_deal_types |= DEALS_ITEMS;
            break;
        case GLOBAL_OBJECT_WEAPON:
            _trade_deal_types |= DEALS_WEAPONS;
            break;
        case GLOBAL_OBJECT_HEAD_ARMOR:
            _trade_deal_types |= DEALS_HEAD_ARMOR;
            break;
        case GLOBAL_OBJECT_TORSO_ARMOR:
            _trade_deal_types |= DEALS_TORSO_ARMOR;
            break;
        case GLOBAL_OBJECT_ARM_ARMOR:
            _trade_deal_types |= DEALS_ARM_ARMOR;
            break;
        case GLOBAL_OBJECT_LEG_ARMOR:
            _trade_deal_types |= DEALS_LEG_ARMOR;
            break;
        case GLOBAL_OBJECT_SPIRIT:
            _trade_deal_types |= DEALS_SPIRIT;
            break;
        default:
            IF_PRINT_WARNING(SHOP_DEBUG) << "unknown object type sold in shop: " << object_type << std::endl;
            break;
        }

        // Also test whether this is a key item
        if (it->second->GetObject()->IsKeyItem())
            _trade_deal_types |= DEALS_KEY_ITEMS;
    }
}
bool ParticleEffect::Update(float frame_time)
{
    _age += frame_time;
    _num_particles = 0;

    if(!_alive)
        return true;

    bool success = true;

    hoa_mode_manager::EffectParameters effect_parameters;
    effect_parameters.orientation = _orientation;

    // note we subtract the effect position to put the attractor point in effect
    // space instead of screen space
    effect_parameters.attractor_x = _attractor_x - _x;
    effect_parameters.attractor_y = _attractor_y - _y;

    std::vector<ParticleSystem>::iterator iSystem = _systems.begin();

    while(iSystem != _systems.end()) {
        if(!(*iSystem).IsAlive()) {
            iSystem = _systems.erase(iSystem);

            if(_systems.empty())
                _alive = false;
        } else {
            if(!(*iSystem).Update(frame_time, effect_parameters)) {
                success = false;
                IF_PRINT_WARNING(VIDEO_DEBUG)
                        << "Failed to update system!" << std::endl;
            }

            _num_particles += (*iSystem).GetNumParticles();
            ++iSystem;
        }
    }

    return success;
}
Example #21
0
void EnemyZone::AddEnemy(EnemySprite* enemy, MapMode* map, uint8 count) {
	if (count == 0) {
		IF_PRINT_WARNING(MAP_DEBUG) << "function called with a count argument equal to zero" << endl;
		return;
	}

	// Prepare the first enemy
	enemy->SetZone(this);
	map->AddGroundObject(enemy);
	_enemies.push_back(enemy);

	// Create any additional copies of the enemy and add them as well
	for (uint8 i = 1; i < count; i++) {
		EnemySprite* copy = new EnemySprite(*enemy);
		copy->SetObjectID(map->GetObjectSupervisor()->GenerateObjectID());
		// Add a 10% random margin of error to make enemies look less synchronized
		copy->SetTimeToChange(static_cast<uint32>(copy->GetTimeToChange() * (1 + RandomFloat() * 10)));
		copy->Reset();
		map->AddGroundObject(copy);
		_enemies.push_back(copy);
	}
}
IndicatorElement::IndicatorElement(BattleActor* actor, INDICATOR_TYPE indicator_type) :
	_actor(actor),
	_timer(INDICATOR_TIME),
	_alpha_color(1.0f, 1.0f, 1.0f, 0.0f),
	_y_force(INITIAL_FORCE),
	_x_position(0.0f),
	_y_position(0.0f),
	_x_absolute_position(0.0f),
	_y_absolute_position(0.0f),
	_indicator_type(indicator_type)
{
	if (actor == NULL)
		IF_PRINT_WARNING(BATTLE_DEBUG) << "constructor received NULL actor argument" << std::endl;

    _x_force = RandomFloat(-20.0f, 20.0f);

    // Setup a default aboslute position
    if (_actor) {
        _x_absolute_position = _actor->GetXLocation();
        _y_absolute_position = _actor->GetYLocation();
    }
}
Example #23
0
bool TexSheet::CopyScreenRect(int32 x, int32 y, const ScreenRect &screen_rect)
{
    TextureManager->_BindTexture(tex_id);

    glCopyTexSubImage2D(
        GL_TEXTURE_2D, // target
        0, // level
        x, // x offset within tex sheet
        y, // y offset within tex sheet
        screen_rect.left, // left starting pixel of the screen to copy
        screen_rect.top, // top starting pixel of the screen to copy
        screen_rect.width, // width in pixels of image
        screen_rect.height // height in pixels of image
    );

    if(VideoManager->CheckGLError() == true) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "an OpenGL error occured: " << VideoManager->CreateGLErrorString() << std::endl;
        return false;
    }

    return true;
}
void IndicatorSupervisor::AddDamageIndicator(uint32 amount) {
	const Color low_red(1.0f, 0.75f, 0.0f, 1.0f);
	const Color mid_red(1.0f, 0.50f, 0.0f, 1.0f);
	const Color high_red(1.0f, 0.25f, 0.0f, 1.0f);
	const Color full_red(Color::red);

	if (amount == 0) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "function was given a zero value argument" << std::endl;
		return;
	}

	std::string text = NumberToString(amount);
	TextStyle style;

	float damage_percent = static_cast<float>(amount) / static_cast<float>(_actor->GetMaxHitPoints());
	if (damage_percent < 0.10f) {
		style.font = "text24";
		style.color = low_red;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}
	else if (damage_percent < 0.20f) {
		style.font = "text24";
		style.color = mid_red;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}
	else if (damage_percent < 0.30f) {
		style.font = "text24";
		style.color = high_red;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}
	else { // (damage_percent >= 0.30f)
		style.font = "text24";
		style.color = full_red;
		style.shadow_style = VIDEO_TEXT_SHADOW_BLACK;
	}

	_wait_queue.push_back(new IndicatorText(_actor, text, style, DAMAGE_INDICATOR));
}
void DialogueSupervisor::_BeginLine() {
	_state = DIALOGUE_STATE_LINE;
	_current_options = _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));
	if (_current_options != NULL) {
		for (uint32 i = 0; i < _current_options->GetNumberOptions(); i++) {
			_dialogue_window.GetDisplayOptionBox().AddOption(_current_options->GetOptionText(i));
		}

		_dialogue_window.GetDisplayOptionBox().SetSelection(0);
	}

	BattleSpeaker* line_speaker = GetSpeaker(_current_dialogue->GetLineSpeaker(_line_counter));
	if (line_speaker == NULL) {
		IF_PRINT_WARNING(BATTLE_DEBUG) << "dialogue #" << _current_dialogue->GetDialogueID()
			<< " referenced a speaker that did not exist with id: " << _current_dialogue->GetLineSpeaker(_line_counter) << std::endl;
		_dialogue_window.GetNameText().SetText("");
		_dialogue_window.SetPortraitImage(NULL);
	}
	else {
		_dialogue_window.GetNameText().SetText(line_speaker->name);
		_dialogue_window.SetPortraitImage(&(line_speaker->portrait));
	}
}
Example #26
0
void EffectSupervisor::EnableLightning(int16 id, bool loop)
{
    if(id > -1 && id < (int16)_lightning_inner_info._lightning_data.size()) {
        _info.lightning.active_id = id;
        _info.lightning.active = true;
        _info.lightning.loop = loop;
        _lightning_inner_info._lightning_current_time = 0;

        // Load the current sound events
        _lightning_inner_info._current_lightning_sound_events.clear();
        std::vector<LightningVideoManagerInfo::lightning_sound_event>::iterator it, it_end;
        for(it = _lightning_inner_info._lightning_sound_events.at(id).begin(),
                it_end = _lightning_inner_info._lightning_sound_events.at(id).end(); it != it_end; ++it) {
            _lightning_inner_info._current_lightning_sound_events.push_back(*it);
            // Preload the files for efficiency
            vt_audio::AudioManager->LoadSound(it->sound_filename);
        }
    } else {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "Invalid lightning effect requested: "
                                      << id << ", the effect won't be displayed." << std::endl;
        DisableLightning();
    }
}
bool BattleDialogue::Validate() {
	if (CommonDialogue::Validate() == false) {
		// The BattleDialogue::Validate() call will print the appropriate warning if debugging is enabled (common code debugging that is)
		return false;
	}

	// Construct containers that hold all unique sprite and event ids for this dialogue
	std::set<uint32> speaker_ids;
	for (uint32 i = 0; i < _line_count; i++) {
		speaker_ids.insert(_speakers[i]);
	}

	// Check that all sprites and events referrenced by the dialogue exist
	for (std::set<uint32>::iterator i = speaker_ids.begin(); i != speaker_ids.end(); i++) {
		if (BattleMode::CurrentInstance()->GetDialogueSupervisor()->GetSpeaker(*i) == NULL) {
			IF_PRINT_WARNING(BATTLE_DEBUG) << "Validation failed for dialogue #" << _dialogue_id
				<< ": dialogue referenced invalid speaker with id: " << *i << std::endl;
			return false;
		}
	}

	return true;
}
Example #28
0
bool TexSheet::CopyRect(int32 x, int32 y, ImageMemory &data)
{
    TextureManager->_BindTexture(tex_id);

    glTexSubImage2D(
        GL_TEXTURE_2D, // target
        0, // level
        x, // x offset within tex sheet
        y, // y offset within tex sheet
        data.width, // width in pixels of image
        data.height, // height in pixels of image
        (data.rgb_format ? GL_RGB : GL_RGBA), // format
        GL_UNSIGNED_BYTE, // type
        data.pixels // pixels of the sub image
    );

    if(VideoManager->CheckGLError() == true) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "an OpenGL error occured: " << VideoManager->CreateGLErrorString() << std::endl;
        return false;
    }

    return true;
}
Example #29
0
bool ReadScriptDescriptor::OpenFile(const string& filename, bool force_reload) {
	// Check for file extensions
	string file_name = filename;
	if (DoesFileExist(file_name + ".lua")) {
		file_name = filename + ".lua";
	}
	if (DoesFileExist(file_name + ".hoa")) {
		if (!(DoesFileExist(file_name + ".lua") && SCRIPT_DEBUG))
			file_name = filename + ".hoa";
	}

	if (ScriptManager->IsFileOpen(file_name) == true) {
		IF_PRINT_WARNING(SCRIPT_DEBUG) << "attempted to open file that is already opened: " << file_name << endl;
		return false;
	}

	// Check if this file was opened previously.
	if ((force_reload == true) || (_lstack = ScriptManager->_CheckForPreviousLuaState(file_name)) == NULL) {
		// Increases the global stack size by 1 element. That is needed because the new thread will be pushed in the
		// stack and we have to be sure there is enough space there.
		lua_checkstack(ScriptManager->GetGlobalState(), 1);
		_lstack = lua_newthread(ScriptManager->GetGlobalState());

		// Attempt to load and execute the Lua file
		if (luaL_loadfile(_lstack, file_name.c_str()) != 0 || lua_pcall(_lstack, 0, 0, 0)) {
			PRINT_ERROR << "could not open script file: " << file_name << ", error message:" << endl;
			cerr << lua_tostring(_lstack, private_script::STACK_TOP) << endl;
			_access_mode = SCRIPT_CLOSED;
			return false;
		}
	}

	_filename = file_name;
	_access_mode = SCRIPT_READ;
	ScriptManager->_AddOpenFile(this);
	return true;
} // bool ReadScriptDescriptor::OpenFile(string file_name, bool force_reload)
Example #30
0
bool FixedTexSheet::InsertTexture(BaseTexture *img)
{
    if(img == nullptr) {
        IF_PRINT_WARNING(VIDEO_DEBUG) << "nullptr pointer was given as function argument" << std::endl;
        return false;
    }

    // Retrieve the node from the head of the list to use for this texture
    FixedTexNode *node = _RemoveOpenNode();
    if(node == nullptr)  // This condition indicates that there are no remaining free nodes on the open list
        return false;

    // Check if there's already an image allocated at this block (an image was freed earlier, but not removed)
    // If so, we must now remove it from memory
    if(node->image != nullptr) {
        // TODO: TextureManager needs to have the image element removed from its map containers
        node->image = nullptr;
    }

    // Calculate the texture's pixel coordinates in the sheet given this node's block index
    img->x = _texture_width * (node->block_index % _block_width);
    img->y = _texture_height * (node->block_index / _block_width);

    // Calculate the u,v coordinates
    float sheet_width = static_cast<float>(width);
    float sheet_height = static_cast<float>(height);

    img->u1 = static_cast<float>(img->x + 0.5f) / sheet_width;
    img->u2 = static_cast<float>(img->x + img->width - 0.5f) / sheet_width;
    img->v1 = static_cast<float>(img->y + 0.5f) / sheet_height;
    img->v2 = static_cast<float>(img->y + img->height - 0.5f) / sheet_height;

    img->texture_sheet = this;
    node->image = img;
    return true;
} // bool FixedTexSheet::InsertTexture(BaseTexture* img)