Skip to content
This repository was archived by the owner on Oct 30, 2020. It is now read-only.

Commit 493a7c9

Browse files
committed
Refactor expression generation, handwrite AB/MWD expressions.
1 parent a342e2c commit 493a7c9

File tree

3 files changed

+176
-47
lines changed

3 files changed

+176
-47
lines changed

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ libdogmactl_SOURCES=src/ctl/main.c
2222

2323
check_PROGRAMS=test/trivial test/basic-attributes \
2424
test/basic-skill-levels test/basic-charges test/basic-fleet \
25-
test/basic-area test/stacking-penalties \
25+
test/basic-area test/basic-propulsion test/stacking-penalties \
2626
test/ancillary-modules test/drones test/implants \
2727
test/projected-effects test/projected-stacking \
2828
test/fleet-stacking test/self-on-self test/extra-misc \

test/basic-propulsion.c

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* libdogma
2+
* Copyright (C) 2017 Romain "Artefact2" Dalmaso <[email protected]>
3+
*
4+
* This program is free software: you can redistribute it and/or
5+
* modify it under the terms of the GNU Affero General Public License
6+
* as published by the Free Software Foundation, either version 3 of
7+
* the License, or (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public
15+
* License along with this program. If not, see
16+
* <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "test.h"
20+
21+
int main(void) {
22+
dogma_context_t* ctx;
23+
double value;
24+
dogma_key_t m, n;
25+
26+
/* Data source: pyfa 1.26.0 Stable - YC118.10 1.2 */
27+
28+
assert(dogma_init() == DOGMA_OK);
29+
assert(dogma_init_context(&ctx) == DOGMA_OK);
30+
31+
assert(dogma_set_ship(ctx, TYPE_Rifter) == DOGMA_OK);
32+
33+
assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &value) == DOGMA_OK);
34+
assertf(456.25, value, .01);
35+
36+
assert(dogma_add_module_s(ctx, TYPE_1MNAfterburnerII, &m, DOGMA_STATE_Active) == DOGMA_OK);
37+
assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &value) == DOGMA_OK);
38+
assertf(1193.25253299, value, .01);
39+
40+
assert(dogma_add_module_s(ctx, TYPE_1600mmSteelPlatesII, &n, DOGMA_STATE_Online) == DOGMA_OK);
41+
assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &value) == DOGMA_OK);
42+
assertf(719.951977966, value, .01);
43+
44+
assert(dogma_remove_module(ctx, m) == DOGMA_OK);
45+
assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &value) == DOGMA_OK);
46+
assertf(456.25, value, .01);
47+
48+
assert(dogma_remove_module(ctx, n) == DOGMA_OK);
49+
50+
assert(dogma_get_ship_attribute(ctx, ATT_SignatureRadius, &value) == DOGMA_OK);
51+
assertf(35.0, value, .01);
52+
53+
assert(dogma_add_module_s(ctx, TYPE_5MNMicrowarpdriveII, &m, DOGMA_STATE_Active) == DOGMA_OK);
54+
assert(dogma_get_ship_attribute(ctx, ATT_MaxVelocity, &value) == DOGMA_OK);
55+
assertf(3240.48141353, value, .01);
56+
assert(dogma_get_ship_attribute(ctx, ATT_SignatureRadius, &value) == DOGMA_OK);
57+
assertf(210.0, value, .01);
58+
59+
assert(dogma_free_context(ctx) == DOGMA_OK);
60+
return 0;
61+
}

tools/bootstrap_from_json

+114-46
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env php
22
<?php
33
/* libdogma
4-
* Copyright (C) 2012, 2013, 2014, 2015, 2016 Romain "Artefact2" Dalmaso <[email protected]>
4+
* Copyright (C) 2012, 2013, 2014, 2015, 2016, 2017 Romain "Artefact2" Dalmaso <[email protected]>
55
*
66
* This program is free software: you can redistribute it and/or
77
* modify it under the terms of the GNU Affero General Public License
@@ -422,6 +422,93 @@ function combine_expressions(&$json, array $expressionids) {
422422
return array_pop($expressionids);
423423
}
424424

425+
/* DEFASSOCIATION($assoc) */
426+
function mkexpr_association(&$json, $assoc) {
427+
return query_or_insert_expression($json, [
428+
'operandID' => 21,
429+
'expressionValue' => $assoc,
430+
]);
431+
}
432+
433+
/* DEFENVIDX($env) */
434+
function mkexpr_envidx(&$json, $env) {
435+
return query_or_insert_expression($json, [
436+
'operandID' => 24,
437+
'expressionValue' => $env,
438+
]);
439+
}
440+
441+
/* DEFATTRIBUTE($attr) */
442+
function mkexpr_attribute(&$json, $attr) {
443+
return query_or_insert_expression($json, [
444+
'operandID' => 22,
445+
'expressionAttributeID' => $attr,
446+
]);
447+
}
448+
449+
/* $env->$attr */
450+
function mkexpr_att(&$json, $env, $attr) {
451+
return query_or_insert_expression($json, [
452+
'operandID' => 12, /* ATT */
453+
'arg1' => mkexpr_envidx($json, $env),
454+
'arg2' => mkexpr_attribute($json, $attr),
455+
]);
456+
}
457+
458+
/* ($env->$attr).($assoc) */
459+
function mkexpr_eff(&$json, $assoc, $env, $attr) {
460+
return query_or_insert_expression($json, [
461+
'operandID' => 31,
462+
'arg1' => mkexpr_association($json, $assoc),
463+
'arg2' => mkexpr_att($json, $env, $attr),
464+
]);
465+
}
466+
467+
/* (($destenv->$destattr).($assoc)).AddItemModifier($srcattr) */
468+
function mkexpr_aim(&$json, $assoc, $destenv, $destattr, $srcattr, $customsrc = false) {
469+
return query_or_insert_expression($json, [
470+
'operandID' => 6,
471+
'arg1' => mkexpr_eff($json, $assoc, $destenv, $destattr),
472+
'arg2' => $customsrc ? $srcattr : mkexpr_attribute($json, $srcattr),
473+
]);
474+
}
475+
476+
/* Turns AIM into RIM, etc. Returns new exprID */
477+
function flip_modifiers(&$json, $id) {
478+
static $mods = null;
479+
480+
if($mods === null) {
481+
$mods = [
482+
2 => 54, /* GangGroupModifier */
483+
3 => 55, /* GangItemModifier */
484+
4 => 56, /* GangOwnerRequiredSkillModifier */
485+
5 => 57, /* GangRequiredSkillModifier */
486+
6 => 58, /* ItemModifier */
487+
7 => 59, /* LocationGroupModifier */
488+
8 => 60, /* LocationModifier */
489+
9 => 61, /* LocationRequiredSkillModifier */
490+
11 => 62, /* OwnerRequiredSkillModifier */
491+
];
492+
foreach($mods as $a => $r) $mods[$r] = $a;
493+
}
494+
495+
assert(isset($json['expressions'][$id]));
496+
$exp = $json['expressions'][$id];
497+
498+
if(isset($exp['arg1'])) {
499+
$exp['arg1'] = flip_modifiers($json, $exp['arg1']);
500+
}
501+
if(isset($exp['arg2'])) {
502+
$exp['arg2'] = flip_modifiers($json, $exp['arg2']);
503+
}
504+
505+
if(isset($mods[$exp['operandID']])) {
506+
$exp['operandID'] = $mods[$exp['operandID']];
507+
}
508+
509+
return query_or_insert_expression($json, $exp);
510+
}
511+
425512
/* ---------------- */
426513

427514
if($argc !== 2) {
@@ -732,10 +819,7 @@ foreach($json['effects'] as &$effect) {
732819

733820
}
734821

735-
$association = query_or_insert_expression($json, [
736-
'operandID' => 21, /* DEFASSOCIATION */
737-
'expressionValue' => $assocstring,
738-
]);
822+
$association = mkexpr_association($json, $assocstring);
739823

740824
$eff = query_or_insert_expression($json, [
741825
'operandID' => 31, /* EFF */
@@ -766,54 +850,16 @@ foreach($json['effects'] as &$effect) {
766850

767851
/* Expression for the AAR charge:
768852
* ((CurrentOther->armorDamageAmount).(PreMul)).AddItemModifier (CurrentOther->chargedArmorDamageMultiplier)
853+
* Real dogma wouldn't accept this.
769854
*/
770855

771-
$source = query_or_insert_expression($json, [
772-
'operandID' => 31, /* EFF */
773-
'arg1' => query_or_insert_expression($json, [
774-
'operandID' => 21, /* DEFASSOCIATION */
775-
'expressionValue' => 'PreMul',
776-
]),
777-
'arg2' => query_or_insert_expression($json, [
778-
'operandID' => 12, /* ATT */
779-
'arg1' => query_or_insert_expression($json, [
780-
'operandID' => 24, /* DEFENVIDX */
781-
'expressionValue' => 'Other',
782-
]),
783-
'arg2' => query_or_insert_expression($json, [
784-
'operandID' => 22, /* DEFATTRIBUTE */
785-
'expressionAttributeID' => 84, /* armorDamageAmount */
786-
]),
787-
]),
788-
]);
789-
790-
$target = query_or_insert_expression($json, [
791-
'operandID' => 12, /* ATT */
792-
'arg1' => query_or_insert_expression($json, [
793-
'operandID' => 24, /* DEFENVIDX */
794-
'expressionValue' => 'Other',
795-
]),
796-
'arg2' => query_or_insert_expression($json, [
797-
'operandID' => 22, /* DEFATTRIBUTE */
798-
'expressionAttributeID' => 1886, /* chargedArmorDamageMultiplier */
799-
]),
800-
]);
801-
802856
/* Effect for the Nanite Repair Paste when used in an Ancillary Armor Repairer */
803857
$json['effects'][-10] = array(
804858
'effectName' => 'internalAAREffect',
805859
'effectID' => -10,
806860
'effectCategory' => 0,
807-
'preExpression' => query_or_insert_expression($json, [
808-
'operandID' => 6, /* AIM */
809-
'arg1' => $source,
810-
'arg2' => $target,
811-
]),
812-
'postExpression' => query_or_insert_expression($json, [
813-
'operandID' => 58, /* RIM */
814-
'arg1' => $source,
815-
'arg2' => $target,
816-
]),
861+
'preExpression' => $id = mkexpr_aim($json, 'PreMul', 'Other', 84, mkexpr_att($json, 'Other', 1886), true),
862+
'postExpression' => flip_modifiers($json, $id),
817863
'durationAttributeID' => null,
818864
'trackingSpeedAttributeID' => null,
819865
'dischargeAttributeID' => null,
@@ -906,6 +952,28 @@ $json['effects'][3380]['postExpression'] = combine_expressions($json, [
906952
$makeWDSGroupModifier(59 /* RLGM */, 46, 20, 1164), /* AB and MWD Max velocity */
907953
]);
908954

955+
/* moduleBonusAfterburner:
956+
* ship mass += massAddition
957+
* speedFactor *= speedBoostFactor (thrust)
958+
* speedFactor /= ship mass
959+
* ship maxVelocity PostPercent speedFactor */
960+
$json['effects'][6731]['preExpression'] = combine_expressions($json, [
961+
mkexpr_aim($json, 'ModAdd', 'Ship', 4, 796),
962+
mkexpr_aim($json, 'PostMul', 'Self', 20, 567),
963+
mkexpr_aim($json, 'PostDiv', 'Self', 20, mkexpr_att($json, 'Ship', 4), true),
964+
mkexpr_aim($json, 'PostPercent', 'Ship', 37, 20),
965+
]);
966+
$json['effects'][6731]['postExpression'] = flip_modifiers($json, $json['effects'][6731]['preExpression']);
967+
968+
/* moduleBonusMicrowarpdrive:
969+
* same as afterburner
970+
* ship signatureRadius PostPercent signatureRadiusBonus */
971+
$json['effects'][6730]['preExpression'] = combine_expressions($json, [
972+
$json['effects'][6731]['preExpression'],
973+
mkexpr_aim($json, 'PostPercent', 'Ship', 552, 554),
974+
]);
975+
$json['effects'][6730]['postExpression'] = flip_modifiers($json, $json['effects'][6730]['preExpression']);
976+
909977
/* skillEffect: bogus/unknown DEFASSOCIATION, skills are handled
910978
* correctly without it anyway */
911979
$json['effects'][132]['preExpression'] = -1;

0 commit comments

Comments
 (0)