int main(void) {
	dogma_context_t *ctxA, *ctxB, *ctxC;
	dogma_key_t slots[30];
	double v;

	dogma_init();
	dogma_init_context(&ctxA);
	dogma_init_context(&ctxB);
	dogma_init_context(&ctxC);

	/* In this test, we have a Rifter with one autocannon and tracking
	 * enhancers. It is being targeted by another Rifter, and a
	 * Scimitar each with the maximum number of tracking links. */

	dogma_set_ship(ctxA, TYPE_Rifter);
	dogma_add_module_sc(ctxA, TYPE_125mmGatlingAutoCannonII, &slots[0], DOGMA_STATE_Active, TYPE_BarrageS);
	dogma_add_module_s(ctxA, TYPE_TrackingEnhancerII, &slots[1], DOGMA_STATE_Online);
	dogma_add_module_s(ctxA, TYPE_TrackingEnhancerII, &slots[2], DOGMA_STATE_Online);
	dogma_add_module_s(ctxA, TYPE_TrackingEnhancerII, &slots[3], DOGMA_STATE_Online);

	/* Source: Pyfa-42efa48 (Jun 13 2013) */

	dogma_get_module_attribute(ctxA, slots[0], ATT_TrackingSpeed, &v);
	assertf(0.671744203407, v, 0.0000000000005);

	dogma_set_ship(ctxB, TYPE_Rifter);
	dogma_add_module_s(ctxB, TYPE_RemoteTrackingComputerII, &slots[10], DOGMA_STATE_Active);
	dogma_add_module_s(ctxB, TYPE_RemoteTrackingComputerII, &slots[11], DOGMA_STATE_Active);
	dogma_add_module_s(ctxB, TYPE_RemoteTrackingComputerII, &slots[12], DOGMA_STATE_Active);
	dogma_target(ctxB, (dogma_location_t){ .type = DOGMA_LOC_Module, .module_index = slots[10] }, ctxA);
int main(void) {
	dogma_context_t* ctx;
	dogma_key_t k;
	double v0, v1;

	assert(dogma_init() == DOGMA_OK);
	assert(dogma_init_context(&ctx) == DOGMA_OK);

	assert(dogma_set_ship(ctx, TYPE_Confessor) == DOGMA_OK);

	assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &v0) == DOGMA_OK);
	assert(dogma_add_module_s(ctx, TYPE_ConfessorPropulsionMode, &k, DOGMA_STATE_Online) == DOGMA_OK);
	assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &v1) == DOGMA_OK);

	printf("%f %f\n", v0, v1);
	
	assert(v1 > v0);

	assert(dogma_free_context(ctx) == DOGMA_OK);
	return 0;
}
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;
}
Exemple #4
0
int main(void) {
	double v;

	dogma_init();
	dogma_init_context(&ctx);

	/* Source: Pyfa-a4d72ca (Oct 7 2013) */

	/* Let's test a whole implant set (which has bonuses affecting the
	 * set as a whole), and see how it reacts with stacking penalized
	 * modules. */

	dogma_add_implant(ctx, TYPE_HighgradeCrystalAlpha, &impslot0);
	dogma_add_implant(ctx, TYPE_HighgradeCrystalBeta, &impslot1);
	dogma_add_implant(ctx, TYPE_HighgradeCrystalGamma, &impslot2);
	dogma_add_implant(ctx, TYPE_HighgradeCrystalDelta, &impslot3);
	dogma_add_implant(ctx, TYPE_HighgradeCrystalEpsilon, &impslot4);
	dogma_add_implant(ctx, TYPE_HighgradeCrystalOmega, &impslot5);

	dogma_set_ship(ctx, TYPE_Venture);
	dogma_add_module(ctx, TYPE_SmallShieldBoosterII, &slot0);
	dogma_add_module(ctx, TYPE_ShieldBoostAmplifierII, &slot1);
	dogma_add_module(ctx, TYPE_ShieldBoostAmplifierII, &slot2);
	dogma_set_module_state(ctx, slot0, DOGMA_STATE_Active);
	dogma_set_module_state(ctx, slot1, DOGMA_STATE_Online);
	dogma_set_module_state(ctx, slot2, DOGMA_STATE_Online);

	dogma_get_module_attribute(ctx, slot0, ATT_ShieldBonus, &v);
	assertf(96.0105996145, v, 0.0000000005);

	dogma_free_context(ctx);
	dogma_init_context(&ctx);

	/* Source: Pyfa-42efa48 (Jun 13 2013) */
	/* Source: EFT 2.19.1 */

	/* Some sources say the Snake set is stacking penalized. This is
	 * not the case (unless both Pyfa and EFT are wrong). */

	dogma_add_implant(ctx, TYPE_HighgradeSnakeAlpha, &impslot0);
	dogma_add_implant(ctx, TYPE_HighgradeSnakeBeta, &impslot1);
	dogma_add_implant(ctx, TYPE_HighgradeSnakeGamma, &impslot2);
	dogma_add_implant(ctx, TYPE_HighgradeSnakeDelta, &impslot3);
	dogma_add_implant(ctx, TYPE_HighgradeSnakeEpsilon, &impslot4);
	dogma_add_implant(ctx, TYPE_HighgradeSnakeOmega, &impslot5);

	dogma_set_ship(ctx, TYPE_Venture);
	dogma_add_module(ctx, TYPE_OverdriveInjectorSystemII, &slot0);
	dogma_add_module(ctx, TYPE_SmallPolycarbonEngineHousingI, &slot1);
	dogma_add_module(ctx, TYPE_SmallPolycarbonEngineHousingI, &slot2);
	dogma_add_module(ctx, TYPE_SmallPolycarbonEngineHousingI, &slot3);
	dogma_set_module_state(ctx, slot0, DOGMA_STATE_Online);
	dogma_set_module_state(ctx, slot1, DOGMA_STATE_Online);
	dogma_set_module_state(ctx, slot2, DOGMA_STATE_Online);
	dogma_set_module_state(ctx, slot3, DOGMA_STATE_Online);

	dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &v);
	assertf(644.929066501, v, 0.0000000005);

	dogma_free_context(ctx);
	dogma_init_context(&ctx);

	/* Source: EFT 2.20.3 */

	dogma_add_implant(ctx, TYPE_StrongBluePillBooster, &impslot0);

	dogma_set_ship(ctx, TYPE_Venture);
	dogma_add_module(ctx, TYPE_SmallShieldBoosterII, &slot0);
	dogma_set_module_state(ctx, slot0, DOGMA_STATE_Active);

	const dogma_location_t imploc0 = {
		.type = DOGMA_LOC_Implant,
		.implant_index = impslot0,
	};

	dogma_get_chance_based_effect_chance(ctx, imploc0, EFFECT_BoosterShieldCapacityPenalty, &v);
	assertf(0.3, v, 0.05);
	dogma_get_chance_based_effect_chance(ctx, imploc0, EFFECT_BoosterCapacitorCapacityPenalty, &v);
	assertf(0.3, v, 0.05);

	dogma_get_module_attribute(ctx, slot0, ATT_ShieldBonus, &v);
	assertf(45.5, v, 0.5);
	dogma_get_ship_attribute(ctx, ATT_ShieldCapacity, &v);
	assertf(281.25, v, 0.005);
	dogma_get_ship_attribute(ctx, ATT_CapacitorCapacity, &v);
	assertf(312.5, v, 0.05);

	dogma_toggle_chance_based_effect(ctx, imploc0, EFFECT_BoosterShieldCapacityPenalty, true);

	dogma_get_module_attribute(ctx, slot0, ATT_ShieldBonus, &v);
	assertf(45.5, v, 0.5);
	dogma_get_ship_attribute(ctx, ATT_ShieldCapacity, &v);
	assertf(217.96875, v, 0.000005);
	dogma_get_ship_attribute(ctx, ATT_CapacitorCapacity, &v);
	assertf(312.5, v, 0.05);

	dogma_toggle_chance_based_effect(ctx, imploc0, EFFECT_BoosterCapacitorCapacityPenalty, true);

	dogma_get_module_attribute(ctx, slot0, ATT_ShieldBonus, &v);
	assertf(45.5, v, 0.5);
	dogma_get_ship_attribute(ctx, ATT_ShieldCapacity, &v);
	assertf(217.96875, v, 0.000005);
	dogma_get_ship_attribute(ctx, ATT_CapacitorCapacity, &v);
	assertf(242.1875, v, 0.00005);

	dogma_toggle_chance_based_effect(ctx, imploc0, EFFECT_BoosterShieldCapacityPenalty, false);

	dogma_get_module_attribute(ctx, slot0, ATT_ShieldBonus, &v);
	assertf(45.5, v, 0.5);
	dogma_get_ship_attribute(ctx, ATT_ShieldCapacity, &v);
	assertf(281.25, v, 0.005);
	dogma_get_ship_attribute(ctx, ATT_CapacitorCapacity, &v);
	assertf(242.1875, v, 0.00005);

	dogma_toggle_chance_based_effect(ctx, imploc0, EFFECT_BoosterCapacitorCapacityPenalty, false);

	dogma_get_module_attribute(ctx, slot0, ATT_ShieldBonus, &v);
	assertf(45.5, v, 0.5);
	dogma_get_ship_attribute(ctx, ATT_ShieldCapacity, &v);
	assertf(281.25, v, 0.005);
	dogma_get_ship_attribute(ctx, ATT_CapacitorCapacity, &v);
	assertf(312.5, v, 0.05);

	dogma_free_context(ctx);
	return 0;
}
int main(void) {
	dogma_key_t slots[20];
	dogma_context_t* ctx[4];
	double delta, s;
	bool stable;

	dogma_init();

	/* Initialize two sets of two rifters, each using two energy
	 * transferrers on the other: this creates two independent "loops"
	 * of two ships each. */

	for(size_t i = 0; i < 4; ++i) {
		dogma_init_context(ctx + i);
		dogma_set_ship(ctx[i], TYPE_Rifter);
		dogma_add_module_s(ctx[i], TYPE_SmallRemoteCapacitorTransmitterII, slots + 5 * i, DOGMA_STATE_Active);
		dogma_add_module_s(ctx[i], TYPE_SmallRemoteCapacitorTransmitterII, slots + 5 * i + 1, DOGMA_STATE_Active);
		dogma_add_module_s(ctx[i], TYPE_SmallCapBatteryII, slots + 5 * i + 4, DOGMA_STATE_Online);
	}

	dogma_target(ctx[0], MOD(0), ctx[1]);
	dogma_target(ctx[0], MOD(1), ctx[1]);
	dogma_target(ctx[1], MOD(5), ctx[0]);
	dogma_target(ctx[1], MOD(6), ctx[0]);

	dogma_target(ctx[2], MOD(10), ctx[3]);
	dogma_target(ctx[2], MOD(11), ctx[3]);
	dogma_target(ctx[3], MOD(15), ctx[2]);
	dogma_target(ctx[3], MOD(16), ctx[2]);

	for(size_t i = 0; i < 4; ++i) {
		/* Source: Pyfa-96bb1b1 (2013-07-30) for the delta numbers,
		 * common sense for the stability */
		assert(dogma_get_capacitor(ctx[i], true, &delta, &stable, &s) == DOGMA_OK);
		assert(stable == true);
		assertf(2 * (6.15 - 7.80) - 11.8, 1000 * delta, 0.1);
	}

	/* Now equip neutralizers on the first set of rifters, and project
	 * them on the other set. Equip nosferatus on teh other set and
	 * project them on the first set. */

	dogma_add_module_s(ctx[0], TYPE_SmallEnergyNeutralizerII, slots + 2, DOGMA_STATE_Active);
	dogma_add_module_s(ctx[0], TYPE_SmallEnergyNeutralizerII, slots + 3, DOGMA_STATE_Active);
	dogma_add_module_s(ctx[1], TYPE_SmallEnergyNeutralizerII, slots + 7, DOGMA_STATE_Active);
	dogma_add_module_s(ctx[1], TYPE_SmallEnergyNeutralizerII, slots + 8, DOGMA_STATE_Active);
	dogma_target(ctx[0], MOD(2), ctx[2]);
	dogma_target(ctx[0], MOD(3), ctx[3]);
	dogma_target(ctx[1], MOD(7), ctx[2]);
	dogma_target(ctx[1], MOD(8), ctx[3]);

	dogma_add_module_s(ctx[2], TYPE_SmallEnergyNosferatuII, slots + 12, DOGMA_STATE_Active);
	dogma_add_module_s(ctx[2], TYPE_SmallEnergyNosferatuII, slots + 13, DOGMA_STATE_Active);
	dogma_add_module_s(ctx[3], TYPE_SmallEnergyNosferatuII, slots + 17, DOGMA_STATE_Active);
	dogma_add_module_s(ctx[3], TYPE_SmallEnergyNosferatuII, slots + 18, DOGMA_STATE_Active);
	dogma_target(ctx[2], MOD(12), ctx[0]);
	dogma_target(ctx[2], MOD(13), ctx[1]);
	dogma_target(ctx[3], MOD(17), ctx[0]);
	dogma_target(ctx[3], MOD(18), ctx[1]);

	dogma_simple_capacitor_t* list;
	size_t len;

	for(size_t i = 0; i < 4; ++i) {
		assert(dogma_get_capacitor_all(ctx[i], true, &list, &len) == DOGMA_OK);
		assert(len == 4);

		for(size_t j = 0; j < len; ++j) {
			printf(
				"context:%p\tstable:%i\tcapacity:%f\tdelta:%f\ts:%f\n",
				(void*)(list[j].context),
				list[j].stable,
				list[j].capacity,
				list[j].delta,
				list[j].stable ? list[j].stable_fraction : list[j].depletion_time
			);
		}

		dogma_free_capacitor_list(list);
	}

	for(size_t i = 0; i < 4; ++i) {
		dogma_free_context(ctx[i]);
	}



	dogma_init_context(&ctx[0]);
	dogma_init_context(&ctx[1]);

	dogma_set_ship(ctx[0], TYPE_Dominix);
	dogma_set_ship(ctx[1], TYPE_Guardian);
	dogma_add_module_s(ctx[1], TYPE_LargeRemoteArmorRepairerII, &slots[0], DOGMA_STATE_Active);
	dogma_target(ctx[1], MOD(0) ,ctx[0]);

	assert(dogma_get_capacitor_all(ctx[0], true, &list, &len) == DOGMA_OK);
	dogma_free_capacitor_list(list);
	assert(dogma_get_capacitor_all(ctx[1], true, &list, &len) == DOGMA_OK);
	dogma_free_capacitor_list(list);

	dogma_free_context(ctx[0]);
	dogma_free_context(ctx[1]);



	dogma_init_context(&ctx[0]);
	dogma_init_context(&ctx[1]);

	dogma_set_ship(ctx[0], TYPE_Dominix);
	dogma_set_ship(ctx[1], TYPE_Dominix);

	dogma_add_module_s(ctx[0], TYPE_HeavyEnergyNeutralizerII, &slots[0], DOGMA_STATE_Active);
	dogma_add_module_s(ctx[0], TYPE_HeavyEnergyNosferatuII, &slots[1], DOGMA_STATE_Active);
	dogma_target(ctx[0], MOD(0), ctx[1]);
	dogma_target(ctx[0], MOD(1), ctx[1]);

	size_t len1, len2;
	dogma_simple_capacitor_t *list1, *list2;

	assert(dogma_get_capacitor_all(ctx[0], true, &list1, &len1) == DOGMA_OK);
	assert(dogma_get_capacitor_all(ctx[1], true, &list2, &len2) == DOGMA_OK);

	/* Test overall equality of result sets */
	assert(len1 == len2);
	size_t tested = 0;

	for(size_t i = 0; i < len1; ++i) {
		for(size_t j = 0; j < len1; ++j) {
			dogma_simple_capacitor_t *p1, *p2;
			p1 = list1 + i;
			p2 = list2 + j;

			if(p1->context != p2->context) continue;

			assert(fabs(p1->capacity - p2->capacity) < 1e-300);
			assert(fabs(p1->delta - p2->delta) < 1e-300);
			assert(p1->stable == p2->stable);
			assert((p1->stable_fraction - p2->stable_fraction) < 1e-300);

			++tested;
		}
	}

	assert(tested == len1);

	dogma_free_capacitor_list(list1);
	dogma_free_capacitor_list(list2);
	dogma_free_context(ctx[0]);
	dogma_free_context(ctx[1]);

	return 0;
}