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

Convert all other structs other than heap

parent c4962bc4
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@
class character {
public:
position_t pos;
position pos;
int speed;
int seq_num;
int next_turn;
......@@ -37,7 +37,7 @@ class player_character : public character {
class monster : public character {
public:
uint32_t characteristics;
position_t last_seen;
position last_seen;
monster(uint8_t x, uint8_t y);
......
......@@ -5,14 +5,15 @@
#include "distance_map.h"
#include "dungeon.h"
typedef struct dijkstra_path {
class dijkstra_path {
public:
heap_node_t *hn;
uint8_t pos[2];
int32_t cost;
} dijkstra_path_t;
};
static int32_t dijkstra_path_cmp(const void *key, const void *with) {
return ((dijkstra_path_t *) key)->cost - ((dijkstra_path_t *) with)->cost;
return ((dijkstra_path *) key)->cost - ((dijkstra_path *) with)->cost;
}
/**
......@@ -24,7 +25,7 @@ static int32_t dijkstra_path_cmp(const void *key, const void *with) {
void dijkstra_from_pos(dungeon &d, uint32_t dist[MAP_HEIGHT][MAP_WIDTH], int hardness_limit, int start_x, int start_y)
{
// Initialize the vairables
static dijkstra_path_t path[MAP_HEIGHT][MAP_WIDTH], *p;
static dijkstra_path path[MAP_HEIGHT][MAP_WIDTH], *p;
static uint32_t initialized = 0;
heap_t h;
uint8_t x, y;
......@@ -67,7 +68,7 @@ void dijkstra_from_pos(dungeon &d, uint32_t dist[MAP_HEIGHT][MAP_WIDTH], int har
}
// Main Dijkstra's Algorithm implementation
while ((p = (dijkstra_path_t *) heap_remove_min(&h))) {
while ((p = (dijkstra_path *) heap_remove_min(&h))) {
// Visit the current node, and set its distance
p->hn = NULL;
dist[p->pos[0]][p->pos[1]] = p->cost;
......
......@@ -100,7 +100,7 @@ void dungeon::gen_monsters(int nummon) {
}
// Record the positions of the open cells
position_t *monster_positions = (position_t *) malloc(open_cells * sizeof(position_t));
position *monster_positions = (position *) malloc(open_cells * sizeof(position));
k = 0;
for (i = 0; i < MAP_HEIGHT; i++) {
for (j = 0; j < MAP_WIDTH; j++) {
......@@ -115,7 +115,7 @@ void dungeon::gen_monsters(int nummon) {
// Shuffle the list of open cells
for (i = 0; i < open_cells; i++) {
int swap_index = rand() % open_cells;
position_t tmp = monster_positions[i];
position tmp = monster_positions[i];
monster_positions[i] = monster_positions[swap_index];
monster_positions[swap_index] = tmp;
}
......@@ -163,7 +163,7 @@ void dungeon::generate_stairs() {
// Up stairs
int num_up_stairs = randrange(1, 2);
upstair_count = num_up_stairs;
upstair_list = (position_t *) malloc(num_up_stairs * sizeof(position_t));
upstair_list = (position *) malloc(num_up_stairs * sizeof(position));
for (i = 0; i < num_up_stairs; i++) {
found_pos = 0;
......@@ -197,7 +197,7 @@ void dungeon::generate_stairs() {
// Down stairs
int num_down_stairs = randrange(1, 2);
downstair_count = num_down_stairs;
downstair_list = (position_t *) malloc(num_down_stairs * sizeof(position_t));
downstair_list = (position *) malloc(num_down_stairs * sizeof(position));
for (i = 0; i < num_down_stairs; i++) {
found_pos = 0;
......
......@@ -34,12 +34,12 @@ class dungeon {
room* room_list;
uint16_t upstair_count;
position_t* upstair_list;
position* upstair_list;
uint16_t downstair_count;
position_t* downstair_list;
position* downstair_list;
position_t player_pos;
position player_pos;
character *characters[MAP_HEIGHT][MAP_WIDTH];
......
......@@ -5,8 +5,8 @@
#include "util.h"
// Erratic tunneling monsters don't care about anything but the border
static position_t next_monster_move_tunnel_erratic(dungeon &d, monster *c) {
position_t next_move;
static position next_monster_move_tunnel_erratic(dungeon &d, monster *c) {
position next_move;
next_move.x = c->pos.x;
next_move.y = c->pos.y;
......@@ -19,8 +19,8 @@ static position_t next_monster_move_tunnel_erratic(dungeon &d, monster *c) {
}
// Erratic non-tunneling monsters have to pick a random open space
static position_t next_monster_move_erratic(dungeon &d, monster *c) {
position_t next_move;
static position next_monster_move_erratic(dungeon &d, monster *c) {
position next_move;
next_move.x = c->pos.x;
next_move.y = c->pos.y;
......@@ -35,13 +35,13 @@ static position_t next_monster_move_erratic(dungeon &d, monster *c) {
// Smart tunneling monsters move toward the last known position of the player following
// the tunneling distance map. Smart non-tunneling monsters do the same but use the non-tunneling
// distance map
static position_t next_monster_move_smart(dungeon &d, monster *c) {
static position next_monster_move_smart(dungeon &d, monster *c) {
int i, j;
uint32_t dist_to_target[MAP_HEIGHT][MAP_WIDTH];
dijkstra_from_pos(d, dist_to_target, (c->has_characteristic(TUNNEL)) ? 255 : 1, c->last_seen.x, c->last_seen.y);
position_t best = {c->pos.x, c->pos.y};
position best = {c->pos.x, c->pos.y};
uint32_t best_dist = dist_to_target[c->pos.y][c->pos.x];
for (i = max(0, c->pos.y-1); i < min(MAP_WIDTH, c->pos.y+2); i++) {
for (j = max(0, c->pos.x-1); j < min(MAP_WIDTH, c->pos.x+2); j++) {
......@@ -59,7 +59,7 @@ static position_t next_monster_move_smart(dungeon &d, monster *c) {
// Dumb tunneling monsters move directly toward the player position if they know it, and
// move erratically otherwise
// Dumb non-tunneling monsters do the same, but can't tunnel
static position_t next_monster_move_dumb(dungeon &d, monster *c) {
static position next_monster_move_dumb(dungeon &d, monster *c) {
if (c->last_seen.x == c->pos.x && c->last_seen.y == c->pos.y) {
if (c->has_characteristic(TUNNEL)) {
return next_monster_move_tunnel_erratic(d, c);
......@@ -67,14 +67,14 @@ static position_t next_monster_move_dumb(dungeon &d, monster *c) {
return next_monster_move_erratic(d, c);
}
} else {
position_t next_move;
position next_move;
next_move.x = c->pos.x + sign(c->last_seen.x - c->pos.x);
next_move.y = c->pos.y + sign(c->last_seen.y - c->pos.y);
return next_move;
}
}
position_t monster_move(dungeon &d, character *c) {
position monster_move(dungeon &d, character *c) {
if (c->is_player()) {
return c->pos;
}
......
......@@ -5,6 +5,6 @@
#include "character.h"
#include "util.h"
position_t monster_move(dungeon &d, character *c);
position monster_move(dungeon &d, character *c);
#endif
......@@ -31,7 +31,7 @@ void regen_dungeon(dungeon &d, heap_t *h, int nummon) {
int main(int argc, char* argv[]) {
int i;
args_t args;
args args;
parse_args(argc, argv, &args);
srand(args.seed);
......@@ -85,7 +85,7 @@ int main(int argc, char* argv[]) {
}
// The character decides where to move next
position_t next_move;
position next_move;
if (!c->is_player()) {
next_move = monster_move(d, c);
} else {
......
......@@ -84,7 +84,7 @@ void load_dungeon(dungeon &d) {
// Read the up staircases
read_short(f, &(d.upstair_count));
d.upstair_list = (position_t *) malloc(d.upstair_count * sizeof(position_t));
d.upstair_list = (position *) malloc(d.upstair_count * sizeof(position));
for (i = 0; i < d.upstair_count; i++) {
fread(&(d.upstair_list[i].x), 1, 1, f);
......@@ -93,7 +93,7 @@ void load_dungeon(dungeon &d) {
// Read the down staircases
read_short(f, &(d.downstair_count));
d.downstair_list = (position_t *) malloc(d.downstair_count * sizeof(position_t));
d.downstair_list = (position *) malloc(d.downstair_count * sizeof(position));
for (i = 0; i < d.downstair_count; i++) {
fread(&(d.downstair_list[i].x), 1, 1, f);
......
......@@ -21,7 +21,7 @@ int sign(int x) {
return 0;
}
void parse_args(int argc, char *argv[], args_t *args) {
void parse_args(int argc, char *argv[], args *args) {
int i;
// Default parameter values
......
......@@ -31,24 +31,26 @@ int randchance(double prob);
*/
int sign(int x);
typedef struct args {
class args {
public:
int load;
int save;
int seed;
int nummon;
} args_t;
};
typedef struct {
class position {
public:
uint8_t x;
uint8_t y;
} position_t;
};
/**
* Parses command line arguments
* Provides default values for arguments that do not exist
*/
void parse_args(int argc, char *argv[], args_t *args);
void parse_args(int argc, char *argv[], args *args);
void print_args(args_t *args);
void print_args(args *args);
#endif
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