Skip to content
Snippets Groups Projects
Commit 8d658f8d authored by Jake Feddersen's avatar Jake Feddersen
Browse files

Fix some bugs

parent 3198d513
No related branches found
No related tags found
No related merge requests found
...@@ -242,7 +242,7 @@ position monster::monster_move(dungeon &d) { ...@@ -242,7 +242,7 @@ position monster::monster_move(dungeon &d) {
return pos; return pos;
} }
player_character::player_character(uint8_t x, uint8_t y) : character(10, '@', 1000) { player_character::player_character(uint8_t x, uint8_t y) : character(10, '@', 100) {
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
...@@ -506,11 +506,11 @@ item *player_character::take_off() { ...@@ -506,11 +506,11 @@ item *player_character::take_off() {
} }
item *player_character::drop_item() { item *player_character::drop_item() {
int slot = print_inventory("Select an item to equip, or ESC to cancel:"); int slot = print_inventory("Select an item to drop, or ESC to cancel:");
if (!(slot >= '0' && slot <= '9')) return 0; if (!(slot >= '0' && slot <= '9')) return 0;
item *item_to_drop = equipment[slot-'0']; item *item_to_drop = inventory[slot-'0'];
equipment[slot-'0'] = 0; inventory[slot-'0'] = 0;
return item_to_drop; return item_to_drop;
} }
......
...@@ -7,19 +7,19 @@ ...@@ -7,19 +7,19 @@
#include "util.h" #include "util.h"
int randrange(int min, int max) { int randrange(int min, int max) {
int range = max - min + 1; int range = max - min + 1;
return (rand() % range) + min; return (rand() % range) + min;
} }
int randchance(double prob) { int randchance(double prob) {
int resolution = RAND_MAX; int resolution = RAND_MAX;
return (rand() % resolution) < (prob * resolution); return (rand() % resolution) < (prob * resolution);
} }
int sign(int x) { int sign(int x) {
if (x > 0) return 1; if (x > 0) return 1;
if (x < 0) return -1; if (x < 0) return -1;
return 0; return 0;
} }
void parse_args(int argc, char *argv[], args *args) { void parse_args(int argc, char *argv[], args *args) {
...@@ -34,11 +34,11 @@ void parse_args(int argc, char *argv[], args *args) { ...@@ -34,11 +34,11 @@ void parse_args(int argc, char *argv[], args *args) {
int valid = 1; int valid = 1;
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "--save")) { if (!strcmp(argv[i], "--save")) {
args->save = 1; args->save = 1;
} else if (!strcmp(argv[i], "--load")) { } else if (!strcmp(argv[i], "--load")) {
args->load = 1; args->load = 1;
} else if (!strncmp(argv[i], "--seed=", 7)) { } else if (!strncmp(argv[i], "--seed=", 7)) {
if (strlen(argv[i]) > 7) { if (strlen(argv[i]) > 7) {
args->seed = atoi(argv[i] + 7); args->seed = atoi(argv[i] + 7);
} else { } else {
...@@ -62,18 +62,18 @@ void parse_args(int argc, char *argv[], args *args) { ...@@ -62,18 +62,18 @@ void parse_args(int argc, char *argv[], args *args) {
fprintf(stderr, " --load: \tInstead of generating a random dungeon, loads the saved dungeon\n\t\tfile from ~/.rlg327/dungeon\n"); fprintf(stderr, " --load: \tInstead of generating a random dungeon, loads the saved dungeon\n\t\tfile from ~/.rlg327/dungeon\n");
fprintf(stderr, " --save: \tSaves the dungeon to ~/.rlg327/dungeon\n"); fprintf(stderr, " --save: \tSaves the dungeon to ~/.rlg327/dungeon\n");
fprintf(stderr, " --seed: \tSeeds the random number generator to the given value. If not\n\t\tspecified, time(NULL) is used as the seed\n"); fprintf(stderr, " --seed: \tSeeds the random number generator to the given value. If not\n\t\tspecified, time(NULL) is used as the seed\n");
fprintf(stderr, " --nummon:\tSets the number of monsters to generate in the dungeon. If not\n\t\tspecified, the default is 7. Automatically capped at the number\n\t\tof empty spaces in the dungeon.\n\t\tIf nummon is 0, the game never ends and the PC wanders the\n\t\tdungeon endlessly.\n"); fprintf(stderr, " --nummon:\tSets the number of monsters to generate in the dungeon. If not\n\t\tspecified, the default is 7. Automatically capped at the number\n\t\tof empty spaces in the dungeon.\n");
fprintf(stderr, " -h: \tPrints this help information and exits\n"); fprintf(stderr, " -h: \tPrints this help information and exits\n");
exit(1); exit(1);
} }
} }
int position::operator==(const position &p) { int position::operator==(const position &p) {
return (x == p.x && y == p.y); return (x == p.x && y == p.y);
} }
position &position::operator=(const position &p) { position &position::operator=(const position &p) {
x = p.x; x = p.x;
y = p.y; y = p.y;
return *this; return *this;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment