Exemplo n.º 1
0
int dogma_set_env_state(dogma_context_t* ctx, dogma_env_t* env, dogma_state_t newstate) {
	dogma_array_t enveffects;
	dogma_key_t index = 0;
	const dogma_type_effect_t** te;
	const dogma_effect_t* e;
	dogma_expctx_t result;

	if(env->state == newstate) return DOGMA_OK;

	DOGMA_ASSUME_OK(dogma_get_type_effects(env->id, &enveffects));
	JLF(te, enveffects, index);
	while(te != NULL) {
		DOGMA_ASSUME_OK(dogma_get_effect((*te)->effectid, &e));
		JLN(te, enveffects, index);

		if(e->fittingusagechanceattributeid > 0) {
			/* Effect is chance-based */

			if(newstate > 0) {
				continue;
			}

			/* When unplugging the environment, turn off all
			 * chance-based effects as a precautionary measure */
			bool* v;
			int ret;
			JLG(v, env->chance_effects, e->id);
			if(v != NULL) {
				assert(*v == true);
				JLD(ret, env->chance_effects, e->id);
				DOGMA_ASSUME_OK(dogma_eval_expression(
					ctx, env,
					e->postexpressionid,
					&result
				));
			}

			continue;
		}

		if((newstate >> e->category) & 1) {
			if(!((env->state >> e->category) & 1)) {
				DOGMA_ASSUME_OK(dogma_eval_expression(
					ctx, env,
					e->preexpressionid,
					&result
				));
			}
		} else if((env->state >> e->category) & 1) {
			DOGMA_ASSUME_OK(dogma_eval_expression(
				ctx, env,
				e->postexpressionid,
				&result
			));
		}
	}
Exemplo n.º 2
0
int dogma_set_ship(dogma_context_t* ctx, dogma_typeid_t ship_typeid) {
	if(ship_typeid == ctx->ship->id) {
		/* Be lazy */
		return DOGMA_OK;
	}

	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, ctx->ship, DOGMA_STATE_Unplugged));
	ctx->ship->id = ship_typeid;
	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, ctx->ship, DOGMA_STATE_Online));

	return DOGMA_OK;
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
static inline int dogma_remove_env_generic(dogma_context_t* ctx,
                                           dogma_env_t* location,
                                           dogma_key_t index) {
	dogma_env_t** env;
	int result;

	JLG(env, location->children, index);
	if(env == NULL) return DOGMA_NOT_FOUND;

	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, *env, DOGMA_STATE_Unplugged));

	dogma_free_env(ctx, *env);

	JLD(result, location->children, index);
	return DOGMA_OK;
}
Exemplo n.º 5
0
static inline int dogma_add_env_generic(dogma_context_t* ctx,
                                        dogma_env_t* location, dogma_context_t* owner,
                                        dogma_typeid_t id, dogma_key_t* index, dogma_state_t state) {
	dogma_env_t* new_env = malloc(sizeof(dogma_env_t));
	dogma_env_t** value;
	int result;

	JLFE(result, location->children, *index);
	JLI(value, location->children, *index);
	*value = new_env;

	DOGMA_INIT_ENV(new_env, id, location, *index, owner);
	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, new_env, state));

	return DOGMA_OK;
}
Exemplo n.º 6
0
int dogma_remove_drone(dogma_context_t* ctx, dogma_typeid_t droneid) {
	dogma_drone_context_t** value;
	dogma_env_t* drone_env;
	int ret;

	JLG(value, ctx->drone_map, droneid);
	if(value == NULL) return DOGMA_OK; /* Nonexistent drone */

	drone_env = (*value)->drone;
	DOGMA_ASSUME_OK(dogma_set_env_state(ctx, drone_env, DOGMA_STATE_Unplugged));

	dogma_free_env(ctx, drone_env);
	free(*value);

	JLD(ret, drone_env->parent->children, drone_env->index);
	JLD(ret, ctx->drone_map, droneid);

	return DOGMA_OK;
}
Exemplo n.º 7
0
int dogma_get_location_attribute(dogma_context_t* ctx, dogma_location_t location,
                                 dogma_attributeid_t attributeid, double* out) {
	dogma_env_t* loc_env;
	DOGMA_ASSUME_OK(dogma_get_location_env(ctx, location, &loc_env));
	return dogma_get_env_attribute(ctx, loc_env, attributeid, out);
}
Exemplo n.º 8
0
int dogma_clear_target(dogma_context_t* targeter, dogma_location_t loc) {
	dogma_env_t* targeter_env;

	DOGMA_ASSUME_OK(dogma_get_location_env(targeter, loc, &targeter_env));
	return dogma_set_target(targeter, targeter_env, NULL, NULL);
}
Exemplo n.º 9
0
int dogma_target(dogma_context_t* targeter, dogma_location_t loc, dogma_context_t* targetee) {
	dogma_env_t* targeter_env;

	DOGMA_ASSUME_OK(dogma_get_location_env(targeter, loc, &targeter_env));
	return dogma_set_target(targeter, targeter_env, targetee, targetee->ship);
}
Exemplo n.º 10
0
int dogma_toggle_chance_based_effect(dogma_context_t* ctx, dogma_location_t loc, dogma_effectid_t id, bool on) {
	dogma_env_t* loc_env;
	DOGMA_ASSUME_OK(dogma_get_location_env(ctx, loc, &loc_env));
	return dogma_toggle_chance_based_effect_env(ctx, loc_env, id, on);
}
Exemplo n.º 11
0
int dogma_add_module_sc(dogma_context_t* ctx, dogma_typeid_t id, dogma_key_t* index, dogma_state_t s, dogma_typeid_t charge) {
	DOGMA_ASSUME_OK(dogma_add_module(ctx, id, index));
	DOGMA_ASSUME_OK(dogma_set_module_state(ctx, *index, s));
	return dogma_add_charge(ctx, *index, charge);
}
Exemplo n.º 12
0
int dogma_free_env(dogma_context_t* ctx, dogma_env_t* env) {
	int ret;
	dogma_key_t index = -1, index2, index3;
	dogma_env_t** child;
	dogma_array_t* modifiers;
	dogma_array_t* modifiers2;
	dogma_modifier_t** modifier;

	/* Clear our own target */
	if(env->target.context != NULL) {
		assert(dogma_set_target(ctx, env, NULL, NULL) == DOGMA_OK);
	}

	/* Clear any targets of things that have what we're about do
	 * delete as a target */
	if(env->targeted_by != NULL) {
		dogma_key_t index = 0;
		dogma_context_t** targeter;
		dogma_env_t* source;

		JLF(targeter, env->targeted_by, index);
		while(targeter != NULL) {
			source = (dogma_env_t*)index;
			assert(dogma_set_target(*targeter, source, NULL, NULL) == DOGMA_OK);

			JLN(targeter, env->targeted_by, index);
		}

		JLC(ret, env->targeted_by, 0, -1);
		assert(ret == 0);
		JLFA(ret, env->targeted_by);
		assert(ret == 0);
	}

	/* Clear any chance-based effects */
	if(env->chance_effects != NULL) {
		dogma_key_t effectid = 0;
		bool* val;

		JLF(val, env->chance_effects, effectid);
		while(val != NULL) {
			DOGMA_ASSUME_OK(dogma_toggle_chance_based_effect_env(ctx, env, effectid, false));
			JLN(val, env->chance_effects, effectid);
		}

		JLFA(ret, env->chance_effects);
	}

	JLL(child, env->children, index);
	while(child != NULL) {
		dogma_free_env(ctx, *child);
		JLP(child, env->children, index);
	}
	JLFA(ret, env->children);

	index = 0;
	JLF(modifiers, env->modifiers, index);
	while(modifiers != NULL) {
		index2 = 0;
		JLF(modifiers2, *modifiers, index2);
		while(modifiers2 != NULL) {
			index3 = 0;
			JLF(modifier, *modifiers2, index3);
			while(modifier != NULL) {
				free(*modifier);
				JLN(modifier, *modifiers2, index3);
			}

			JLFA(ret, *modifiers2);
			JLN(modifiers2, *modifiers, index2);
		}

		JLFA(ret, *modifiers);
		JLN(modifiers, env->modifiers, index);
	}
	JLFA(ret, env->modifiers);

	free(env);

	return DOGMA_OK;
}