int dogma_free_context(dogma_context_t* ctx) { dogma_drone_context_t** value; dogma_key_t index = 0; int ret; if(ctx->fleet != NULL) { bool found; DOGMA_ASSUME_OK(dogma_remove_fleet_member(ctx->fleet, ctx, &found)); assert(found == true && ctx->fleet == NULL); } dogma_free_env(ctx, ctx->character); dogma_free_env(ctx, ctx->gang); dogma_reset_skill_levels(ctx); JLF(value, ctx->drone_map, index); while(value != NULL) { /* The drone environments were freed when char was freed */ free(*value); JLN(value, ctx->drone_map, index); } JLFA(ret, ctx->drone_map); free(ctx); return DOGMA_OK; }
int main(void) { dogma_context_t* ctx; double value; assert(dogma_init() == DOGMA_OK); assert(dogma_init_context(&ctx) == DOGMA_OK); assert(dogma_set_ship(ctx, TYPE_Harbinger) == DOGMA_OK); assert(dogma_get_ship_attribute(ctx, ATT_PowerOutput, &value) == DOGMA_OK); assertf(value, HARB_BasePG * 1.25, EPS); assert(dogma_get_ship_attribute(ctx, ATT_CpuOutput, &value) == DOGMA_OK); assertf(value, HARB_BaseCPU * 1.25, EPS); assert(dogma_set_default_skill_level(ctx, 1) == DOGMA_OK); assert(dogma_get_ship_attribute(ctx, ATT_PowerOutput, &value) == DOGMA_OK); assertf(value, HARB_BasePG * 1.05, EPS); assert(dogma_get_ship_attribute(ctx, ATT_CpuOutput, &value) == DOGMA_OK); assertf(value, HARB_BaseCPU * 1.05, EPS); assert(dogma_set_skill_level(ctx, TYPE_CPUManagement, 4) == DOGMA_OK); assert(dogma_set_skill_level(ctx, TYPE_PowerGridManagement, 0) == DOGMA_OK); assert(dogma_get_ship_attribute(ctx, ATT_PowerOutput, &value) == DOGMA_OK); assertf(value, HARB_BasePG, EPS); assert(dogma_get_ship_attribute(ctx, ATT_CpuOutput, &value) == DOGMA_OK); assertf(value, HARB_BaseCPU * 1.20, EPS); assert(dogma_set_default_skill_level(ctx, 5) == DOGMA_OK); assert(dogma_reset_skill_levels(ctx) == DOGMA_OK); assert(dogma_get_ship_attribute(ctx, ATT_PowerOutput, &value) == DOGMA_OK); assertf(value, HARB_BasePG * 1.25, EPS); assert(dogma_get_ship_attribute(ctx, ATT_CpuOutput, &value) == DOGMA_OK); assertf(value, HARB_BaseCPU * 1.25, EPS); assert(dogma_free_context(ctx) == DOGMA_OK); return 0; }