示例#1
0
文件: dogma.c 项目: bastianh/libdogma
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);
}
示例#2
0
文件: dogma.c 项目: bastianh/libdogma
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);
}
示例#3
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;
}