Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some updates, see description #88

Merged
merged 7 commits into from
Feb 22, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ bool construct::able_wall_wood(game *g, point p)

bool construct::able_indoors(game *g, point p)
{
return (g->m.ter(p.x, p.y) == t_floor);
return (g->m.is_indoor(p.x, p.y));
}

bool construct::able_dig(game *g, point p)
Expand Down Expand Up @@ -746,7 +746,7 @@ void construct::done_furniture(game *g, point p)
return;
x += p.x;
y += p.y;
if(g->m.ter(x, y) != t_floor || !g->is_empty(x, y)) {
if(!g->m.is_indoor(x, y) || !g->is_empty(x, y)) {
mvprintz(0, 0, c_red, "Can't move furniture there! Choose a direction with open floor.");
continue;
}
Expand All @@ -755,6 +755,13 @@ void construct::done_furniture(game *g, point p)

g->m.ter(x, y) = g->m.ter(p.x, p.y);
g->m.ter(p.x, p.y) = t_floor;

//Move all Items within a container
std::vector <item> vItemMove = g->m.i_at(p.x, p.y);
for (int i=0; i < vItemMove.size(); i++)
g->m.add_item(x, y, vItemMove[i]);

g->m.i_clear(p.x, p.y);
}

void construct::done_tree(game *g, point p)
Expand Down
8 changes: 4 additions & 4 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ void game::process_activity()
}

if (u.skillLevel(reading->type) < reading->level) {
add_msg("You learn a little about %s!", reading->type->name().c_str());
add_msg("You learn a little about %s! (%d%%%%)", reading->type->name().c_str(), u.skillLevel(reading->type).exercise());
int min_ex = reading->time / 10 + u.int_cur / 4,
max_ex = reading->time / 5 + u.int_cur / 2 - u.skillLevel(reading->type).level();
if (min_ex < 1)
Expand Down Expand Up @@ -4186,7 +4186,7 @@ void game::open()
return;
}

if (m.ter(u.posx, u.posy) == t_floor)
if (m.is_indoor(u.posx, u.posy))
didit = m.open_door(u.posx + openx, u.posy + openy, true);
else
didit = m.open_door(u.posx + openx, u.posy + openy, false);
Expand Down Expand Up @@ -4816,7 +4816,7 @@ void game::examine()
*/
//Debug for testing things
}

else if (m.ter(examx, examy) == t_barndoor && query_yn("Pull the rope?"))
{
open_gate( this, examx, examy, t_barndoor );
Expand Down Expand Up @@ -7145,7 +7145,7 @@ void game::plmove(int x, int y)
// Only lose movement if we're blind
add_msg("You bump into a %s!", m.tername(x, y).c_str());
u.moves -= 100;
} else if (m.open_door(x, y, m.ter(u.posx, u.posy) == t_floor))
} else if (m.open_door(x, y, m.is_indoor(u.posx, u.posy)))
u.moves -= 100;
else if (m.ter(x, y) == t_door_locked || m.ter(x, y) == t_door_locked_alarm) {
u.moves -= 100;
Expand Down
50 changes: 42 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "debug.h"
#include <sys/stat.h>
#include <cstdlib>
#include <signal.h>

void exit_handler(int s);

int main(int argc, char *argv[])
{
Expand Down Expand Up @@ -58,6 +61,15 @@ int main(int argc, char *argv[])
MAPBUFFER.set_game(g);
MAPBUFFER.load();
load_options();

#if (!(defined _WIN32 || defined WINDOWS))
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = exit_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
#endif

do {
g->setup();
while (!g->do_turn()) ;
Expand All @@ -74,13 +86,35 @@ int main(int argc, char *argv[])
MAPBUFFER.save_if_dirty();
}

erase(); // Clear screen
endwin(); // End ncurses
#if (defined _WIN32 || defined WINDOWS)
system("cls"); // Tell the terminal to clear itself
system("color 07");
#else
system("clear"); // Tell the terminal to clear itself
#endif
exit_handler(-999);

return 0;
}

void exit_handler(int s) {
bool bExit = false;

if (s == 2) {
if (query_yn("Really Quit without saving?")) {
bExit = true;
}
} else if (s == -999) {
bExit = true;
} else {
//query_yn("Signal received: %d", s);
bExit = true;
}

if (bExit) {
erase(); // Clear screen
endwin(); // End ncurses
#if (defined _WIN32 || defined WINDOWS)
system("cls"); // Tell the terminal to clear itself
system("color 07");
#else
system("clear"); // Tell the terminal to clear itself
#endif

exit(1);
}
}
38 changes: 31 additions & 7 deletions map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,27 @@ ter_id& map::ter(const int x, const int y)
return grid[nonant]->ter[lx][ly];
}

bool map::is_indoor(const int x, const int y)
{
if (!INBOUNDS(x, y))
return false;

int iNumFloor = 0;
for (int iRow = -1; iRow <= 1; iRow++) {
for (int iCol = -1; iCol <= 1; iCol++) {
if (terlist[ter(iRow+x, iCol+y)].name == "floor" &&
terlist[ter(iRow+x, iCol+y)].flags & mfb(supports_roof)) {
iNumFloor++;
}
}
}

if (iNumFloor > 0)
return true;

return false;
}

std::string map::tername(const int x, const int y)
{
return terlist[ter(x, y)].name;
Expand Down Expand Up @@ -1262,6 +1283,8 @@ bool map::bash(const int x, const int y, const int str, std::string &sound, int
}
break;

case t_sink:
case t_bathtub:
case t_toilet:
result = dice(8, 4) - 8;
if (res) *res = result;
Expand All @@ -1277,6 +1300,9 @@ bool map::bash(const int x, const int y, const int str, std::string &sound, int

case t_dresser:
case t_bookcase:
case t_pool_table:
case t_counter:
case t_table:
result = rng(0, 45);
if (res) *res = result;
if (str >= result) {
Expand Down Expand Up @@ -1307,7 +1333,9 @@ bool map::bash(const int x, const int y, const int str, std::string &sound, int
break;

case t_bench:
case t_counter:
case t_chair:
case t_desk:
case t_cupboard:
result = rng(0, 30);
if (res) *res = result;
if (str >= result) {
Expand Down Expand Up @@ -1490,12 +1518,6 @@ void map::destroy(game *g, const int x, const int y, const bool makesound)
break;

case t_floor:
case t_counter:
case t_bookcase:
case t_rack:
case t_dresser:
case t_table:
case t_pool_table:
g->sound(x, y, 20, "SMASH!!");
for (int i = x - 2; i <= x + 2; i++) {
for (int j = y - 2; j <= y + 2; j++) {
Expand Down Expand Up @@ -1779,6 +1801,8 @@ bool map::hit_with_acid(game *g, const int x, const int y)
break;

case t_toilet:
case t_sink:
case t_bathtub:
case t_gas_pump:
case t_gas_pump_smashed:
return false;
Expand Down
5 changes: 3 additions & 2 deletions map.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct itype;

// TODO: This should be const& but almost no functions are const
struct wrapped_vehicle{
int x;
int x;
int y;
int i; // submap col
int j; // submap row
Expand Down Expand Up @@ -110,6 +110,7 @@ class map

// Terrain
ter_id& ter(const int x, const int y); // Terrain at coord (x, y); {x|y}=(0, SEE{X|Y}*3]
bool is_indoor(const int x, const int y); // Check if current ter is indoors
std::string tername(const int x, const int y); // Name of terrain at (x, y)
std::string features(const int x, const int y); // Words relevant to terrain (sharp, etc)
bool has_flag(const t_flag flag, const int x, const int y); // checks terrain and vehicles
Expand Down Expand Up @@ -187,7 +188,7 @@ class map
void create_anomaly(const int cx, const int cy, artifact_natural_property prop);
vehicle *add_vehicle(game *g, vhtype_id type, const int x, const int y, const int dir);
computer* add_computer(const int x, const int y, std::string name, const int security);

std::vector <itype*> *itypes;
std::set<vehicle*> vehicle_list;
std::map< std::pair<int,int>, std::pair<vehicle*,int> > veh_cached_parts;
Expand Down
Loading