area.c (999B)
1 #include "game/area.h" 2 3 #include "engine/area.h" 4 #include "game/content.h" 5 6 #define LEN(a) (sizeof(a) / sizeof(0[a])) 7 8 int 9 ph_game_world_init(PhWorld *world, float viewport_w, float viewport_h) 10 { 11 PhArea area; 12 int player = -1; 13 size_t i; 14 15 if (ph_area_catalog_load(&area, &ph_area_catalog, PH_START_AREA) < 0) 16 return -1; 17 ph_world_init(world, area, PH_START_AREA, viewport_w, viewport_h); 18 for (i = 0; i < LEN(ph_entity_defs); ++i) 19 if (ph_world_add_entity_def(world, ph_entity_defs[i]) < 0) goto fail; 20 for (i = 0; i < LEN(ph_item_defs); ++i) 21 if (ph_world_add_item_def(world, ph_item_defs[i]) < 0) goto fail; 22 if (ph_world_prepare_area(world, &world->area, &ph_area_catalog, 23 PH_START_AREA, &player) < 0 || player < 0) goto fail; 24 for (i = 0; i < LEN(ph_player_equipment); ++i) 25 if (ph_player_equipment[i] && 26 ph_world_equip_item(world, player, ph_player_equipment[i]) < 0) 27 goto fail; 28 ph_world_set_player(world, player); 29 return 0; 30 31 fail: 32 ph_area_free(&world->area); 33 return -1; 34 }