Skip to content

Commit

Permalink
Merge pull request #57 from OzoneH3/master
Browse files Browse the repository at this point in the history
Added: List items on the ground around player
  • Loading branch information
TheDarklingWolf committed Feb 12, 2013
2 parents a907cc6 + dec7b59 commit 3d9c70e
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 22 deletions.
6 changes: 5 additions & 1 deletion action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ std::string action_ident(action_id act)
return "look";
case ACTION_PEEK:
return "peek";
case ACTION_LIST_ITEMS:
return "listitems";
case ACTION_INVENTORY:
return "inventory";
case ACTION_COMPARE:
Expand Down Expand Up @@ -303,6 +305,8 @@ std::string action_name(action_id act)
return "Look Around";
case ACTION_PEEK:
return "Peek Around Corners";
case ACTION_LIST_ITEMS:
return "List all items around the player";
case ACTION_INVENTORY:
return "Open Inventory";
case ACTION_COMPARE:
Expand Down Expand Up @@ -350,7 +354,7 @@ std::string action_name(action_id act)
case ACTION_CONSTRUCT:
return "Construct Terrain";
case ACTION_DISASSEMBLE:
return "Disassemble items";
return "Disassemble items";
case ACTION_SLEEP:
return "Sleep";
case ACTION_TOGGLE_SAFEMODE:
Expand Down
1 change: 1 addition & 0 deletions action.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ACTION_BUTCHER,
ACTION_CHAT,
ACTION_LOOK,
ACTION_PEEK,
ACTION_LIST_ITEMS,
// Inventory Interaction (including quasi-inventories like bionics)
ACTION_INVENTORY,
ACTION_COMPARE,
Expand Down
140 changes: 124 additions & 16 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
#include "mapbuffer.h"
#include "debug.h"
#include "bodypart.h"
#include "map.h"

#include <map>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
Expand Down Expand Up @@ -695,7 +697,7 @@ bool game::do_turn()
}

if (turn % 10 == 0) update_bodytemp();

rustCheck();
if (turn % 10 == 0)
u.update_morale();
Expand All @@ -706,16 +708,16 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
{
// NOTE : Bodytemp is measured on a scale of 0u to 1000u, where 1u = 0.02C and 500u is 37C
// Converts temperature to Celsius/10!(Wito plans on using degrees Kelvin later)
int Ctemperature = 10*(temperature - 32) * 5/9;
int Ctemperature = 10*(temperature - 32) * 5/9;
// Temperature thresholds
const int freezing = 50, very_cold = 200, cold = 350, hot = 650, very_hot = 800, scorching = 950;
const int freezing = 50, very_cold = 200, cold = 350, hot = 650, very_hot = 800, scorching = 950;
// Temperature norms
const int body_norm = 500, ambient_norm = 220;
// Creative thinking for clean morale penalties
int morale_cold = 0, morale_hot = 0;
int morale_cold = 0, morale_hot = 0;
// This adjusts the temperature scale to match the bodytemp scale
int adjusted_temp = 2*(Ctemperature - ambient_norm);
// Fetch the morale value of wetness for bodywetness
int adjusted_temp = 2*(Ctemperature - ambient_norm);
// Fetch the morale value of wetness for bodywetness
int bodywetness = 0;
for (int i = 0; bodywetness == 0 && i < u.morale.size(); i++)
if( u.morale[i].type == MORALE_WET ) {
Expand All @@ -725,23 +727,23 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
// Current temperature and converging temperature calculations
for (int i = 0 ; i < num_bp ; i++){
// Represents the fact that the body generates heat when it is cold. TODO : should this increase hunger?
float homeostasis_adjustement = (u.temp_cur[i] > body_norm ? 1.0 : 3.0);
float homeostasis_adjustement = (u.temp_cur[i] > body_norm ? 1.0 : 3.0);
int clothing_warmth_adjustement = homeostasis_adjustement * (float)u.warmth(body_part(i)) / (1.0 + (float)bodywetness / 50.0);
// Disease name shorthand
int blister_pen = dis_type(DI_BLISTERS) + 1 + i, hot_pen = dis_type(DI_HOT) + 1 + i;
int cold_pen = dis_type(DI_COLD)+ 1 + i, frost_pen = dis_type(DI_FROSTBITE) + 1 + i;
int cold_pen = dis_type(DI_COLD)+ 1 + i, frost_pen = dis_type(DI_FROSTBITE) + 1 + i;
signed int temp_conv = body_norm + adjusted_temp + clothing_warmth_adjustement; // Convergeant temperature is affected by ambient temperature, clothing warmth, and body wetness. 20C is normal
// Fatigue also affects convergeant temperature
if (!u.has_disease(DI_SLEEP)) temp_conv -= u.fatigue/6;
else {
if (!u.has_disease(DI_SLEEP)) temp_conv -= u.fatigue/6;
else {
int vpart = -1;
vehicle *veh = m.veh_at (u.posx, u.posy, vpart);
vehicle *veh = m.veh_at (u.posx, u.posy, vpart);
if (m.ter(u.posx, u.posy) == t_bed) temp_conv += 100;
else if (m.ter(u.posx, u.posy) == t_makeshift_bed) temp_conv += 50;
else if (m.tr_at(u.posx, u.posy) == tr_cot) temp_conv -= 50;
else if (m.tr_at(u.posx, u.posy) == tr_rollmat) temp_conv -= 100;
else if (veh && veh->part_with_feature (vpart, vpf_seat) >= 0) temp_conv += 30;
else temp_conv -= 200;
else temp_conv -= 200;
}
// Fire : generates body heat, helps fight frostbite TODO : add lava checks. TODO : cleanup like I did with temp_conv calculation
int blister_count = 0; // If the counter is high, your skin starts to burn
Expand All @@ -752,7 +754,7 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
int fire_dist = std::max(1, std::max(j, k));;
int fire_density = m.field_at(u.posx + j, u.posy + k).density;
if (u.frostbite_timer[i] > 0) u.frostbite_timer[i] -= fire_density - fire_dist/2;
temp_conv += 300*fire_density/(fire_dist*fire_dist); // How do I square things
temp_conv += 300*fire_density/(fire_dist*fire_dist); // How do I square things
blister_count += fire_density/(fire_dist*fire_dist);
}
}
Expand Down Expand Up @@ -780,8 +782,8 @@ void game::update_bodytemp() // TODO bionics, diseases and humidity (not in yet)
else if (temp_before > cold && temp_after < cold) add_msg("You feel your %s getting cold.", body_part_name(body_part(i), -1).c_str());
else if (temp_before < scorching && temp_after > scorching) add_msg("You feel your %s getting red hot from the heat!", body_part_name(body_part(i), -1).c_str());
else if (temp_before < very_hot && temp_after > very_hot) add_msg("You feel your %s getting very hot.", body_part_name(body_part(i), -1).c_str());
else if (temp_before < hot && temp_after > hot) add_msg("You feel your %s getting hot.", body_part_name(body_part(i), -1).c_str());
}
else if (temp_before < hot && temp_after > hot) add_msg("You feel your %s getting hot.", body_part_name(body_part(i), -1).c_str());
}
// Morale penalties TODO only updates every 10 ticks
if (morale_cold > 0) u.add_morale(MORALE_COLD, -1*morale_cold, -10*morale_cold);
if (morale_hot > 0) u.add_morale(MORALE_HOT, -1*morale_hot, -10*morale_hot);
Expand Down Expand Up @@ -1483,6 +1485,10 @@ input_ret game::get_input(int timeout_ms)
peek();
break;

case ACTION_LIST_ITEMS:
list_items();
break;

case ACTION_INVENTORY: {
bool has = false;
do {
Expand Down Expand Up @@ -5172,6 +5178,108 @@ point game::look_around()
return point(-1, -1);
}

void game::list_items()
{
WINDOW* w_items = newwin(15, 55, 0, 25);
WINDOW* w_item_info = newwin(10, 55, 15, 25);

wborder(w_items, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );

std::vector <item> here;
std::vector <item> grounditems;
std::vector <int> itemposx;
std::vector <int> itemposy;

//Area to search +- of players position
int iSearchX = 12;
int iSearchY = 12;

int iTile;
for (int iCol = (iSearchX * -1); iCol <= iSearchX; iCol++) {
for (int iRow = (iSearchY * -1); iRow <= iSearchY; iRow++) {
if (u_see(u.posx + iCol, u.posy + iRow, iTile)) {
here.clear();
here = m.i_at(u.posx + iCol, u.posy + iRow);
for (int i = 0; i < here.size(); i++) {
grounditems.push_back(here[i]);
itemposx.push_back(iCol);
itemposy.push_back(iRow);
}
}
}
}

int iActive = 0;
int iMaxRows = 13;
int iStartPos = 0;
int iItemNum = grounditems.size();
long ch = '.';

do {
if (iItemNum > 0) {
switch(ch) {
case KEY_UP:
iActive--;
if (iActive < 0)
iActive = 0;
break;
case KEY_DOWN:
iActive++;
if (iActive >= iItemNum)
iActive = iItemNum-1;
break;
}

if (iItemNum > iMaxRows) {
iStartPos = iActive - (iMaxRows - 1) / 2;

if (iStartPos < 0)
iStartPos = 0;
else if (iStartPos + iMaxRows > iItemNum)
iStartPos = iItemNum - iMaxRows;
}

for (int i = 0; i < iMaxRows; i++)
mvwprintz(w_items, 1 + i , 1, c_black, "%s", " ");

for (int i = iStartPos; i < iStartPos + ((iMaxRows > iItemNum) ? iItemNum : iMaxRows); i++)
mvwprintz(w_items, 1 + i - iStartPos, 2, ((i == iActive) ? c_ltgreen : c_white), "%s", grounditems[i].tname(this).c_str());

wclear(w_item_info);
mvwprintz(w_item_info, 0, 2, c_white, "%s", grounditems[iActive].info().c_str());
wborder(w_item_info, LINE_XOXO, LINE_XOXO, LINE_OXOX, LINE_OXOX,
LINE_OXXO, LINE_OOXX, LINE_XXOO, LINE_XOOX );

draw_ter();
std::vector<point> trajectory = line_to(u.posx, u.posy, u.posx + itemposx[iActive], u.posy + itemposy[iActive], 0);
int junk;
for (int i = 0; i < trajectory.size(); i++) {
if (i > 0)
m.drawsq(w_terrain, u, trajectory[i-1].x, trajectory[i-1].y, true, true);

if (u_see(trajectory[i].x, trajectory[i].y, junk)) {
char bullet = '*';
mvwputch(w_terrain, trajectory[i].y + SEEY - u.posy,
trajectory[i].x + SEEX - u.posx, c_red, bullet);
}
}

wrefresh(w_terrain);
} else {
mvwprintz(w_items, 8, 6, c_ltred, "%s", "No Items around!");
}

wrefresh(w_items);
wrefresh(w_item_info);
ch = getch();
} while (ch != '\n' && ch != KEY_ESCAPE && ch != ' ');
werase(w_items);
delwin(w_items);
erase();
refresh_all();
}

// Pick up items at (posx, posy).
void game::pickup(int posx, int posy, int min)
{
Expand Down
11 changes: 6 additions & 5 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum quit_status {
QUIT_SUICIDE, // Quit with 'Q'
QUIT_SAVED, // Saved and quit
QUIT_DIED, // Actual death
QUIT_DELETE_WORLD // Quit and delete world
QUIT_DELETE_WORLD // Quit and delete world
};

struct monster_and_count
Expand Down Expand Up @@ -188,8 +188,9 @@ class game

void peek();
point look_around();// Look at nearby terrain ';'
void list_items(); //List all items around the player
char inv(std::string title = "Inventory:");
char inv_type(std::string title = "Inventory:", int inv_item_type = 0);
char inv_type(std::string title = "Inventory:", int inv_item_type = 0);
std::vector<item> multidrop();
faction* list_factions(std::string title = "FACTIONS:");
point find_item(item *it);
Expand Down Expand Up @@ -231,7 +232,7 @@ class game
ter_id dragging;
std::vector<item> items_dragged;
int weight_dragged; // Computed once, when you start dragging
bool debugmon;
bool debugmon;
bool no_npc;
// Display data... TODO: Make this more portable?
WINDOW *w_terrain;
Expand Down Expand Up @@ -290,8 +291,8 @@ class game
void pick_recipes(std::vector<recipe*> &current,
std::vector<bool> &available, craft_cat tab);// crafting.cpp
void disassemble(); // See crafting.cpp
void disassemble_item(recipe *dis); // See crafting.cpp
void complete_disassemble(); // See crafting.cpp
void disassemble_item(recipe *dis); // See crafting.cpp
void complete_disassemble(); // See crafting.cpp
void construction_menu(); // See construction.cpp
bool player_can_build(player &p, inventory inv, constructable* con,
int level = -1, bool cont = false,
Expand Down
1 change: 1 addition & 0 deletions keypress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ butcher B\n\
chat C\n\
look ; x\n\
peek X\n\
listitems V\n\
\n\
# INVENTORY & QUASI-INVENTORY INTERACTION\n\
inventory i\n\
Expand Down

0 comments on commit 3d9c70e

Please sign in to comment.