From 0a0ea3cf11173c862f482674e3aaca30839c5e8a Mon Sep 17 00:00:00 2001 From: Alien_AV Date: Wed, 29 Jun 2011 17:03:55 +0300 Subject: [PATCH 1/3] adjusting for windows compatibility, minor bug fixes --- game.cpp | 168 ++++++++++++++++++++--------------------------- game.h | 36 +++++++++- help.cpp | 20 +----- newcharacter.cpp | 27 ++------ output.cpp | 28 ++++---- output.h | 24 +++---- player.cpp | 52 +++++++-------- 7 files changed, 170 insertions(+), 185 deletions(-) diff --git a/game.cpp b/game.cpp index 6397d35215..4a4833b3ef 100644 --- a/game.cpp +++ b/game.cpp @@ -17,38 +17,10 @@ void intro(); nc_color sev(int a); // Right now, ONLY used for scent debugging.... moncat_id mt_to_mc(mon_id type); // Pick the moncat that contains type - -/* Windows lacks the nanosleep() function. The following code was stuffed - together from GNUlib (http://www.gnu.org/software/gnulib/), which is - licensed under the GPLv3. */ #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Windows platforms. */ - -# ifdef __cplusplus -extern "C" { -# endif - -struct timespec -{ - time_t tv_sec; - long int tv_nsec; -}; - -# ifdef __cplusplus -} -# endif - -enum { BILLION = 1000 * 1000 * 1000 }; - -# define WIN32_LEAN_AND_MEAN -# include - -/* The Win32 function Sleep() has a resolution of about 15 ms and takes - at least 5 ms to execute. We use this function for longer time periods. - Additionally, we use busy-looping over short time periods, to get a - resolution of about 0.01 ms. In order to measure such short timespans, - we use the QueryPerformanceCounter() function. */ - +/* Windows lacks the nanosleep() function. The following code was stuffed + together from GNUlib (http://www.gnu.org/software/gnulib/), which is + licensed under the GPLv3. */ int nanosleep (const struct timespec *requested_delay, struct timespec *remaining_delay) @@ -223,7 +195,7 @@ fivedozenwhales@gmail.com."); if (!dir) { #if (defined _WIN32 || defined __WIN32__) mkdir("save"); -#else +#else mkdir("save", 0777); #endif dir = opendir("save"); @@ -547,7 +519,7 @@ void game::start_tutorial(tut_type type) m.add_item(SEEX * 2 - 2, SEEY * 2 + 7, itypes[itm_cig], 0); m.add_item(SEEX * 2 - 2, SEEY * 2 + 7, itypes[itm_codeine], 0); m.add_item(SEEX * 2 - 3, SEEY * 2 + 7, itypes[itm_water], 0); - + levz = 0; u.posx = SEEX + 2; u.posy = SEEY + 4; @@ -879,7 +851,7 @@ void game::update_weather() new_weather = weather_type(int(new_weather) + 1); } weather = new_weather; - + // Now update temperature if (!one_in(4)) { // 3 in 4 chance of respecting avg temp for the weather int average = weather_data[weather].avg_temperature[season]; @@ -1087,7 +1059,7 @@ int& game::scent(int x, int y) } return grscent[x][y]; } - + void game::update_scent() { signed int newscent[SEEX * 3][SEEY * 3]; @@ -1290,7 +1262,7 @@ void game::save() fout.open(playerfile.str().c_str()); // First, write out basic game state information. fout << turn << " " << int(last_target) << " " << int(run_mode) << " " << - mostseen << " " << nextinv << " " << next_npc_id << " " << + mostseen << " " << nextinv << " " << next_npc_id << " " << next_mission_id << " " << nextspawn << " " << int(temperature) << " " << levx << " " << levy << " " << levz << " " << cur_om.posx << " " << cur_om.posy << " " << std::endl; @@ -1328,7 +1300,7 @@ void game::advance_nextinv() else nextinv++; } - + void game::add_msg(const char* msg, ...) { char buff[512]; @@ -1364,7 +1336,7 @@ void game::add_event(event_type type, int on_turn, faction* rel) void game::debug() { // WINDOW *w = newwin(80, 25, 0, 0); -// mvwprintw(w, +// mvwprintw(w, } void game::mondebug() @@ -1434,7 +1406,7 @@ void game::disp_kills() refresh_all(); return; } - + for (int i = 0; i < types.size(); i++) { if (i < 24) { mvwprintz(w, i + 1, 0, types[i]->color, "%c %s", types[i]->sym, @@ -1460,7 +1432,7 @@ void game::disp_kills() mvwprintz(w, i + 1, hori, c_white, "%d", count[i]); } } - + wrefresh(w); getch(); werase(w); @@ -1468,7 +1440,7 @@ void game::disp_kills() delwin(w); refresh_all(); } - + void game::disp_NPCs() { WINDOW* w = newwin(25, 80, 0, 0); @@ -1664,9 +1636,9 @@ void game::list_missions() selection = umissions.size() - 1; break; } - + } while (ch != 'q' && ch != 'Q' && ch != KEY_ESCAPE); - + werase(w_missions); delwin(w_missions); @@ -1891,16 +1863,16 @@ void game::draw_minimap() nc_color ter_color; long ter_sym; bool seen = true; - overmap hori; - overmap vert; + overmap *hori = NULL; //when it wasn't a pointer it used too much space on stack and died on windows + overmap *vert = NULL; //not to forget to free it in the end of function if (cursx < 2) - hori = overmap(this, cur_om.posx - 1, cur_om.posy, 0); + hori = new overmap(this, cur_om.posx - 1, cur_om.posy, 0); if (cursx > OMAPX - 3) - hori = overmap(this, cur_om.posx + 1, cur_om.posy, 0); + hori = new overmap(this, cur_om.posx + 1, cur_om.posy, 0); if (cursy < 2) - vert = overmap(this, cur_om.posx, cur_om.posy - 1, 0); + vert = new overmap(this, cur_om.posx, cur_om.posy - 1, 0); if (cursy > OMAPY - 3) - vert = overmap(this, cur_om.posx, cur_om.posy + 1, 0); + vert = new overmap(this, cur_om.posx, cur_om.posy + 1, 0); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { omx = cursx + i; @@ -1912,20 +1884,20 @@ void game::draw_minimap() cur_ter = ot_null; } else if (omx < 0) { omx += OMAPX; - cur_ter = hori.ter(omx, omy); - hori.seen(omx, omy) = true; + cur_ter = hori->ter(omx, omy); + hori->seen(omx, omy) = true; } else if (omx >= OMAPX) { omx -= OMAPX; - cur_ter = hori.ter(omx, omy); - hori.seen(omx, omy) = true; + cur_ter = hori->ter(omx, omy); + hori->seen(omx, omy) = true; } else if (omy < 0) { omy += OMAPY; - cur_ter = vert.ter(omx, omy); - vert.seen(omx, omy) = true; + cur_ter = vert->ter(omx, omy); + vert->seen(omx, omy) = true; } else if (omy >= OMAPY) { omy -= OMAPY; - cur_ter = vert.ter(omx, omy); - vert.seen(omx, omy) = true; + cur_ter = vert->ter(omx, omy); + vert->seen(omx, omy) = true; } else { debugmsg("No data loaded! omx: %d omy: %d", omx, omy); } @@ -1957,16 +1929,16 @@ void game::draw_minimap() cur_ter = ot_null; } else if (barx < 0) { barx += OMAPX; - cur_ter = hori.ter(barx, bary); + cur_ter = hori->ter(barx, bary); } else if (barx >= OMAPX) { barx -= OMAPX; - cur_ter = hori.ter(barx, bary); + cur_ter = hori->ter(barx, bary); } else if (bary < 0) { bary += OMAPY; - cur_ter = vert.ter(barx, bary); + cur_ter = vert->ter(barx, bary); } else if (bary >= OMAPY) { bary -= OMAPY; - cur_ter = vert.ter(barx, bary); + cur_ter = vert->ter(barx, bary); } if (oterlist[cur_ter].see_cost <= 2 || seen) { if (omx >= 0 && omx < OMAPX && omy >= 0 && omy < OMAPY) { @@ -1976,20 +1948,20 @@ void game::draw_minimap() cur_ter = ot_null; } else if (omx < 0) { omx += OMAPX; - cur_ter = hori.ter(omx, omy); - hori.seen(omx, omy) = true; + cur_ter = hori->ter(omx, omy); + hori->seen(omx, omy) = true; } else if (omx >= OMAPX) { omx -= OMAPX; - cur_ter = hori.ter(omx, omy); - hori.seen(omx, omy) = true; + cur_ter = hori->ter(omx, omy); + hori->seen(omx, omy) = true; } else if (omy < 0) { omy += OMAPY; - cur_ter = vert.ter(omx, omy); - vert.seen(omx, omy) = true; + cur_ter = vert->ter(omx, omy); + vert->seen(omx, omy) = true; } else if (omy >= OMAPY) { omy -= OMAPY; - cur_ter = vert.ter(omx, omy); - vert.seen(omx, omy) = true; + cur_ter = vert->ter(omx, omy); + vert->seen(omx, omy) = true; } ter_color = oterlist[cur_ter].color; ter_sym = oterlist[cur_ter].sym; @@ -1999,6 +1971,8 @@ void game::draw_minimap() } } wrefresh(w_minimap); + if(hori != NULL)delete hori; + if(vert != NULL)delete vert; } void game::hallucinate() @@ -2204,7 +2178,7 @@ void game::mon_info() // 0 1 2 // 3 4 5 // 6 7 8 - std::vector unique_types[10]; + std::vector unique_types[10]; int direction; for (int i = 0; i < z.size(); i++) { if (u_see(&(z[i]), buff)) { @@ -2232,7 +2206,7 @@ void game::mon_info() else direction = 4; } - + if (!vector_has(unique_types[direction], z[i].type->id)) unique_types[direction].push_back(z[i].type->id); } @@ -2266,7 +2240,7 @@ void game::mon_info() unique_types[direction].push_back(-1 - i); } } - + if (newseen > mostseen) { cancel_activity_query("Monster spotted!"); if (run_mode == 1) @@ -2463,7 +2437,7 @@ void game::check_warmth() add_msg("Your body is cold."); u.add_disease(DI_COLD, abs(warmth), this); } else if (warmth >= 12) { - add_msg("Your body is too hot."); + add_msg("Your body is too hot."); u.add_disease(DI_HOT, warmth * 2, this); } // HANDS @@ -2906,7 +2880,7 @@ void game::kill_mon(int index) last_target = -1; else if (last_target > index) last_target--; -} +} void game::explode_mon(int index) { @@ -2946,7 +2920,7 @@ void game::explode_mon(int index) for (int i = 0; i < num_chunks; i++) { int tarx = posx + rng(-3, 3), tary = posy + rng(-3, 3); std::vector traj = line_to(posx, posy, tarx, tary, 0); - + bool done = false; for (int j = 0; j < traj.size() && !done; j++) { tarx = traj[j].x; @@ -2979,7 +2953,7 @@ void game::explode_mon(int index) m.add_item(tarx, tary, meat, turn); } } - + z.erase(z.begin()+index); if (last_target == index) last_target = -1; @@ -3179,7 +3153,7 @@ void game::examine() add_msg("The nearby doors slide into the floor."); u.use_up(itm_card_id, 1); } - bool using_electrohack = (u.has_amount(itm_electrohack, 1) && + bool using_electrohack = (u.has_amount(itm_electrohack, 1) && query_yn("Use electrohack on the reader?")); bool using_fingerhack = (!using_electrohack && u.has_bionic(bio_fingerhack) && u.power_level > 0 && @@ -3342,7 +3316,7 @@ void game::look_around() m.drawsq(w_terrain, u, lx, ly, true, true); } else m.drawsq(w_terrain, u, lx, ly, true, true); - + } else if (lx == u.posx && ly == u.posy) { mvwputch_inv(w_terrain, SEEX, SEEY, u.color(), '@'); mvwprintw(w_look, 1, 1, "You (%s)", u.name.c_str()); @@ -3826,7 +3800,7 @@ bool game::handle_liquid(item &liquid, bool from_ground, bool infinite) } return false; } - + void game::drop() { @@ -3986,7 +3960,7 @@ void game::plthrow() { char ch = inv("Throw item:"); int range = u.throw_range(u.lookup_item(ch)); - if (range < 0) { + if (range < 0) { add_msg("You don't have that item."); return; } else if (range == 0) { @@ -4007,12 +3981,12 @@ void game::plthrow() if (u_see(j, k, junk)) { if (k >= y0 && k <= y1 && j >= x0 && j <= x1) m.drawsq(w_terrain, u, j, k, false, true); - else + else mvwputch(w_terrain, k + SEEY - u.posy, j + SEEX - u.posx, c_dkgray, '#'); } } } - + std::vector mon_targets; std::vector targetindices; int passtarget = -1; @@ -4063,7 +4037,7 @@ void game::plfire(bool burst) if (u_see(j, k, junk)) { if (k >= y0 && k <= y1 && j >= x0 && j <= x1) m.drawsq(w_terrain, u, j, k, false, true); - else + else mvwputch(w_terrain, k + SEEY - y, j + SEEX - x, c_dkgray, '#'); } } @@ -4073,7 +4047,7 @@ void game::plfire(bool burst) std::vector targetindices; int passtarget = -1; for (int i = 0; i < z.size(); i++) { - if (z[i].posx >= x0 && z[i].posx <= x1 && + if (z[i].posx >= x0 && z[i].posx <= x1 && z[i].posy >= y0 && z[i].posy <= y1 && z[i].friendly == 0 && u_see(&(z[i]), junk)) { mon_targets.push_back(z[i]); @@ -4150,7 +4124,7 @@ void game::butcher() } } } - + void game::complete_butcher(int index) { mtype* corpse = m.i_at(u.posx, u.posy)[index].corpse; @@ -4178,7 +4152,7 @@ void game::complete_butcher(int index) skill_shift -= rng(0, 5 * (4 - u.str_cur)) / 4; if (factor > 0) skill_shift -= rng(0, factor / 5); - + int practice = 4 + pieces; if (practice > 20) practice = 20; @@ -4325,7 +4299,7 @@ void game::reload() add_msg("You can't reload a %s!", u.weapon.tname(this).c_str()); refresh_all(); } - + void game::unload() { if (!u.weapon.is_gun() && u.weapon.contents.size() == 0 && @@ -4420,7 +4394,7 @@ void game::unload() } u.weapon.curammo = NULL; } - + void game::wield() { if (u.weapon.type->id > num_items) { @@ -4535,7 +4509,7 @@ void game::plmove(int x, int y) int side = rng(0, 1); add_msg("You hit %s's %s.", active_npc[npcdex].name.c_str(), body_part_name(bphit, side).c_str()); - if (u.has_bionic(bio_shock) && u.power_level >= 2 && one_in(3) && + if (u.has_bionic(bio_shock) && u.power_level >= 2 && one_in(3) && (!u.is_armed() || u.weapon.type->id > num_items)) { add_msg("You shock %s!", active_npc[npcdex].name.c_str()); int shock = rng(2, 5); @@ -4594,7 +4568,7 @@ void game::plmove(int x, int y) if (m.move_cost(x, y) > 0) { // move_cost() of 0 = impassible (e.g. a wall) if (u.underwater) u.underwater = false; - int movecost; + int movecost; if (m.field_at(x, y).is_dangerous() && !query_yn("Really step into that %s?", m.field_at(x, y).name().c_str())) return; @@ -4605,7 +4579,7 @@ void game::plmove(int x, int y) if (u.has_trait(PF_PARKOUR) && m.move_cost(x, y) <= 4) movecost = 100 + u.encumb(bp_feet) * 5 + u.encumb(bp_legs) * 3; else - movecost = m.move_cost(x, y) * 50 + u.encumb(bp_feet) * 5 + + movecost = m.move_cost(x, y) * 50 + u.encumb(bp_feet) * 5 + u.encumb(bp_legs) * 3; if (u.has_trait(PF_FLEET) && m.move_cost(x, y) == 2) movecost = int(movecost * .85); @@ -4729,7 +4703,7 @@ void game::plmove(int x, int y) tutorial_message(LESSON_SMASH); } } -} +} void game::plswim(int x, int y) { @@ -4863,7 +4837,7 @@ void game::vertical_move(int movez, bool force) } refresh_all(); } - + void game::update_map(int &x, int &y) { @@ -4897,7 +4871,7 @@ void game::update_map(int &x, int &y) cur_om.save(u.name); cur_om = overmap(this, cur_om.posx + olevx, cur_om.posy + olevy, cur_om.posz); } - + // Shift monsters for (int i = 0; i < z.size(); i++) { z[i].shift(shiftx, shifty); @@ -5022,7 +4996,7 @@ void game::spawn_mon(int shiftx, int shifty) zom = monster(mtypes[type]); iter = 0; do { - monx = rng(0, SEEX * 3 - 1); + monx = rng(0, SEEX * 3 - 1); mony = rng(0, SEEY * 3 - 1); if (shiftx == -1) monx = 0 - SEEX * 2; if (shiftx == 1) monx = SEEX * 4; if (shifty == -1) mony = 0 - SEEX * 2; if (shifty == 1) mony = SEEY * 4; @@ -5043,7 +5017,7 @@ void game::spawn_mon(int shiftx, int shifty) } } } -} +} mon_id game::valid_monster_from(std::vector group) { @@ -5209,7 +5183,7 @@ std::vector game::factions_at(int x, int y) } return ret; } - + oter_id game::ter_at(int omx, int omy, bool& mark_as_seen) { oter_id ret; diff --git a/game.h b/game.h index b74f171d39..7e1f48b681 100644 --- a/game.h +++ b/game.h @@ -23,6 +23,40 @@ #define BULLET_SPEED 10000000 #define EXPLOSION_SPEED 70000000 + +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +/* Windows platforms. */ + +# ifdef __cplusplus +extern "C" { +# endif + +struct timespec +{ + time_t tv_sec; + long int tv_nsec; +}; + +# ifdef __cplusplus +} +# endif + +enum { BILLION = 1000 * 1000 * 1000 }; + +# define WIN32_LEAN_AND_MEAN +# include + +/* The Win32 function Sleep() has a resolution of about 15 ms and takes + at least 5 ms to execute. We use this function for longer time periods. + Additionally, we use busy-looping over short time periods, to get a + resolution of about 0.01 ms. In order to measure such short timespans, + we use the QueryPerformanceCounter() function. */ + +int +nanosleep (const struct timespec *requested_delay, + struct timespec *remaining_delay); +#endif + enum tut_type { TUT_NULL, TUT_BASIC, TUT_COMBAT, @@ -157,7 +191,7 @@ class game void wait(); // Long wait (player action) '^' void open(); // Open a door 'o' void close(); // Close a door 'c' - void smash(); // Smash terrain + void smash(); // Smash terrain void craft(); // See crafting.cpp void make_craft(recipe *making); // See crafting.cpp void complete_craft(); // See crafting.cpp diff --git a/help.cpp b/help.cpp index 01597d51c0..ca89380b52 100644 --- a/help.cpp +++ b/help.cpp @@ -1,20 +1,6 @@ #include "game.h" #include "keypress.h" -#ifndef LINE_XOXO - #define LINE_XOXO 4194424 - #define LINE_OXOX 4194417 - #define LINE_XXOO 4194413 - #define LINE_OXXO 4194412 - #define LINE_OOXX 4194411 - #define LINE_XOOX 4194410 - #define LINE_XXXO 4194420 - #define LINE_XXOX 4194422 - #define LINE_XOXX 4194421 - #define LINE_OXXX 4194423 - #define LINE_XXXX 4194414 -#endif - void game::help() { char ch; @@ -46,7 +32,7 @@ m: Survival tips\n\ 5: Frequently Asked Questions (Some spoilers!)\n\ \n\ q: Return to game"); - + ch = getch(); switch (ch) { case 'a': @@ -67,7 +53,7 @@ setting makes some tasks easier. Firearms, medications, and a wide variety of\n\ tools are all available to help you survive."); getch(); break; - + case 'b': case 'B': erase(); @@ -492,7 +478,7 @@ F Forest - May be dense or sparse. Slow moving; foragable food."); mvputch(3, 8, c_dkgray, LINE_XOXX); mvputch(3, 9, c_dkgray, LINE_OXXX); mvputch(3, 10, c_dkgray, LINE_XXXX); - + mvprintz( 3, 12, c_dkgray, "\ Road - Safe from burrowing animals."); mvprintz( 4, 0, c_dkgray, "\ diff --git a/newcharacter.cpp b/newcharacter.cpp index 201fa5d38c..cc8d19fd16 100644 --- a/newcharacter.cpp +++ b/newcharacter.cpp @@ -5,19 +5,6 @@ #include "game.h" #include -// ncurses has not yet been initialized, so we need to define our line chars -#define LINE_XOXO 4194424 -#define LINE_OXOX 4194417 -#define LINE_XXOO 4194413 -#define LINE_OXXO 4194412 -#define LINE_OOXX 4194411 -#define LINE_XOOX 4194410 -#define LINE_XXXO 4194420 -#define LINE_XXOX 4194422 -#define LINE_XOXX 4194421 -#define LINE_OXXX 4194423 -#define LINE_XXXX 4194414 - // Colors used in this file: (Most else defaults to c_ltgray) #define COL_STAT_ACT c_ltred // Selected stat #define COL_TR_GOOD c_green // Good trait descriptive text @@ -188,7 +175,7 @@ bool player::create(game *g, character_type type) if (tab < 0) return false; - + // Character is finalized. Now just set up HP, &c for (int i = 0; i < num_hp_parts; i++) { hp_max[i] = calc_HP(str_max, has_trait(PF_TOUGH)); @@ -274,8 +261,8 @@ void draw_tabs(WINDOW* w) mvwputch(w, 1,57, c_ltgray, LINE_XOXO); mvwputch(w, 1,73, c_ltgray, LINE_XOXO); } - - + + int set_stats(WINDOW* w, player *u, int &points) { @@ -382,7 +369,7 @@ int set_stats(WINDOW* w, player *u, int &points) mvwprintz(w,11, 33, COL_STAT_ACT, " "); break; } - + wrefresh(w); ch = input(); if (ch == 'j' && sel < 4) @@ -654,7 +641,7 @@ int set_skills(WINDOW* w, player *u, int &points) mvwputch(w, 2,57, c_ltgray, LINE_XXOX); mvwputch(w, 2,73, c_ltgray, LINE_XXOX); mvwprintz(w,1,40, h_ltgray, " SKILLS "); - + int cur_sk = 1; do { @@ -720,7 +707,7 @@ int set_skills(WINDOW* w, player *u, int &points) } } } - + wrefresh(w); switch (input()) { case 'j': @@ -782,7 +769,7 @@ Gender: Male Female (Press spacebar to toggle)"); When your character is finished and you're ready to start playing, press '>'."); mvwprintz(w,12, 2, c_ltgray, "\ To go back and review your character, press '<'."); - + int line = 1; bool noname = false; long ch; diff --git a/output.cpp b/output.cpp index 1f92609ac9..3422954913 100644 --- a/output.cpp +++ b/output.cpp @@ -12,17 +12,19 @@ #include "rng.h" #include "keypress.h" -#define LINE_XOXO 4194424 -#define LINE_OXOX 4194417 -#define LINE_XXOO 4194413 -#define LINE_OXXO 4194412 -#define LINE_OOXX 4194411 -#define LINE_XOOX 4194410 -#define LINE_XXXO 4194420 -#define LINE_XXOX 4194422 -#define LINE_XOXX 4194421 -#define LINE_OXXX 4194423 -#define LINE_XXXX 4194414 +#ifndef LINE_XOXO +#define LINE_XOXO ACS_VLINE +#define LINE_OXOX ACS_HLINE +#define LINE_XXOO ACS_LLCORNER +#define LINE_OXXO ACS_ULCORNER +#define LINE_OOXX ACS_URCORNER +#define LINE_XOOX ACS_LRCORNER +#define LINE_XXXO ACS_RTEE +#define LINE_XXOX ACS_BTEE +#define LINE_XOXX ACS_LTEE +#define LINE_OXXX ACS_TTEE +#define LINE_XXXX ACS_PLUS +#endif nc_color hilite(nc_color c) { @@ -446,7 +448,7 @@ void popup_top(const char *mes, ...) } line_num++; mvwprintz(w, line_num, 1, c_white, tmp.c_str()); - + wrefresh(w); char ch; do @@ -497,7 +499,7 @@ void popup(const char *mes, ...) } line_num++; mvwprintz(w, line_num, 1, c_white, tmp.c_str()); - + wrefresh(w); char ch; do diff --git a/output.h b/output.h index 88a9123981..66fd941a08 100644 --- a/output.h +++ b/output.h @@ -7,17 +7,19 @@ #include // LINE_NESW - X for on, O for off -#define LINE_XOXO 4194424 -#define LINE_OXOX 4194417 -#define LINE_XXOO 4194413 -#define LINE_OXXO 4194412 -#define LINE_OOXX 4194411 -#define LINE_XOOX 4194410 -#define LINE_XXXO 4194420 -#define LINE_XXOX 4194422 -#define LINE_XOXX 4194421 -#define LINE_OXXX 4194423 -#define LINE_XXXX 4194414 +#ifndef LINE_XOXO +#define LINE_XOXO ACS_VLINE +#define LINE_OXOX ACS_HLINE +#define LINE_XXOO ACS_LLCORNER +#define LINE_OXXO ACS_ULCORNER +#define LINE_OOXX ACS_URCORNER +#define LINE_XOOX ACS_LRCORNER +#define LINE_XXXO ACS_RTEE +#define LINE_XXOX ACS_BTEE +#define LINE_XOXX ACS_LTEE +#define LINE_OXXX ACS_TTEE +#define LINE_XXXX ACS_PLUS +#endif void mvputch(int y, int x, nc_color FG, long ch); void wputch(WINDOW* w, nc_color FG, long ch); diff --git a/player.cpp b/player.cpp index f38f05869f..fe1d694e40 100644 --- a/player.cpp +++ b/player.cpp @@ -71,7 +71,7 @@ void player::normalize(game *g) hp_cur[i] = hp_max[i]; } } - + void player::reset() { // Reset our stats to normal levels @@ -130,7 +130,7 @@ void player::reset() dex_cur += int(stim / 10); per_cur += int(stim / 7); int_cur += int(stim / 6); - if (stim >= 30) { + if (stim >= 30) { dex_cur -= int(abs(stim - 15) / 8); per_cur -= int(abs(stim - 15) / 12); int_cur -= int(abs(stim - 15) / 14); @@ -148,7 +148,7 @@ void player::reset() per_cur = 0; if (int_cur < 0) int_cur = 0; - + int mor = morale_level(); if (mor >= 300) xp_pool += 4; @@ -420,12 +420,12 @@ void player::disp_info(game *g) int dexbonus = int(stim / 10); int perbonus = int(stim / 7); int intbonus = int(stim / 6); - if (abs(stim) >= 30) { + if (abs(stim) >= 30) { dexbonus -= int(abs(stim - 15) / 8); perbonus -= int(abs(stim - 15) / 12); intbonus -= int(abs(stim - 15) / 14); } - + if (dexbonus < 0) effect_name.push_back("Stimulant Overdose"); else @@ -731,7 +731,7 @@ which require brute force."); mvwprintz(w_stats, 3, 2, h_ltgray, "Dexterity:"); mvwprintz(w_info, 0, 0, c_magenta, "\ Dexterity affects your chance to hit in melee combat, helps you steady your\n\ -gun for ranged combat, and enhances many actions that require finesse."); +gun for ranged combat, and enhances many actions that require finesse."); } else if (line == 2) { mvwprintz(w_stats, 4, 2, h_ltgray, "Intelligence:"); mvwprintz(w_info, 0, 0, c_magenta, "\ @@ -1005,7 +1005,7 @@ encumb(bp_feet) * 5); } else { mvwprintz(w_skills, 2 + i - min, 1, status, "%s:", skill_name(skillslist[i]).c_str()); - mvwprintz(w_skills, 2 + i - min,19, status, "%d (%s%d%%%%)", + mvwprintz(w_skills, 2 + i - min,19, status, "%d (%s%d%%%%)", sklevel[skillslist[i]], (skexercise[skillslist[i]] < 10 && skexercise[skillslist[i]] >= 0 ? " " : ""), @@ -1055,7 +1055,7 @@ encumb(bp_feet) * 5); } } } while (!done); - + werase(w_info); werase(w_grid); werase(w_stats); @@ -1066,7 +1066,7 @@ encumb(bp_feet) * 5); werase(w_speed); werase(w_info); - delwin(w_info); + //delwin(w_info); delwin(w_grid); delwin(w_stats); delwin(w_encumb); @@ -1119,7 +1119,7 @@ void player::disp_morale() werase(w); delwin(w); } - + void player::disp_status(WINDOW *w) { @@ -2117,7 +2117,7 @@ int player::hit_mon(game *g, monster *z) } else { headshot &= z->hp < dam && one_in(2); if (headshot && can_see) - g->add_msg("%s crush%s the %s's skull in a single blow!", + g->add_msg("%s crush%s the %s's skull in a single blow!", You.c_str(), (is_u ? "" : "es"), z->name().c_str()); else if (can_see) g->add_msg("%s deliver%s a crushing punch!",You.c_str(),(is_u ? "" : "s")); @@ -2290,7 +2290,7 @@ bool player::hit_player(player &p, body_part &bp, int &hitdam, int &hitcut) bp = bp_arms; else bp = bp_legs; - + hitdam = base_damage(); if (unarmed) {// Unarmed bonuses @@ -2380,7 +2380,7 @@ int player::throw_range(int index) return str_cur * 2; return ret; } - + int player::base_damage(bool real_life) { int str = (real_life ? str_cur : str_max); @@ -2448,7 +2448,7 @@ int player::throw_dex_mod(bool real_life) return 0; if (dex >= 10) return (real_life ? 0 - rng(0, dex - 9) : 9 - dex); - + int deviation = 0; if (dex < 6) deviation = 3 * (8 - dex); @@ -2750,7 +2750,7 @@ void player::add_disease(dis_type type, int duration, game *g) } i++; } - if (!found) { + if (!found) { if (!is_npc()) dis_msg(g, type); disease tmp(type, duration); @@ -3229,7 +3229,7 @@ void player::add_morale(morale_type type, int bonus, int max_bonus, morale.push_back(tmp); } } - + void player::sort_inv() { std::vector types[8]; // guns ammo weaps armor food tools books other @@ -3263,7 +3263,7 @@ void player::sort_inv() void player::i_add(item it) { - if (it.is_food() || it.is_ammo() || it.is_gun() || it.is_armor() || + if (it.is_food() || it.is_ammo() || it.is_gun() || it.is_armor() || it.is_book() || it.is_tool() || it.is_weap() || it.is_food_container()) inv_sorted = false; if (it.is_ammo()) { // Possibly combine with other ammo @@ -3495,7 +3495,7 @@ void player::use_up(itype_id it, int quantity) int cur_item = 0; while (used < quantity && cur_item < inv.size()) { int local_used = 0; - if (inv[cur_item].type->id == it) { + if (inv[cur_item].type->id == it) { if (inv[cur_item].is_ammo() || inv[cur_item].is_tool()) { if (quantity < inv[cur_item].charges) { local_used = quantity; @@ -3558,7 +3558,7 @@ void player::use_amount(itype_id it, int quantity) } while (used < quantity && cur_item < inv.size()) { - if (inv[cur_item].type->id == it) { + if (inv[cur_item].type->id == it) { used++; i_remn(cur_item); cur_item--; @@ -3591,7 +3591,7 @@ void player::use_charges(itype_id it, int quantity) for (int i = 0; i < inv.size(); i++) { int local_used = 0; - if (inv[i].type->id == it) { + if (inv[i].type->id == it) { local_used = inv[i].charges; if (local_used > quantity) inv[i].charges = local_used - quantity; @@ -3710,7 +3710,7 @@ bool player::has_charges(itype_id it, int quantity) for (int i = 0; i < inv.size(); i++) { if (inv[i].type->id == it) i_have += inv[i].charges; - else if (inv[i].contents.size() > 0 && inv[i].contents[0].type->id == it) + else if (inv[i].contents.size() > 0 && inv[i].contents[0].type->id == it) i_have += inv[i].contents[0].charges; if (i_have >= quantity) return true; @@ -3854,7 +3854,7 @@ bool player::eat(game *g, int index) if (spoiled) { // We're only warned if we're a supertaster, OR the food is very old - if ((!has_trait(PF_SUPERTASTER) && very_spoiled) || + if ((!has_trait(PF_SUPERTASTER) && very_spoiled) || (!is_npc() && query_yn("This %s smells awful! Eat it?", eaten->tname(g).c_str()))) { if (is_npc()) @@ -3891,7 +3891,7 @@ bool player::eat(game *g, int index) use_charges(comest->tool, 1); // Tools like lighters get used if (comest->stim > 0 && stim < comest->stim * 3) stim += comest->stim; - + iuse use; (use.*comest->use)(g, this, eaten, false); add_addiction(comest->add, comest->addict); @@ -3936,7 +3936,7 @@ bool player::eat(game *g, int index) thirst = -20; } } - + eaten->charges--; if (eaten->charges <= 0) { if (which == -1) @@ -4291,7 +4291,7 @@ void player::read(game *g, char ch) activity = player_activity(ACT_READ, time, index); moves = 0; } - + void player::try_to_sleep(game *g) { add_disease(DI_LYING_DOWN, 300, g); @@ -4509,7 +4509,7 @@ void player::absorb(game *g, body_part bp, int &dam, int &cut) if (cut < 0) cut = 0; } - + int player::resist(body_part bp) { int ret = 0; From f0dfd7550d265348d739c173a1b316ae58e8683f Mon Sep 17 00:00:00 2001 From: Alien_AV Date: Fri, 1 Jul 2011 06:30:33 +0300 Subject: [PATCH 2/3] merged to upstream, HP now still shows after screen switches --- game.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/game.cpp b/game.cpp index 73ea16e959..902e1f22ec 100644 --- a/game.cpp +++ b/game.cpp @@ -1784,7 +1784,8 @@ void game::refresh_all() { draw(); draw_minimap(); - wrefresh(w_HP); + werase(w_HP); + draw_HP(); wrefresh(w_moninfo); wrefresh(w_messages); refresh(); From cbe8e564d9a59b5eb1c6eb0431d69b818e12fd0b Mon Sep 17 00:00:00 2001 From: Alien_AV Date: Fri, 1 Jul 2011 06:51:24 +0300 Subject: [PATCH 3/3] fix backspace, make screen clear attempt after exit not happen on windows --- game.cpp | 2 +- keypress.h | 9 +++++++++ main.cpp | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/game.cpp b/game.cpp index 902e1f22ec..7771e563a6 100644 --- a/game.cpp +++ b/game.cpp @@ -1784,7 +1784,7 @@ void game::refresh_all() { draw(); draw_minimap(); - werase(w_HP); + werase(w_HP); // fix by headswe draw_HP(); wrefresh(w_moninfo); wrefresh(w_messages); diff --git a/keypress.h b/keypress.h index b81ae3ba97..9a29733882 100644 --- a/keypress.h +++ b/keypress.h @@ -1,6 +1,15 @@ #ifndef _KEYPRESS_H_ #define _KEYPRESS_H_ #include + +/* Fix the backspace key on Windows (by jaydg) */ +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# if defined KEY_BACKSPACE +# undef KEY_BACKSPACE +# endif +# define KEY_BACKSPACE 8 +#endif + // Simple text input--translates numpad to vikeys long input(); // If ch is vikey, x & y are set to corresponding direction; ch=='y'->x=-1,y=-1 diff --git a/main.cpp b/main.cpp index e2ead6a1db..450abec166 100644 --- a/main.cpp +++ b/main.cpp @@ -25,7 +25,9 @@ int main(int argc, char *argv[]) while (!g.do_turn()); erase(); endwin(); + #if !(defined _WIN32 || defined __WIN32__) || defined __CYGWIN__ system("clear"); + #endif return 0; }