1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-22 21:03:19 +02:00

fix unlimited medikit, show health bar in the inventory menu

This commit is contained in:
XProger
2018-11-24 08:14:40 +03:00
parent ce4418941d
commit 87126db2ca
3 changed files with 41 additions and 14 deletions

View File

@@ -39,7 +39,7 @@ struct Camera : ICamera {
void reset() { void reset() {
Sound::listener[cameraIndex].matrix.identity(); Sound::listener[cameraIndex].matrix.identity();
Sound::listener[cameraIndex].matrix.translate(vec3(0x7FFFFFFF)); Sound::listener[cameraIndex].matrix.translate(vec3(float(0x7FFFFFFF)));
lookAngle = vec3(0.0f); lookAngle = vec3(0.0f);

View File

@@ -646,6 +646,8 @@ struct Inventory {
} }
#ifdef _DEBUG #ifdef _DEBUG
addWeapons(); addWeapons();
add(TR::Entity::MEDIKIT_BIG);
add(TR::Entity::MEDIKIT_SMALL, 2);
add(TR::Entity::INV_KEY_ITEM_1, 3); add(TR::Entity::INV_KEY_ITEM_1, 3);
add(TR::Entity::INV_KEY_ITEM_2, 3); add(TR::Entity::INV_KEY_ITEM_2, 3);
add(TR::Entity::INV_KEY_ITEM_3, 3); add(TR::Entity::INV_KEY_ITEM_3, 3);
@@ -1475,6 +1477,23 @@ struct Inventory {
renderItemCount(item, vec2(UI::width / 2 - 160 - eye, 480 - 96), 320); renderItemCount(item, vec2(UI::width / 2 - 160 - eye, 480 - 96), 320);
// show health bar in inventory when selector is over medikit
if (item->type == TR::Entity::INV_MEDIKIT_BIG || item->type == TR::Entity::INV_MEDIKIT_SMALL) {
Character *lara = (Character*)game->getLara(playerIndex);
if (lara) {
float health = lara->health / 1000.0f; // LARA_MAX_HEALTH
vec2 size = vec2(180, 10);
vec2 pos;
if (Core::settings.detail.stereo == Core::Settings::STEREO_VR)
pos = vec2((UI::width - size.x) * 0.5f - eye * 4.0f, 96);
else
pos = vec2(UI::width - 32 - size.x - eye, 32);
UI::renderBar(UI::BAR_HEALTH, pos, size, health);
}
}
if (phaseChoose == 1.0f) { if (phaseChoose == 1.0f) {
switch (item->type) { switch (item->type) {
case TR::Entity::INV_PASSPORT : case TR::Entity::INV_PASSPORT :

View File

@@ -299,7 +299,7 @@ struct Lara : Character {
} arms[2]; } arms[2];
TR::Entity::Type itemHolster; TR::Entity::Type itemHolster;
TR::Entity::Type usedKey; TR::Entity::Type usedItem;
int pickupListCount; int pickupListCount;
Controller *pickupList[32]; Controller *pickupList[32];
KeyHole *keyHole; KeyHole *keyHole;
@@ -1681,10 +1681,7 @@ struct Lara : Character {
case TR::Entity::INV_MEDIKIT_SMALL : case TR::Entity::INV_MEDIKIT_SMALL :
case TR::Entity::INV_MEDIKIT_BIG : case TR::Entity::INV_MEDIKIT_BIG :
saveStats.mediUsed += (item == TR::Entity::INV_MEDIKIT_SMALL) ? 1 : 2; saveStats.mediUsed += (item == TR::Entity::INV_MEDIKIT_SMALL) ? 1 : 2;
damageTime = LARA_DAMAGE_TIME; usedItem = item;
health = min(LARA_MAX_HEALTH, health + (item == TR::Entity::INV_MEDIKIT_SMALL ? LARA_MAX_HEALTH / 2 : LARA_MAX_HEALTH));
game->playSound(TR::SND_HEALTH, pos, Sound::PAN);
//TODO: remove medikit item
break; break;
case TR::Entity::INV_PUZZLE_1 : case TR::Entity::INV_PUZZLE_1 :
case TR::Entity::INV_PUZZLE_2 : case TR::Entity::INV_PUZZLE_2 :
@@ -1694,9 +1691,9 @@ struct Lara : Character {
case TR::Entity::INV_KEY_ITEM_2 : case TR::Entity::INV_KEY_ITEM_2 :
case TR::Entity::INV_KEY_ITEM_3 : case TR::Entity::INV_KEY_ITEM_3 :
case TR::Entity::INV_KEY_ITEM_4 : case TR::Entity::INV_KEY_ITEM_4 :
if (usedKey == item) if (usedItem == item)
return false; return false;
usedKey = item; usedItem = item;
break; break;
case TR::Entity::INV_LEADBAR : case TR::Entity::INV_LEADBAR :
for (int i = 0; i < level->entitiesCount; i++) { for (int i = 0; i < level->entitiesCount; i++) {
@@ -1978,24 +1975,24 @@ struct Lara : Character {
return; return;
limit = actionState == STATE_USE_PUZZLE ? &TR::Limits::PUZZLE_HOLE : &TR::Limits::KEY_HOLE; limit = actionState == STATE_USE_PUZZLE ? &TR::Limits::PUZZLE_HOLE : &TR::Limits::KEY_HOLE;
if (!checkInteraction(controller, limit, isPressed(ACTION) || usedKey != TR::Entity::NONE)) if (!checkInteraction(controller, limit, isPressed(ACTION) || usedItem != TR::Entity::NONE))
return; return;
if (usedKey == TR::Entity::NONE) { if (usedItem == TR::Entity::NONE) {
if (isPressed(ACTION) && !game->invChooseKey(camera->cameraIndex, entity.type)) if (isPressed(ACTION) && !game->invChooseKey(camera->cameraIndex, entity.type))
game->playSound(TR::SND_NO, pos, Sound::PAN); // no compatible items in inventory game->playSound(TR::SND_NO, pos, Sound::PAN); // no compatible items in inventory
return; return;
} }
if (TR::Entity::convToInv(TR::Entity::getItemForHole(entity.type)) != usedKey) { // check compatibility if user select other if (TR::Entity::convToInv(TR::Entity::getItemForHole(entity.type)) != usedItem) { // check compatibility if user select other
game->playSound(TR::SND_NO, pos, Sound::PAN); // uncompatible item game->playSound(TR::SND_NO, pos, Sound::PAN); // uncompatible item
return; return;
} }
keyHole = controller; keyHole = controller;
if (game->invUse(camera->cameraIndex, usedKey)) { if (game->invUse(camera->cameraIndex, usedItem)) {
keyItem = game->addEntity(usedKey, getRoomIndex(), pos, 0); keyItem = game->addEntity(usedItem, getRoomIndex(), pos, 0);
keyItem->lockMatrix = true; keyItem->lockMatrix = true;
keyItem->pos = keyHole->pos + vec3(0, -590, 484).rotateY(-keyHole->angle.y); keyItem->pos = keyHole->pos + vec3(0, -590, 484).rotateY(-keyHole->angle.y);
keyItem->angle.x = PI * 0.5f; keyItem->angle.x = PI * 0.5f;
@@ -3127,6 +3124,17 @@ struct Lara : Character {
if (fixRoomIndex() && braid) if (fixRoomIndex() && braid)
braid->update(); braid->update();
} else { } else {
switch (usedItem) {
case TR::Entity::INV_MEDIKIT_SMALL :
case TR::Entity::INV_MEDIKIT_BIG :
damageTime = LARA_DAMAGE_TIME;
health = min(LARA_MAX_HEALTH, health + (usedItem == TR::Entity::INV_MEDIKIT_SMALL ? LARA_MAX_HEALTH / 2 : LARA_MAX_HEALTH));
game->playSound(TR::SND_HEALTH, pos, Sound::PAN);
inventory->remove(usedItem);
usedItem = TR::Entity::NONE;
default : ;
}
Character::update(); Character::update();
if (braid) if (braid)
braid->update(); braid->update();
@@ -3157,7 +3165,7 @@ struct Lara : Character {
if (oxygen < LARA_MAX_OXYGEN && health > 0.0f) if (oxygen < LARA_MAX_OXYGEN && health > 0.0f)
oxygen = min(LARA_MAX_OXYGEN, oxygen + Core::deltaTime * 10.0f); oxygen = min(LARA_MAX_OXYGEN, oxygen + Core::deltaTime * 10.0f);
usedKey = TR::Entity::NONE; usedItem = TR::Entity::NONE;
if (camera->mode != Camera::MODE_CUTSCENE && camera->mode != Camera::MODE_STATIC) { if (camera->mode != Camera::MODE_CUTSCENE && camera->mode != Camera::MODE_STATIC) {
camera->mode = (emptyHands() || health <= 0.0f) ? Camera::MODE_FOLLOW : Camera::MODE_COMBAT; camera->mode = (emptyHands() || health <= 0.0f) ? Camera::MODE_FOLLOW : Camera::MODE_COMBAT;