X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;f=src%2Froguelike.c;h=04da8a654799397ccdf031d499136ba21db36340;hb=867fe8e2358c8d71919b144f97e4ab272b8f4ebe;hp=37e90c96ac8b766849de77895d1d4e91b3807cba;hpb=bbea8aaa3fa48f00ea46a7d8d79138e02929881e;p=plomrogue
diff --git a/src/roguelike.c b/src/roguelike.c
index 37e90c9..04da8a6 100644
--- a/src/roguelike.c
+++ b/src/roguelike.c
@@ -96,18 +96,14 @@ void save_game(struct World * world) {
write_uint32_bigendian(world->turn, file);
write_uint16_bigendian(world->player->pos.y, file);
write_uint16_bigendian(world->player->pos.x, file);
- write_uint16_bigendian(world->monster->pos.y, file);
- write_uint16_bigendian(world->monster->pos.x, file);
- write_uint16_bigendian(world->monster->next->pos.y, file);
- write_uint16_bigendian(world->monster->next->pos.x, file);
- write_uint16_bigendian(world->monster->next->next->pos.y, file);
- write_uint16_bigendian(world->monster->next->next->pos.x, file);
- write_uint16_bigendian(world->item->pos.y, file);
- write_uint16_bigendian(world->item->pos.x, file);
- write_uint16_bigendian(world->item->next->pos.y, file);
- write_uint16_bigendian(world->item->next->pos.x, file);
- write_uint16_bigendian(world->item->next->next->pos.y, file);
- write_uint16_bigendian(world->item->next->next->pos.x, file);
+ struct Monster * monster;
+ for (monster = world->monster; monster != 0; monster = monster->next) {
+ write_uint16_bigendian(monster->pos.y, file);
+ write_uint16_bigendian(monster->pos.x, file); }
+ struct Item * item;
+ for (item = world->item; item != 0; item = item->next) {
+ write_uint16_bigendian(item->pos.y, file);
+ write_uint16_bigendian(item->pos.x, file); }
fclose(file); }
void toggle_window (struct WinMeta * win_meta, struct Win * win) {
@@ -208,26 +204,23 @@ int main (int argc, char *argv[]) {
update_log (&world, " ");
struct Player player;
world.player = &player;
- struct Monster monster1;
- struct Monster monster2;
- struct Monster monster3;
- world.monster = &monster1;
- monster1.next = &monster2;
- monster2.next = &monster3;
- monster3.next = 0;
- monster1.name = 'A';
- monster2.name = 'B';
- monster3.name = 'C';
- struct Item item1;
- struct Item item2;
- struct Item item3;
- world.item = &item1;
- item1.next = &item2;
- item2.next = &item3;
- item3.next = 0;
- item1.name = '&';
- item2.name = '%';
- item3.name = '#';
+ char i;
+ struct Monster * monster = malloc(sizeof(struct Monster));
+ world.monster = monster;
+ for (i = 0; i < 2; i++) {
+ monster->name = 'M';
+ monster->next = malloc(sizeof(struct Monster));
+ monster = monster->next; }
+ monster->name = 'M';
+ monster->next = 0;
+ struct Item * item = malloc(sizeof(struct Item));
+ world.item = item;
+ for (i = 0; i < 2; i++) {
+ item->name = '#';
+ item->next = malloc(sizeof(struct Item));
+ item = item->next; }
+ item->name = '#';
+ item->next = 0;
// For interactive mode, try to load world state from savefile.
FILE * file;
@@ -237,18 +230,12 @@ int main (int argc, char *argv[]) {
world.turn = read_uint32_bigendian(file);
player.pos.y = read_uint16_bigendian(file);
player.pos.x = read_uint16_bigendian(file);
- monster1.pos.y = read_uint16_bigendian(file);
- monster1.pos.x = read_uint16_bigendian(file);
- monster2.pos.y = read_uint16_bigendian(file);
- monster2.pos.x = read_uint16_bigendian(file);
- monster3.pos.y = read_uint16_bigendian(file);
- monster3.pos.x = read_uint16_bigendian(file);
- item1.pos.y = read_uint16_bigendian(file);
- item1.pos.x = read_uint16_bigendian(file);
- item2.pos.y = read_uint16_bigendian(file);
- item2.pos.x = read_uint16_bigendian(file);
- item3.pos.y = read_uint16_bigendian(file);
- item3.pos.x = read_uint16_bigendian(file);
+ for (monster = world.monster; monster != 0; monster = monster->next) {
+ monster->pos.y = read_uint16_bigendian(file);
+ monster->pos.x = read_uint16_bigendian(file); }
+ for (item = world.item; item != 0; item = item->next) {
+ item->pos.y = read_uint16_bigendian(file);
+ item->pos.x = read_uint16_bigendian(file); }
fclose(file); }
// For non-interactive mode, try to load world state from frecord file.
@@ -273,12 +260,10 @@ int main (int argc, char *argv[]) {
for (player.pos.y = player.pos.x = 0; 0 == is_passable(&map, player.pos);) {
player.pos.y = rrand(0, 0) % map.size.y;
player.pos.x = rrand(0, 0) % map.size.x; }
- struct Item * item;
for (item = world.item; item != 0; item = item->next)
for (item->pos.y = item->pos.x = 0; 0 == is_passable(&map, item->pos);) {
item->pos.y = rrand(0, 0) % map.size.y;
item->pos.x = rrand(0, 0) % map.size.x; }
- struct Monster * monster;
for (monster = world.monster; monster != 0; monster = monster->next)
for (monster->pos.y = monster->pos.x = 0; 0 == is_passable(&map, monster->pos);) {
monster->pos.y = rrand(0, 0) % map.size.y;