This repository has been archived by the owner on Aug 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_faction_xml2html.pl
executable file
·2706 lines (2102 loc) · 91.6 KB
/
convert_faction_xml2html.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# script to create HTML-pages and diagrams from the glest-factions techtree
# 20110120, bugs & feedback to [email protected]
# Copyright 2011 olaus
# Copyright 2012-2016 olaus & MegaGlest Team
# license: GPLv3 or newer
our $version = "0.8.2 beta";
# This tool requires jquery and the jquery dataTables plugin (run setupDeps.sh which uses curl to try to download these into the media folder).
# These are NOT required to run the script but are used to display the resulting html.
# general comments for running:
# - developed on ubuntu linux 10.04 and with modules from ubuntu (install with "apt-get install libgraphviz-perl libconfig-inifiles-perl libxml-xpath-perl perlmagick")
# - on non-ubuntu systems install "graphviz" using your package manager and try to also find the right perl modules with it.
# - if the package manager doesn't work install the needed perl modules using "cpan" on the command line: (untested):
# cpan> install XML::XPath;
# cpan> install GraphViz;
# cpan> install Config::IniFiles;
#
# - adjust the paths in the .ini-file to your system and run with f.e. "convert_faction_xml2html.pl mg.ini"
# - won't work on windows without adjustments (search for "system", at least ... ) and i guess some of the modules used aren't easily available for active-state-perl (graphviz also runs on windows).
# general comments for changing the code:
# - as far as possible i used "pidgin-perl" and tried to avoid complicated functions and data-structures. so hopefully anybody with bare programming skills can adopt this code to his needs
# - it runs with "use strict" and -w without any warnings. this makes coding a bit more complicated but saves lots of time in the long run, get used to it ;)
# - watch out for singular & plural in the variable-names, $harvested_resources{} ne $harvested_resource
# - if you need to read some new stuff from the XML-files, google the xpath-documentation. check if it's single- or multi-valued. use xpath.pl to check the location.
# - if you want to rewrite this in your favorite language i recommend your local xpath-module, then you can reuse the xpath-locations from this script
# - uses jquery.com and datatables.net for table sorting and searching. i recommend the firefox add-onswebdeveloper and firebug if touching these
# TODO:
# - requirement page per faction with all buildings and producing units and the units they produce (footnotes for requirements) (collect in $production{ $u } and $production_units{ $u }
# DONE:
# 0.8
# - bugfix: missing requirements in building & units diagrams
# - included all needed files in media-directory
# - reworker directory-structure in generated html-directory (best to delete the old one before upgrading!)
# - changed mg.ini and style.css to mg-webdesign (doesn't work with the wide tables because tiles are just made for narrow content in the middle)
# 0.7
# - big all and everything-table
# 0.6:
# - add png images rendered by g3d_viewer (by softcoder, thanks)
# 0.5:
# - allow relative & absolut path at the same time (relative can't start with / )
# - show what levels (f.e. elite after x kills) add to sight, armor, ...
# - show what available upgrades add to stats in each unit
# 0.4:
# - show updates available for each unit
# - fix paths with spaces
# 0.3
# - @all_html_pages with with page-title, sort by faction, special pages (keys & armor/attack)
# - fixed morph cost of thor/thortotem
# - pass http://validator.w3.org
# - images path per unit for romans (5 times guard.bmp with different content)
# - <NOBR> in cost
# - included levels
# maybe someday ...
# - compare units like http://www.imaging-resource.com/IMCOMP/COMPS01.HTM
# - support GAE skills (patrol, guard)
# - units commands in seperate table
# - links to XML-files
# - print -> &log
# - generate some descriptive text for each unit, like "this is the unit with the most hitpoints/damage to air units/armor/movement speed/... of the tech faction"
# - diff feature (CGI?) to show what changed in units if moving f.e. from vanila glest 3.2 to MG 3.4
# - make overview tables sortable (javascript?)
# - overview tables without border but different colors in odd/even rows
# - list of units this one is strong/weak against (via armor- and attack-types)
# - top-lists over all factions (units with most hit points, damage, ...)
# - calculate a "bang for the buck" for 10 units including all cost for upgrades, buildings, ...
# - multilanguage (use more icons, lng-files but unit names aren't multilanguage anyway)
# - import bitmap-icons in SVG (doesn't work with perls graphviz-module, would need to parse and change SVG)
# - map symbology below diagram
# - single pages for units with animated gif, link to XML, mini-diagram of techtree just for this unit
# - convert bmp-icons to png
# - create PDF-handbook of all units
# usefull for converting HTML-colors: http://www.yafla.com/yaflaColor/ColorRGBHSL.aspx
# strange stuff in the techtrees:
# - persian magician splash radius 0?
# - tech upgrades piercing/blade weapon don't work for battle machine?
# - f.e. battle machine with "hold" will only attack land units
# - workers are able to help a technician build an aerodrome faster. is that wanted?
####################################################################
our $cfg;
my $cfg_file;
if ( $cfg_file = shift @ARGV ) {
if ( ! -e $cfg_file ) {
die "cfg_file not existing: $cfg_file\n";
}
}
else {
$cfg_file ="zetapack.ini";
}
if ( ! -e $cfg_file ) {
die "\nusage: $0 [zetapack.ini]\n\n";
}
$cfg = new Config::IniFiles( -file => "./$cfg_file", -allowcontinue => 1 );
use strict;
use XML::XPath;
use XML::XPath::XMLParser;
use GraphViz;
use Config::IniFiles;
use FindBin;
use File::Spec;
use Cwd;
use File::Glob ':glob';
#use Image::Resize;
use Image::Magick;
BEGIN {
$ENV{APP_ROOT} = Cwd::realpath(File::Spec->rel2abs($FindBin::Bin)) ;
}
our $use_relative_paths = $cfg->val( 'all', 'relative_paths');
our $generate_g3d_images = $cfg->val( 'all', 'generate_g3d_images');
our $debug = $cfg->val( 'all', 'debug');
our $glest_version = $cfg->val( 'all', 'version');
our $factions_path=$cfg->val( 'files' , 'factions_path');
$factions_path = "$ENV{APP_ROOT}/$factions_path" if ( $use_relative_paths && $factions_path !~ /^\//);
our $g3dviewer_path=$cfg->val( 'files' , 'g3dviewer_path');
$g3dviewer_path = "$ENV{APP_ROOT}/$g3dviewer_path" if ( $use_relative_paths );
our $resources_path=$cfg->val( 'files' , 'resources_path');
$resources_path = "$ENV{APP_ROOT}/$resources_path" if ( $use_relative_paths && $resources_path !~ /^\// );
our $out_path=$cfg->val( 'files' , 'out_path');
$out_path = "$ENV{APP_ROOT}/$out_path" if ( $use_relative_paths && $out_path !~ /^\// );
our $pack_file=$cfg->val( 'files' , 'pack_file');
$pack_file = "$ENV{APP_ROOT}/$pack_file" if ( $use_relative_paths && $pack_file !~ /^\// );
our $units_path=$cfg->val( 'files' , 'units_path');
our $upgrades_path=$cfg->val( 'files' , 'upgrades_path');
our $images_path=$cfg->val( 'files' , 'images_path');
our $glestkeys=$cfg->val( 'files' , 'glestkeys');
$glestkeys = "$ENV{APP_ROOT}/$glestkeys" if ( $use_relative_paths && $glestkeys !~ /^\// );
our $summary = $cfg->val('files', 'summary');
our $svg_fontcolor = $cfg->val( 'style', 'svg_fontcolor');
our @armor_types;
our @attack_types;
our @resource_order = split(/:/, $cfg->val( 'style', 'resource_order') );
my $now_string = localtime;
my $me = $0;
$me =~ s/^.+\///;
our $footer=$cfg->val( 'style', 'footer');
our $map_legend = $cfg->val('style', 'map_legend');
#$footer =~ s/VAR_CREATED_BY/<I><A HREF=\"http:\/\/rupp.de\/glest\/\">$me<\/A><\/I>, version: <I>$version<\/I>, using config-file: <I>$cfg_file<\/I>, on: <I>$now_string<\/I> /;
# ^ timestamp should be in the one common footer
$footer =~ s/VAR_CREATED_BY/<I><A HREF=\"https:\/\/github.com\/ZetaGlest\/zetaglest.github.io\/blob\/master\/convert_faction_xml2html\/convert_faction_xml2html.pl\">$me<\/A><\/I>, version: <I>$version<\/I>, using config-file: <I>$cfg_file<\/I>/;
our $level_hp = $cfg->val('all', 'level_hp');
our $level_ep = $cfg->val('all', 'level_ep');
our $level_sight = $cfg->val('all', 'level_sight');
our $level_armor = $cfg->val('all', 'level_armor');
$|=1;
if ( ! -e $factions_path ) {
die "ERROR: cant find factions_path: $factions_path, check $cfg_file\n";
}
if ( ! -e $resources_path ) {
die "ERROR: cant find resources_path: $resources_path, check $cfg_file\n";
}
mkdir $out_path;
mkdir "$out_path/images";
if ( ! -w $out_path ) {
die "cant find out_path: $out_path or no write permission\n";
}
#our @factions = bsd_glob("$factions_path/magi*");
#our @factions = bsd_glob("$factions_path/norsemen");
#our @factions = bsd_glob("$factions_path/tec*");
#our @factions = bsd_glob("$factions_path/roma*");
#our @factions = bsd_glob("$factions_path/egy*");
our @factions = bsd_glob("$factions_path/*");
our @resources = bsd_glob( "$resources_path/*");
our @all_html_pages;
our %h_all_html_pages;
our @special_html_pages;
push @special_html_pages, "compare.html;Compare Units";
push @special_html_pages, "all.html;All Units of all Factions";
our %damage_multiplier;
our %icon;
our %max_hp;
our %max_ep;
our %regeneration;
our %regeneration_ep;
our %building;
our %armor;
our %armor_type;
our %sight;
our %time;
our %height;
our %upgrade;
our %upgrade_effects;
our %upgrades_for;
our %move_speed;
our %production_speed;
our %worker;
our %combat;
our %air_unit;
our %land_unit;
our %created_by_unit;
our %c_unit_allows;
our %c_unit_requires;
our %c_all;
our %c_resource_requirement;
our %c_resource_store;
our %c_harvested_resources;
our %max_load;
our %hits_per_unit;
our %c_unit_requirements;
our %c_upgrade_requirements;
our %u_levels;
our %graph_files;
our %c_nodes;
our %c_edges;
our %c_edges_from;
our %edges_relation;
our %multi_hop;
our %multi_hop_upgrade;
# for storing skills:
our %c_skill;
our %c_command;
our %speed;
our %ep_cost;
our %skill_type;
our %attack_range;
our %attack_strength;
our %attack_var;
our %attack_type;
our %attack_start_time;
our %attack_land;
our %attack_air;
our %splash;
our %splash_radius;
our %splash_damage_all;
# for storing commands:
our %commands_of_unit;
our %command_type;
our %command_icon;
our %morph_skill;
our %morph_unit;
our %morph_discount;
our %move_skill;
our %move_loaded_skill;
our %attack_skill;
our %repair_skill;
our %build_skill;
our %produce_skill;
our %upgrade_skill;
our %harvest_skill;
our %produce_unit;
our %c_produced_units;
our %c_repaired_units;
our $graph_all;
our $graph_buildings;
our $graph_buildings_units;
our %tips;
# create page with all keys
if ( -f $glestkeys ) {
&create_glestkey_page();
}
if ( $cfg->val('files', 'load_tips') ) {
&load_tip_files();
}
if ( $pack_file ) {
&create_armor_vs_attack( $pack_file );
}
################################################
# built HTML for selecting faction
our $all_faction_links_overview ="";
foreach my $faction_path ( @factions ) {
my $faction = $faction_path;
$faction =~ s/.+\///;
my $faction_pretty = &format_name( $faction );
$all_faction_links_overview .= " <A HREF=${faction}_overview.html>$faction_pretty</a> | \n";
}
# remove last pipe
$all_faction_links_overview =~ s/ \| $//;
# built HTML-links for special pages:
our $special_pages ="Special Pages: ";
foreach my $page_tmp ( @special_html_pages ) {
my ( $page, $title ) = split(/;/, $page_tmp );
$page =~ s/$out_path\///;
$special_pages .= "<A HREF=\"$page\">$title</a> |\n";
}
# remove last pipe
chop $special_pages;
chop $special_pages;
chop $special_pages;
################################################
# copy resource images
mkdir "$out_path/images";
mkdir "$out_path/images/resources";
foreach my $resource_path ( @resources ) {
my $resource = $resource_path;
$resource =~ s/.+\///;
system "cp $resource_path/images/$resource.bmp $out_path/images/resources";
}
################################################
# read all units and draw graphs
foreach my $faction_path ( @factions ) {
my $faction = $faction_path;
$faction =~ s/.+\///;
my $faction_pretty = &format_name( $faction );
#my $graph = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "twopi" , overlap => "false");
#my $graph = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "fdp", concentrate => 1 , overlap => 0, epsilon => 0.01 );
$graph_all = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "dot", rankdir => 0 , overlap => 'false', concentrate => 1, epsilon => 0.01 );
# layout twopi, doesn't "bend" edges around nodes so the result doesn't look as good as it could
#$graph_all = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "twopi", rankdir => 0 , overlap => 'false', concentrate => 0, epsilon => 0.01 );
$graph_buildings = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "dot", rankdir => 0 , overlap => 'false', concentrate => 1, epsilon => 0.01 );
$graph_buildings_units = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "dot", rankdir => 0 , overlap => 'false', concentrate => 1, epsilon => 0.01 );
# good, from left to right:, not exactly 16:9 ;)
#my $graph = GraphViz->new( bgcolor => "0.5666,0,0.086", layout => "dot", rankdir => 1 , overlap => 0 );
print ("doing faction: $faction in path: <$faction_path>/<$units_path>\n") if ($debug);
mkdir ("$out_path/$images_path");
mkdir ("$out_path/$images_path/${faction}");
#system "cp $faction_path/loading_screen.jpg $out_path/$images_path/${faction}";
# read XML-files for all units
chdir ("$faction_path/$units_path");
opendir(UNITS, "." ) || die "cant open directory $faction_path/$units_path\n";
my @units = grep { !/\./ } readdir(UNITS);
closedir(UNITS);
foreach my $unit ( @units ) {
push @{ $c_all{"$faction"} }, $unit;
my $u = "$faction:$unit";
print "reading unit: $faction:$unit in $faction_path\n" if ( $debug );
my $unit_file ="$faction_path/$units_path/$unit/$unit.xml";
mkdir ("$out_path/$images_path/${faction}/$unit");
my ( $icon ) = &read_unit( $unit_file, $faction, $faction_path, $unit);
system "cp $faction_path/$units_path/$unit/images/$icon $out_path/$images_path/${faction}/$unit";
if ($generate_g3d_images == 1) {
my $full_png = $icon;
$full_png=~ s/\.[^.]+$//;
# use the height from the units XML-file for a rough guess on zooming the model to the right size
my $unit_height = $height{ $u };
# max to 6
$unit_height = 6 if ( $unit_height > 6 );
my $zoom = $cfg->val('style', 'unit_png_unit_zoom') - ( $unit_height * 0.15 );
# set buildings to config-value because some have just height=2 in XML
$zoom = $cfg->val('style', 'unit_png_building_zoom') if ( $building{ $u } );
my $save_as = "$out_path/$images_path/${faction}/$unit/$full_png-full.png";
if ( ! -e $save_as ) {
my $g3d_generate_cmd = "$g3dviewer_path --load-unit=$faction_path/$units_path/$unit,stop_skill,attack_skill --load-model-animation-value=0.5 --load-particle-loop-value=8 --zoom-value=$zoom --rotate-x-value=".$cfg->val('style', 'unit_png_rotate_x_value')." --rotate-y-value=".$cfg->val('style', 'unit_png_rotate_y_value')." --auto-screenshot=disable_grid,saveas-$save_as";
print "generating G3D using: [$g3d_generate_cmd]\n" if ( $debug );
my $ret = `$g3d_generate_cmd`;
print "g3d_generate said: $ret\n";
# if we need to resize the image the code below does it
#
my $image = new Image::Magick;
$image->Read($save_as);
#$image->Resize(
#width =>$cfg->val('style', 'unit_png_width'),
#height =>$cfg->val('style', 'unit_png_height')
#);
$image->Trim();
$image->Write($save_as);
#exit;
}
else {
print "g3d image already exist, skipping: $save_as\n";
}
}
}
# read XML-files for all upgrades
chdir ("$faction_path/$upgrades_path");
opendir(UPGRADES, "." ) || die "cant open directory $faction_path/$upgrades_path\n";
my @upgrades = grep { !/\./ } readdir(UPGRADES);
closedir(UPGRADES);
foreach my $upgrade ( @upgrades ) {
push @{ $c_all{"$faction"} }, $upgrade;
print "reading upgrade: $faction:$upgrade in $faction_path\n" if ( $debug );
my $upgrade_file ="$faction_path/$upgrades_path/$upgrade/$upgrade.xml";
mkdir ("$out_path/$images_path/${faction}/$upgrade");
my ( $icon ) = &read_unit( $upgrade_file, $faction, $faction_path, $upgrade );
system "cp $faction_path/$upgrades_path/$upgrade/images/$icon $out_path/$images_path/${faction}/$upgrade";
}
# don't clutter the diagram with direct links (mostly "requirement") if there's an indirect link with 2 hops.
# f.e. don't show a link that the technodrom is a requirement of the defense-tower because there's a link from
# technodrom to advanced architecture and a link from there to defense tower.
&check_multi_hops($faction);
# now the graphviz-nodes are set, do the edges
foreach my $edge ( @{$c_edges{"$faction"}} ) {
my ( $unit_from, $unit_to, $style, $relation ) = split(/:/, $edge );
# print "dedge: deciding edge for $faction:$unit_from:$unit_to - $relation -style: $style\n";
# only show requirement-link of there's no build, morph or produce link
# otherwise graphviz would show a dotted line where a solid one makes more sense
if (
(
$relation eq "Requirement" ||
$relation eq "Upgrade-Requirement"
) && (
$edges_relation{"$faction:$unit_from:$unit_to:Build"} ||
$edges_relation{"$faction:$unit_from:$unit_to:Morph"} ||
$edges_relation{"$faction:$unit_from:$unit_to:Produce"}
)
) {
}
else {
my $dont_link_in_all=0;
if (
$multi_hop{"$faction:$unit_from:$unit_to"} &&
$relation ne "Build" &&
$relation ne "Morph" &&
$relation ne "Produce"
) {
$dont_link_in_all=1;
# print "dedge: not showing edge $faction:$unit_from:$unit_to\n";
}
if ( $relation eq "Requirement" && $building{"$faction:$unit_to"} ) {
$graph_all -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor ) if (!$dont_link_in_all);
# only draw in the buildings-only-map if the requirement is also a building (f.e. in egypt a priest is needed for the obelisk)
if ( $building{"$faction:$unit_from"} ) {
$graph_buildings -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
}
elsif (
$relation eq "Requirement" ||
$relation eq "Upgrade-Requirement"
) {
$graph_all -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor ) if (!$dont_link_in_all);
# print "dedge: SHOWING edge $faction:$unit_from:$unit_to\n";
if ( !$upgrade{"$faction:$unit_from"} ) {
$graph_buildings_units -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
}
elsif ( $relation eq "Build" ) {
$graph_all -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor ) if (!$dont_link_in_all);
$graph_buildings_units -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
#$graph_buildings -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
elsif ( $relation eq "Upgrade" ) {
$graph_all -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor ) if (!$dont_link_in_all);
##$graph_buildings_units -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
##$graph_buildings -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
elsif ( $relation eq "Morph" ) {
$graph_all -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor ) if (!$dont_link_in_all);
$graph_buildings_units -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
##$graph_buildings -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
elsif ( $relation eq "Produce" ) {
$graph_all -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor ) if (!$dont_link_in_all);
$graph_buildings_units -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
##$graph_buildings -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
else {
die "shouldnt happen, grep me 545454545: $relation\n";
}
}
}
# create edges in diagrams which don't show the upgrades but go via an upgrade
# f.e. edge from technodrome to defense tower via advanced architecture
foreach my $multihop ( keys %multi_hop_upgrade ) {
my ( $faction_hop, $unit_from, $unit_to ) = split(/:/, $multihop );
if ( $faction eq $faction_hop ) {
# print "found multihop from building to building $unit_from to $unit_to\n";
my $style="dotted";
$graph_buildings_units -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
$graph_buildings -> add_edge("$unit_from" => "$unit_to", style => $style, color => $svg_fontcolor );
}
}
&export_graphs($faction);
if (
$cfg->val('all', 'build_clickable_map') &&
$cfg->val('all', 'export_graph') =~ /as_png/ &&
$cfg->val('all', 'export_graph') =~ /as_cmapx/
) {
&build_clickable_map( $faction );
}
}
####################################################################################
# now that we have all the unit- and upgrade-requirements: export HTML
####################################################################################
# for all and everything table:
my $all_html_table="";
my $col_order_tmp = $cfg->val('style', 'columns_all_table');
$col_order_tmp =~ s/\s//g;
my ( @col_order ) =split(/,/, $col_order_tmp );
foreach my $faction_path ( @factions ) {
my $faction = $faction_path;
$faction =~ s/.+\///;
my $faction_pretty = &format_name( $faction );
my $full_all = "<P> <P><HR><H1>Unit Details for Faction $faction_pretty</H1>\n";
my $overview_all = "<TABLE BORDER=1 WIDTH=\"100%\"><TR> <TH> Name
<TH> Total Cost
<TH> Hit Points
<TH> Rege- nerate
<TH> Armor Strength
<TH> Armor Type
<TH> Sight Range
";
my $overview_combat = "<H3>Combat Units</H3> $overview_all
<TH> Move Speed
<TH> Air / Ground
<TH> Attack Strength Land
<TH> Attack Strength Air
<TH> Attack Range
";
my $overview_worker = "<H3>Worker Units</H3> $overview_all
<TH> Move Speed
<TH> Air / Ground
";
my $overview_building = "<H3>Buildings</H3> $overview_all
<TH>Storage
";
my $overview_upgrades = "<H3>Upgrades</H3><TABLE BORDER=1><TR> <TH WIDTH=200> Name
<TH> Cost
<TH> Increases
<TH> Affects
<TH> Enables to build
";
# now we have read all the XMLs, loop again over all units and export them to HTML
foreach my $unit ( sort @{$c_all{"$faction"}} ) {
my $full = "";
# collect all columns seperatly and build tables in the end as configured
my %col = ();
my $u = "$faction:$unit";
# print "doing HTML for $u\n" if ( $debug );
my $full_tmp = "";
my $found = 0;
my $unit_pretty = &format_name( $unit );
$col{'name'} = $unit;
$col{'name_pretty'} = $unit_pretty;
$col{'name_link'} = &link_unit($faction, $unit);
$col{'faction'} = $faction;
$col{'faction_pretty'} = &format_name( $faction );
# FULL
$full .= "\n<TABLE BORDER=1>";
$full .= "<TR><TD WIDTH=250><A NAME=\"${unit}_full\"></A>".&html_icon( $u, 64 )."</TD><TD WIDTH=500> <B>$unit_pretty</B></TD></TR>\n";
if ($generate_g3d_images == 1) {
$full .= "<TR><TD COLSPAN=2 WIDTH=750><A NAME=\"${unit}_G3Dfull\"></A>".&html_icon_png( $u, $cfg->val('style', 'unit_png_width'), $cfg->val('style', 'unit_png_height') )."</TD></TR>\n";
}
if ( $upgrade{$u} ) {
$full .= "<TR><TD>Type:</TD><TD>Upgrade</TD></TR>\n";
$col{'type'} = "Upgrade";
}
elsif ( $building{$u} ) {
$full .= "<TR><TD>Type:</TD><TD>Building</TD></TR>\n";
$col{'type'} = "Building";
}
else {
$full .= "<TR><TD>Type:</TD><TD>";
if ( $worker{$u} ) {
$full .= "Worker Unit<br>\n";
$col{'type'} = "Worker Unit";
}
# a unit might fight and build so no elsif!
if ( $combat{$u} ) {
$full .= "Combat Unit\n";
$col{'type'} = "Combat Unit";
}
$full .= "</TD></TR>\n";
}
if ( $tips{ $unit } ) {
$full .= "<TR><TD>Description:</TD><TD> ".$tips{ "${unit}_info" }."</TD></TR>\n";
$col{'tip'} = $tips{ "${unit}_info" };
}
# put cost together
my $full_tmp_cost;
my ( $cost, $cost_icon, $cost_icon_overview );
# loop over creation-methods because f.e. guard might be produced in barracks or upgraded from swordman
my $num_creation_methods =@{$created_by_unit{ $u }};
my $num_method=0;
$full .= "<TR><TD>Creation:</TD><TD>";
foreach my $created_by_unit_tmp ( @{$created_by_unit{ $u }} ) {
$num_method++;
my ( $created_by_u, $method, $discount ) = split(/:/, $created_by_unit_tmp );
my ( $cost_tmp, $cost_icon_tmp, $cost_icon_overview_tmp ) = &calc_cost_of_unit( $u, $created_by_u, $method, $discount );
$cost_icon .= $cost_icon_tmp;
my %cost_hash;
my ( @cost_resources ) = split(/,/, $cost_tmp );
foreach my $cost_res ( @cost_resources ) {
my ( $resource, $amount ) = split(/:/, $cost_res );
$col{"${resource}_${num_method}"} = $amount;
$cost_hash{ $resource } = $amount;
}
my $created;
if ( $method eq "morph" ) {
$created = "upgraded from";
$full .= "Morphing from ".&link_unit($faction, ${created_by_u})."<BR>\n";
$col{"creation_${num_method}"} = "Morphed from ".&link_unit( $faction, ${created_by_u});
}
elsif ( $method eq "produce" ) {
$created = "produced by";
$full .= "Produced by ".&link_unit($faction, ${created_by_u})."<BR>\n";
$col{"creation_${num_method}"} = "Produced by ".&link_unit( $faction, ${created_by_u});
}
elsif ( $method eq "build" ) {
$created = "built by";
$full .= "Built by ".&link_unit($faction, ${created_by_u})."<BR>\n";
$col{"creation_${num_method}"} = "Built by ".&link_unit( $faction, ${created_by_u});
}
elsif ( $method eq "upgrade" ) {
$created = "upgraded by";
$full .= "Upgraded by ".&link_unit($faction, ${created_by_u})."<BR>\n";
$col{"creation_${num_method}"} = "Upgraded by ".&link_unit( $faction, ${created_by_u});
}
else {
print "method: $method for $u $created_by_u\n";
}
if ( $num_creation_methods == 1 ) {
$full_tmp_cost .= "<TR><TD>Total Cost: </TD><TD> $cost_icon_tmp\n";
}
else {
# f.e. guard might be produced in barracks or upgraded from swordman
$full_tmp_cost .= "<TR><TD>Total Cost when ${created} ".&format_name($created_by_u).": </TD><TD> $cost_icon_tmp\n";
}
# prefer cost for produce-method in overview if more than one method (guard) because that's less micromanagement for player
if (
$num_creation_methods == 1 ||
$num_creation_methods >= 2 &&
$method eq "produce"
) {
$cost_icon_overview = $cost_icon_overview_tmp;
}
}
$full .= "</TD></TR>\n";
# put storage of resources together
my $storage="";
my $storage_icon="";
foreach my $resource_stored ( @{$c_resource_store{"$faction:$unit"}} ) {
my ( $resource, $amount ) = split(/:/, $resource_stored );
$storage .= &format_name($resource).": $amount, ";
$storage_icon .= &html_icon_resource($resource, 16)." $amount ";
}
# remove trailing ", "
chop $storage;
chop $storage;
print "storage: $storage\n";
$col{"storage"} = $storage;
# do commands & skills
my $commands="";
my $full_attack_tmp="";
my $full_move_tmp="";
my $full_morph_tmp="";
my $full_repair_tmp="";
my $full_harvest_tmp="";
my $max_strength_vs_land = 0;
my $max_strength_vs_land_var = 0;
my $max_strength_vs_air = 0;
my $max_strength_vs_air_var = 0;
my $max_range = 0;
my $max_move_speed = 0;
my $num_move_command=0;
foreach my $c ( @{$commands_of_unit{"$u:move"}} ) {
$num_move_command++;
################################################################
# MOVE-command
################################################################
my ( $faction, $unit, $command ) = split(/:/, $c );
my $skill = $move_skill{ $c };
my $s = "$faction:$unit:$skill";
$full_move_tmp .= "<TR><TD> Move Command: ".&format_name($command)." </TD><TD> Speed: ".$speed{ $s }."</TD></TR>\n";
$col{"move_speed_${num_move_command}"} = $speed{ $s };
if ( $speed{ $s } > $max_move_speed ) {
$max_move_speed = $speed{ $s };
}
}
my $skill_on_hold_position="";
# don't ask me why this doesn't work ???????????
#$num_of_attacks = @{$commands_of_unit{"$u:attack"}};
# so do workaround:
my $num_of_attacks = 0;
foreach my $x ( @{$commands_of_unit{"$u:attack"}} ) {
$num_of_attacks++;
}
foreach my $c ( @{$commands_of_unit{"$u:attack_stopped"}} ) {
my ( $faction, $unit, $command ) = split(/:/, $c );
my $command_pretty = &format_name( $command );
$commands .= "$command_pretty, ";
# defensive-buildings like defense tower don't have an attack skill but just an attack_stopped skill
# so show this as main attack
if ( !$num_of_attacks ) {
my $full_attack_tmp_tmp;
( $full_attack_tmp_tmp, $max_strength_vs_land, $max_strength_vs_land_var, $max_strength_vs_air, $max_strength_vs_air_var, $max_range, $max_move_speed ) =
&show_attack( $c, $max_strength_vs_land, $max_strength_vs_land_var, $max_strength_vs_air, $max_strength_vs_air_var, $max_range, $max_move_speed );
$full_attack_tmp .= $full_attack_tmp_tmp;
}
else {
$skill_on_hold_position= $attack_skill{ $c };
if ( $c_upgrade_requirements{ $c } ) {
print "skill requires: $c_upgrade_requirements{ $c }\n";
$skill_on_hold_position .= ";$c_upgrade_requirements{ $c }";
}
}
}
# do all commands with <type value=attack>
my $num_attack=0;
foreach my $c ( @{$commands_of_unit{"$u:attack"}} ) {
my ( $faction, $unit, $command ) = split(/:/, $c );
my $command_pretty = &format_name( $command );
$commands .= "$command_pretty, ";
$num_move_command++;
$num_attack++;
my ($strength, $var, $range, $type, $speed, $start_time, $ep_cost ) ="";
my $full_attack_tmp_tmp;
(
$full_attack_tmp_tmp,
$max_strength_vs_land,
$max_strength_vs_land_var,
$max_strength_vs_air,
$max_strength_vs_air_var,
$max_range,
$max_move_speed,
$col{"attack_strength_$num_attack"},
$col{"attack_var_$num_attack"},
$col{"attack_range_$num_attack"},
$col{"attack_type_$num_attack"},
$col{"attack_speed_$num_attack"},
$col{"attack_start_time_$num_attack"},
$col{"attack_ep_cost_$num_attack"},
$col{"used_on_hold_position_$num_attack"},
$col{"target_$num_attack"},
) =
&show_attack( $c, $max_strength_vs_land, $max_strength_vs_land_var, $max_strength_vs_air, $max_strength_vs_air_var, $max_range, $max_move_speed, $skill_on_hold_position );
$full_attack_tmp .= $full_attack_tmp_tmp;
my $move_skill = $move_skill{ $c };
if ( $move_skill) {
my $ms = "$faction:$unit:$move_skill";
$col{"move_speed_${num_move_command}"} = $speed{ $ms };
}
}
$col{"max_move_speed"} = $max_move_speed;
# show levels
if ( $u_levels{ $u } ) {
my $level_num = 0;
$full_attack_tmp .= "<TR><TD>Level(s):</TD><TD>\n";
foreach my $level ( @{ $u_levels{ $u }} ) {
$level_num++;
$col{"max_level"} = $level_num;
my ( $name, $kills ) = split(/:/, $level );
$full_attack_tmp .= "<B>".&format_name($name)."</b> at $kills kills<BR>\n";
# let do some mathz:
$full_attack_tmp .= "Hitpoints: ".int( $max_hp{ $u } * $level_hp ** ( $level_num - 1))." -> ". int( $max_hp{ $u } * ( $level_hp ** $level_num) )."<BR>\n";
if ( $max_ep{ $u } ) {
$full_attack_tmp .= "Energy Points: ".int( $max_ep{ $u } * $level_ep ** ( $level_num -1))." -> ".int( $max_ep{ $u } * $level_ep ** $level_num)."<BR>\n";
}
$full_attack_tmp .= "Armor Strength: ".int($armor{ $u } * $level_armor ** ($level_num-1))." -> ".int( $armor{ $u } * $level_armor ** $level_num )."<BR>\n";
$full_attack_tmp .= "Sight: ".int($sight{ $u } * $level_sight ** ( $level_num -1))." -> ".int( $sight{ $u } * $level_sight ** $level_num )."<BR>\n";
# as specified in the code, thanks titi for digging it out
#maxHp+= ut->getMaxHp()*50/100;
#maxEp+= ut->getMaxEp()*50/100;
#sight+= ut->getSight()*20/100;
#armor+= ut->getArmor()*50/100;
}
$full_attack_tmp .= "</TD></TR>\n";
}
# show available upgrades for this unit
if ( $upgrades_for{ $u } ) {
$full_attack_tmp .= "<TR><TD>Upgrades Available:</TD><TD>";
foreach my $upgrade_tmp ( @{ $upgrades_for{ $u }} ) {
my ( $u_faction, $u_upgrade ) = split(/:/, $upgrade_tmp );
my ( $upgrade_benefits, $upgrade_benefits_html ) = &do_upgrade_benefits( $upgrade_tmp );
my $str_tmp = &link_unit($faction, $u_upgrade);
$str_tmp .= " ($upgrade_benefits)" if ( $upgrade_benefits );
$str_tmp .= "<BR>\n";
$full_attack_tmp .= $str_tmp;
$col{"available_upgrades"} .= $str_tmp;
}
$full_attack_tmp .= "</TD></TR>\n";
}
# morphing
my $num_morph_skill=0;
foreach my $c ( @{$commands_of_unit{"$u:morph"}} ) {
my ( $faction, $unit, $command ) = split(/:/, $c );
my $skill = $morph_skill{ $c };
my $s = "$faction:$unit:$skill";
my $skill_short = $skill;
$skill_short =~ s/_skill$//;
# print "morph_command: $command $c\n";
$full_morph_tmp .= "<TR><TD> Morph Skill: ".&format_name($skill_short)." </TD><TD>";
# since f.e. the technician can morph into different units, find the one for this skill
foreach my $command ( @{$c_command{ $u }} ) {
my $c = "$u:$command";
# print "comparing command: $skill of $c\n";
if ( $morph_skill{ $c } && $morph_skill{ $c } eq $skill ) {
# print "fitting morph_skill and command $skill of $c\n";
$full_morph_tmp .= "Morphing to: ".&link_unit($faction, $morph_unit{ $c }).&html_icon($faction.":".$morph_unit{ $c }, 64)."<BR>\n";
$full_morph_tmp .= "Refund (Discount): ".$morph_discount{ $c }." %<BR>\n";
$full_morph_tmp .="Morph Speed: ".$speed{ $s }."<BR>\n";
$num_morph_skill++;
$col{"morphing_to_$num_morph_skill"} = &link_unit($faction, $morph_unit{ $c });
$col{"morphing_discount_$num_morph_skill"} = $morph_discount{ $c }." %<BR>\n";
$col{"morphing_speed_$num_morph_skill"} = $speed{ $s }."<BR>\n";
}
}
$full_morph_tmp .= "</TD></TR>\n";