diff --git a/build_tools/code-generators/db-lang.pl b/build_tools/code-generators/db-lang.pl index 14a2c7452..ef2bb676d 100755 --- a/build_tools/code-generators/db-lang.pl +++ b/build_tools/code-generators/db-lang.pl @@ -48,6 +48,24 @@ sub parseEnum } } +sub readTillEnd +{ + my ($output) = @_; + + while (<>) + { + chomp; + + # See if we've reached the end of this block + if (/^\s*end\s*;\s*$/) + { + return; + } + + push @$output, $_; + } +} + sub parseStruct { my %curStruct = (name => $_[0]); @@ -102,6 +120,19 @@ sub parseStruct ${$curStruct{"qualifiers"}}{"inherit"} = \%{$structMap{$1}}; } + elsif (/^preLoadTable(\s+maxId)?(\s+rowCount)?\s*$/) + { + push @{${${$curStruct{"qualifiers"}}{"preLoadTable"}}{"parameters"}}, $1 if $1; + push @{${${$curStruct{"qualifiers"}}{"preLoadTable"}}{"parameters"}}, $2 if $2; + + readTillEnd(\@{${${$curStruct{"qualifiers"}}{"preLoadTable"}}{"code"}}); + } + elsif (/^postLoadRow\s+curRow(\s+curId)?\s*$/) + { + push @{${${$curStruct{"qualifiers"}}{"postLoadRow"}}{"parameters"}}, $1 if $1; + + readTillEnd(\@{${${$curStruct{"qualifiers"}}{"postLoadRow"}}{"code"}}); + } } # Parse regular field declarations elsif (/^\s*(count|real|bool)\s+(unique\s+)?(\w+)\s*;\s*$/) diff --git a/build_tools/code-generators/test_code.tpl b/build_tools/code-generators/test_code.tpl index 33128841d..715e4a061 100644 --- a/build_tools/code-generators/test_code.tpl +++ b/build_tools/code-generators/test_code.tpl @@ -51,6 +51,25 @@ end; struct BODY %inherit COMPONENT; %loadFunc "loadBodyStatsFromDB"; + %preLoadTable maxId; + if (!statsAllocBody($maxId)) + ABORT; + end; + %postLoadRow curRow curId; + // set the max stat values for the design screen + if ($curRow->designable) + { + // use front armour value to prevent bodyStats corrupt problems + setMaxBodyArmour($curRow->armourValue[HIT_SIDE_FRONT][WC_KINETIC]); + setMaxBodyArmour($curRow->armourValue[HIT_SIDE_FRONT][WC_HEAT]); + setMaxBodyPower($curRow->powerOutput); + setMaxBodyPoints($curRow->body); + setMaxComponentWeight($curRow->weight); + } + + // save the stats + statsSetBody($curRow, $curId - 1); + end; # The number of available weaponSlots slots on the body count weaponSlots;