// __ ___ _ _ __ __ _ ___ ___ _ __ // \ \/ / | | | '_ \ / _` |/ _ \/ _ \| '_ \ // > <| |_| | | | | (_| | __/ (_) | | | | // /_/\_\\__,_|_| |_|\__, |\___|\___/|_| |_| // |___/ // // Copyright (c) 1997 - Ognjen 'xolatile' Milan Robovic // // xolatile@chud.cyou - xungeon - Small library for defining dungeon crawler gameplay information. // // This program is free software, free as in freedom and as in free beer, you can redistribute it and/or modify it under the terms of the GNU // General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version if you wish... // // This program is distributed in the hope that it will be useful, but it is probably not, and without any warranty, without even the implied // warranty of merchantability or fitness for a particular purpose, because it is pointless. Please see the GNU (Geenoo) General Public License // for more details, if you dare, it is a lot of text that nobody wants to read... //~typedef struct { //~char * name; //~} * _definition; typedef struct { char * name; // Name string copy. uint temperature; // ; uint humidity; // ; } * dungeon_biome_definition; typedef struct { char * name; // Name string copy. uint biome; // Index in biome array. bool clip; // Can entities move through? } * dungeon_landmark_definition; typedef struct { char * name; // Name string copy. } * dungeon_expertise_definition; typedef struct { char * name; // Name string copy. uint base; // Default amount of points per entity. uint limit; // After this point, points won't increase. } * dungeon_attribute_definition; typedef struct { char * name; // Name string copy. uint base; // Default amount of points per entity. uint limit; // After this point, points won't increase. } * dungeon_skill_definition; typedef struct { char * name; // Name string copy. uint base; // Default amount of points per entity. uint limit; // After this point, points won't increase. uint value; // Constant trade value per index 0. uint trade; // Trade rate for acquiring the resource. } * dungeon_resource_definition; typedef struct { char * name; // Name string copy. } * dungeon_item_slot_definition; typedef struct { char * name; // Name string copy. uint slot; // Index in item slot array. uint effect; // Index in effect array. } * dungeon_item_definition; typedef struct { uint biome_count; uint landmark_count; uint expertise_count; uint attribute_count; uint skill_count; uint resource_count; uint item_slot_count; uint item_count; dungeon_biome_definition * biome_array; dungeon_landmark_definition * landmark_array; dungeon_expertise_definition * expertise_array; dungeon_attribute_definition * attribute_array; dungeon_skill_definition * skill_array; dungeon_resource_definition * resource_array; dungeon_item_slot_definition * item_slot_array; dungeon_item_definition * item_array; } * dungeon_structure; static uint dungeon_biome_define (dungeon_structure dungeon, char * name, uint temperature, uint humidity) { dungeon_biome_definition biome = arena_add (sizeof (* biome)); fatal_failure (dungeon == null, "biome_define: Dungeon is not configured."); fatal_failure (name == null, "biome_define: Name is null pointer."); string_copy ((biome->name = arena_add ((string_length (name) + 1) * sizeof (* biome->name))), name); biome->temperature = temperature; biome->humidity = humidity; dungeon->biome_count += 1; dungeon->biome_array [dungeon->biome_count - 1] = biome; return (dungeon->biome_count - 1); } static char * dungeon_biome_name (dungeon_structure dungeon, uint index) { return (dungeon->biome_array [index]->name); } static uint dungeon_biome_temperature (dungeon_structure dungeon, uint index) { return (dungeon->biome_array [index]->temperature); } static uint dungeon_biome_humidity (dungeon_structure dungeon, uint index) { return (dungeon->biome_array [index]->humidity); } static uint dungeon_landmark_define (dungeon_structure dungeon, char * name, uint biome, bool clip) { dungeon_landmark_definition landmark = arena_add (sizeof (* landmark)); fatal_failure (dungeon == null, "landmark_define: Dungeon is not configured."); fatal_failure (name == null, "landmark_define: Name is null pointer."); string_copy ((landmark->name = arena_add ((string_length (name) + 1) * sizeof (* landmark->name))), name); landmark->biome = biome; landmark->clip = clip; dungeon->landmark_count += 1; dungeon->landmark_array [dungeon->landmark_count - 1] = landmark; return (dungeon->landmark_count - 1); } static char * dungeon_landmark_name (dungeon_structure dungeon, uint index) { return (dungeon->landmark_array [index]->name); } static uint dungeon_landmark_biome (dungeon_structure dungeon, uint index) { return (dungeon->landmark_array [index]->biome); } static bool dungeon_landmark_clip (dungeon_structure dungeon, uint index) { return (dungeon->landmark_array [index]->clip); } static uint dungeon_expertise_define (dungeon_structure dungeon, char * name) { dungeon_expertise_definition expertise = arena_add (sizeof (* expertise)); fatal_failure (dungeon == null, "expertise_define: Dungeon is not configured."); fatal_failure (name == null, "expertise_define: Name is null pointer."); string_copy ((expertise->name = arena_add ((string_length (name) + 1) * sizeof (* expertise->name))), name); dungeon->expertise_count += 1; dungeon->expertise_array [dungeon->expertise_count - 1] = expertise; return (dungeon->expertise_count - 1); } static char * dungeon_expertise_name (dungeon_structure dungeon, uint index) { return (dungeon->expertise_array [index]->name); } static uint dungeon_attribute_define (dungeon_structure dungeon, char * name, uint base, uint limit) { dungeon_attribute_definition attribute = arena_add (sizeof (* attribute)); fatal_failure (dungeon == null, "attribute_define: Dungeon is not configured."); fatal_failure (name == null, "attribute_define: Name is null pointer."); string_copy ((attribute->name = arena_add ((string_length (name) + 1) * sizeof (* attribute->name))), name); attribute->base = base; attribute->limit = limit; dungeon->attribute_count += 1; dungeon->attribute_array [dungeon->attribute_count - 1] = attribute; return (dungeon->attribute_count - 1); } static char * dungeon_attribute_name (dungeon_structure dungeon, uint index) { return (dungeon->attribute_array [index]->name); } static uint dungeon_attribute_base (dungeon_structure dungeon, uint index) { return (dungeon->attribute_array [index]->base); } static uint dungeon_attribute_limit (dungeon_structure dungeon, uint index) { return (dungeon->attribute_array [index]->limit); } static uint dungeon_skill_define (dungeon_structure dungeon, char * name, uint base, uint limit) { dungeon_skill_definition skill = arena_add (sizeof (* skill)); fatal_failure (dungeon == null, "skill_define: Dungeon is not configured."); fatal_failure (name == null, "skill_define: Name is null pointer."); string_copy ((skill->name = arena_add ((string_length (name) + 1) * sizeof (* skill->name))), name); skill->base = base; skill->limit = limit; dungeon->skill_count += 1; dungeon->skill_array [dungeon->skill_count - 1] = skill; return (dungeon->skill_count - 1); } static char * dungeon_skill_name (dungeon_structure dungeon, uint index) { return (dungeon->skill_array [index]->name); } static uint dungeon_skill_base (dungeon_structure dungeon, uint index) { return (dungeon->skill_array [index]->base); } static uint dungeon_skill_limit (dungeon_structure dungeon, uint index) { return (dungeon->skill_array [index]->limit); } static uint dungeon_resource_define (dungeon_structure dungeon, char * name, uint base, uint limit, uint value, uint trade) { dungeon_resource_definition resource = arena_add (sizeof (* resource)); fatal_failure (dungeon == null, "resource_define: Dungeon is not configured."); fatal_failure (name == null, "resource_define: Name is null pointer."); string_copy ((resource->name = arena_add ((string_length (name) + 1) * sizeof (* resource->name))), name); resource->base = base; resource->limit = limit; resource->value = value; resource->trade = trade; dungeon->resource_count += 1; dungeon->resource_array [dungeon->resource_count - 1] = resource; return (dungeon->resource_count - 1); } static char * dungeon_resource_name (dungeon_structure dungeon, uint index) { return (dungeon->resource_array [index]->name); } static uint dungeon_resource_base (dungeon_structure dungeon, uint index) { return (dungeon->resource_array [index]->base); } static uint dungeon_resource_limit (dungeon_structure dungeon, uint index) { return (dungeon->resource_array [index]->limit); } static uint dungeon_resource_value (dungeon_structure dungeon, uint index) { return (dungeon->resource_array [index]->value); } static uint dungeon_resource_trade (dungeon_structure dungeon, uint index) { return (dungeon->resource_array [index]->trade); } static uint dungeon_item_slot_define (dungeon_structure dungeon, char * name) { dungeon_item_slot_definition item_slot = arena_add (sizeof (* item_slot)); fatal_failure (dungeon == null, "item_slot_define: Dungeon is not configured."); fatal_failure (name == null, "item_slot_define: Name is null pointer."); string_copy ((item_slot->name = arena_add ((string_length (name) + 1) * sizeof (* item_slot->name))), name); dungeon->item_slot_count += 1; dungeon->item_slot_array [dungeon->item_slot_count - 1] = item_slot; return (dungeon->item_slot_count - 1); } static char * dungeon_item_slot_name (dungeon_structure dungeon, uint index) { return (dungeon->item_slot_array [index]->name); } static uint dungeon_item_define (dungeon_structure dungeon, char * name, uint slot, uint effect) { dungeon_item_definition item = arena_add (sizeof (* item)); fatal_failure (dungeon == null, "item_define: Dungeon is not configured."); fatal_failure (name == null, "item_define: Name is null pointer."); string_copy ((item->name = arena_add ((string_length (name) + 1) * sizeof (* item->name))), name); item->slot = slot; item->effect = effect; dungeon->item_count += 1; dungeon->item_array [dungeon->item_count - 1] = item; return (dungeon->item_count - 1); } static char * dungeon_item_name (dungeon_structure dungeon, uint index) { return (dungeon->item_array [index]->name); } static uint dungeon_item_slot (dungeon_structure dungeon, uint index) { return (dungeon->item_array [index]->slot); } static uint dungeon_item_effect (dungeon_structure dungeon, uint index) { return (dungeon->item_array [index]->effect); } static dungeon_structure dungeon_configure (uint biome_limit, uint landmark_limit, uint expertise_limit, uint attribute_limit, uint skill_limit, uint resource_limit, uint item_slot_limit, uint item_limit) { dungeon_structure dungeon = arena_add (sizeof (* dungeon)); dungeon->biome_array = arena_add (biome_limit * sizeof (* dungeon->biome_array)); dungeon->landmark_array = arena_add (landmark_limit * sizeof (* dungeon->landmark_array)); dungeon->expertise_array = arena_add (expertise_limit * sizeof (* dungeon->expertise_array)); dungeon->attribute_array = arena_add (attribute_limit * sizeof (* dungeon->attribute_array)); dungeon->skill_array = arena_add (skill_limit * sizeof (* dungeon->skill_array)); dungeon->resource_array = arena_add (resource_limit * sizeof (* dungeon->resource_array)); dungeon->item_slot_array = arena_add (item_slot_limit * sizeof (* dungeon->item_slot_array)); dungeon->item_array = arena_add (item_limit * sizeof (* dungeon->item_array)); return (dungeon); }