1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-18 19:01:45 +02:00

#11 ammo & weapon pickup

This commit is contained in:
XProger
2017-07-01 19:21:00 +03:00
parent 8776e04935
commit 0ea27ca3d8
2 changed files with 72 additions and 26 deletions

View File

@@ -5,7 +5,7 @@
#include "controller.h" #include "controller.h"
#include "ui.h" #include "ui.h"
#define INVENTORY_MAX_ITEMS 64 #define INVENTORY_MAX_ITEMS 32
#define INVENTORY_MAX_RADIUS 688.0f #define INVENTORY_MAX_RADIUS 688.0f
#define INVENTORY_BG_SIZE 512 #define INVENTORY_BG_SIZE 512
#define INVENTORY_HEIGHT 2048.0f #define INVENTORY_HEIGHT 2048.0f
@@ -138,17 +138,17 @@ struct Inventory {
add(TR::Entity::INV_DETAIL); add(TR::Entity::INV_DETAIL);
add(TR::Entity::INV_SOUND); add(TR::Entity::INV_SOUND);
add(TR::Entity::INV_CONTROLS); add(TR::Entity::INV_CONTROLS);
/*
add(TR::Entity::INV_COMPASS); add(TR::Entity::INV_COMPASS);
if (level->extra.inv.map != -1) if (level->extra.inv.map != -1)
add(TR::Entity::INV_MAP); add(TR::Entity::INV_MAP);
if (level->extra.inv.gamma != -1) if (level->extra.inv.gamma != -1)
add(TR::Entity::INV_GAMMA); add(TR::Entity::INV_GAMMA);
*/
add(TR::Entity::INV_PISTOLS, UNLIMITED_AMMO); add(TR::Entity::INV_PISTOLS, UNLIMITED_AMMO);
add(TR::Entity::INV_SHOTGUN, 999); add(TR::Entity::INV_SHOTGUN, 10);
add(TR::Entity::INV_MAGNUMS, 999); add(TR::Entity::INV_MAGNUMS, 10);
add(TR::Entity::INV_UZIS, 10); add(TR::Entity::INV_UZIS, 50);
// add(TR::Entity::INV_MEDIKIT_SMALL, 999); // add(TR::Entity::INV_MEDIKIT_SMALL, 999);
// add(TR::Entity::INV_MEDIKIT_BIG, 999); // add(TR::Entity::INV_MEDIKIT_BIG, 999);
@@ -214,7 +214,38 @@ struct Inventory {
return -1; return -1;
} }
void addAmmo(TR::Entity::Type &type, int &count, int clip, TR::Entity::Type wpnType, TR::Entity::Type ammoType) {
count *= clip;
if (type == wpnType) {
int index = contains(ammoType);
if (index > -1) {
count += items[index]->count;
remove(index);
}
} else {
if (contains(wpnType) > -1)
type = wpnType;
}
}
void add(TR::Entity::Type type, int count = 1) { void add(TR::Entity::Type type, int count = 1) {
type = convToInv(type);
switch (type) {
case TR::Entity::INV_SHOTGUN :
case TR::Entity::INV_AMMO_SHOTGUN :
addAmmo(type, count, 12, TR::Entity::INV_SHOTGUN, TR::Entity::INV_AMMO_SHOTGUN);
break;
case TR::Entity::INV_MAGNUMS :
case TR::Entity::INV_AMMO_MAGNUMS :
addAmmo(type, count, 50, TR::Entity::INV_MAGNUMS, TR::Entity::INV_AMMO_MAGNUMS);
break;
case TR::Entity::INV_UZIS :
case TR::Entity::INV_AMMO_UZIS :
addAmmo(type, count, 100, TR::Entity::INV_UZIS, TR::Entity::INV_AMMO_UZIS);
break;
}
int i = contains(type); int i = contains(type);
if (i > -1) { if (i > -1) {
items[i]->count += count; items[i]->count += count;
@@ -223,8 +254,6 @@ struct Inventory {
ASSERT(itemsCount < INVENTORY_MAX_ITEMS); ASSERT(itemsCount < INVENTORY_MAX_ITEMS);
type = convToInv(type);
int pos = 0; int pos = 0;
for (int pos = 0; pos < itemsCount; pos++) for (int pos = 0; pos < itemsCount; pos++)
if (items[pos]->type > type) if (items[pos]->type > type)
@@ -246,17 +275,19 @@ struct Inventory {
} }
void remove(TR::Entity::Type type, int count = 1) { void remove(TR::Entity::Type type, int count = 1) {
int idx = contains(type); int index = contains(type);
if (idx > -1) { if (index == -1) return;
items[idx]->count -= count;
if (!items[idx]->count) { items[index]->count -= count;
delete items[idx]; if (items[index]->count <= 0)
for (int i = idx; i < itemsCount - 1; i++) { remove(index);
items[i] = items[i + 1]; }
}
itemsCount--; void remove(int index) {
} delete items[index];
} for (int i = index; i < itemsCount - 1; i++)
items[i] = items[i + 1];
itemsCount--;
} }
bool use(TR::Entity::Type item, TR::Entity::Type slot) { bool use(TR::Entity::Type item, TR::Entity::Type slot) {

View File

@@ -26,13 +26,22 @@ namespace UI {
return c > 10 ? (c > 15 ? char_map[c - 32] : c + 91) : c + 81; return c > 10 ? (c > 15 ? char_map[c - 32] : c + 91) : c + 81;
} }
int getTextWidth(const char *text) { vec2 getTextSize(const char *text) {
int width = 0; int x = 0, w = 0, h = 16;
while (char c = *text++) while (char c = *text++) {
width += (c == ' ' || c == '_') ? 6 : (char_width[charRemap(c)] + 1); if (c == ' ' || c == '_') {
x += 6;
} else if (c == '@') {
w = max(w, x);
h += 16;
x = 0;
} else
x += char_width[charRemap(c)] + 1;
}
w = max(w, x);
return width - 1; return vec2(float(w), float(h));
} }
#define MAX_CHARS DYN_MESH_QUADS #define MAX_CHARS DYN_MESH_QUADS
@@ -87,10 +96,10 @@ namespace UI {
int y = int(pos.y); int y = int(pos.y);
if (align == aCenter) if (align == aCenter)
x += (int(width) - getTextWidth(text)) / 2; x += int((width - getTextSize(text).x) / 2);
if (align == aRight) if (align == aRight)
x += int(width) - getTextWidth(text); x += int(width - getTextSize(text).x);
while (char c = *text++) { while (char c = *text++) {
if (c == ' ' || c == '_') { if (c == ' ' || c == '_') {
@@ -98,6 +107,12 @@ namespace UI {
continue; continue;
} }
if (c == '@') {
x = int(pos.x);
y += 16;
continue;
}
int frame = charRemap(c); int frame = charRemap(c);
if (buffer.iCount == MAX_CHARS * 6) if (buffer.iCount == MAX_CHARS * 6)