/
worldmap
executable file
·203 lines (174 loc) · 7.94 KB
/
worldmap
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
#!/usr/bin/perl -wT
use strict;
use CGI;
use Data::Dumper;
use List::Util 'shuffle', 'min', 'max' ;
use POSIX;
use XML::Simple;
###################################################
# Using findbin to locate our new City.pm module
use lib "lib/";
###################################################
#TODO it would be cool if it could rain frogs or potatoes
use City 'build_city', 'd', 'generate_name' ;
my $xml = new XML::Simple;
###########################################################
# Yes, this is sloppy. I am aware, but it's also unique.
# Unique, Ubiquitous Singletons.
our $q = CGI->new;
our $xml_data = $xml->XMLin( "xml/data.xml", ForceContent => 1, ForceArray =>[] );
our $names_data = $xml->XMLin( "xml/names.xml", ForceContent => 1, ForceArray =>[] );
my $testcityid=City::set_seed();
if (defined $q->param('cityid')){
$testcityid=$q->param('cityid');
}elsif (defined $q->param('continent')){
$testcityid=$q->param('continent').'00';
}elsif (defined $q->param('region')){
$testcityid=$q->param('region').'0';
}
#########################################################################
# First thing we need to do is establish a city skeleton of information,
# then fill it in as needed by each subsection of the sample text.
#########################################################################
our $city=build_city($testcityid);
#########################################################################
# Now that $city is fleshed out, we can print it..
#########################################################################
# Show city XML
if (defined $q->param('type') and $q->param('type') eq 'xml' ){
print $q->header( 'text/xml' );
print "<?xml version='1.0' encoding='ISO-8859-1' ?>\n";
print XMLout($city);
#show city data structure
}elsif (defined $q->param('type') and $q->param('type') eq 'dump' ){
print $q->header( 'text/plain' );
print Dumper $city;
#show city data structure
}elsif (defined $q->param('type') and $q->param('type') eq 'citizens' ){
print $q->header( 'text/plain' );
print Dumper $city->{'citizens'};
# run describe city, but don't print it- useful for debugging
}elsif (defined $q->param('type') and $q->param('type') =~ /debug/ ){
describe_city();
# show the data.xml xml content
}elsif (defined $q->param('type') and $q->param('type') eq 'source' ){
print $q->header( 'text/xml' );
print "<?xml version='1.0' encoding='ISO-8859-1' ?>\n";
print XMLout($xml_data);
# and if it doesn't match those, do the regular printing of the city.
}else {
# print $q->header( 'text/xml' ); # XXX remove this
print $q->header;
print describe_city();
}
exit;
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
#######################################################################################################################
sub describe_city {
my $content=describe_header();
}
sub format_regions{
my $content="[";
foreach my $realm ( @{$city->{'realms'}} ){
$content.="{".
"seed:'". $realm->{'id'}."',".
"name:'". $realm->{'name'}."',".
"},\n"
}
$content.="]";
return $content;
}
sub format_neighbors{
my $content="[";
foreach my $neighbor ( @{$city->{'neighbors'}} ){
$content.="{".
"seed:'". $neighbor->{'id'}."',".
"name:'". $neighbor->{'name'}."',".
"relation:'".$neighbor->{'relation'}."',".
"size:'". $neighbor->{'population'}->{'size'}."',".
"size_modifier:'". $neighbor->{'size_modifier'}."'".
"},\n"
}
$content.="]";
return $content;
}
sub describe_header{
my $letter = substr $city->{'name'}, 0,1;
my $regionseed=$city->{'seed'}-$city->{'seed'}%10 ;
my $cityID=0;
my $origseed=$city->{'seed'};
my @names;
while ($cityID <10){
my $seed= $regionseed+$cityID;
push @names, generate_name($seed);
$cityID++
}
my $names="['".join("', '",@names)."']";
my $districts="['".join("', '",@{ $city->{'districts'}})."']";
my $neighbors=format_neighbors();
my $regions=format_regions();
my $continentseed=($city->{'seed'}-$city->{'seed'}%100)/100 ;
my $continentname=$city->{'continent'};
my $content=" <!DOCTYPE html>
<html>
<head>
<title>City Generator: Continent of $continentname ($continentseed)</title>
<script src='js/flag.js' ></script>
<script src='js/rhill-voronoi-core.js' ></script>
<script src='js/simplex-noise.js' ></script>
<script src='js/map.js' ></script>
<script src='js/VoronoiMap.js' ></script>
<script src='js/CityMap.js' ></script>
<script src='js/WorldMap.js' ></script>
<script src='js/QuadTree.js' ></script>
<script src='http://code.jquery.com/jquery-latest.js'></script>
<link href='css/style.css' type='text/css' rel='stylesheet'/>
</head>
<body onload=\"
canvas=document.getElementById('worldmap')
continentmap=new WorldMap({
seed:$city->{'seed'},
sites:9000,
canvas:canvas,
cities:$neighbors,
regions:$regions,
locations:[]
});
continentmap.redrawMap(canvas);
;\">
<h1><a href='worldmap?continent=$continentseed'>Continent of $continentname ($continentseed)</a></h1>
<canvas id=\"worldmap\" width='1080' height='650' onclick='continentmap.gotoRegion(event,this)' onmousemove='continentmap.setCurrentRegion(event,this); continentmap.redrawMap(canvas) '></canvas>
<div id='regionlegend'> </div>
<div id='continentlegend'></div>
<div id='neighboring_cities'></div>
<div id='diplomatic_ties_text'></div>
<div id='footer'>
<sub>Note: The purpose of this tool is not to provide you with a complete, logical, feasible city- quite the contrary. The purpose is to give a DM a seed for building their own city. If things don't make sense, try to figure out the conditions that lead to that state. The intersting backstory comes from the DM excercising their imagination.</sub>
<p>Follow development progress at <a href='https://plus.google.com/112661873200782342936' rel='publisher'>CityGenerator on Google+</a></p>
</div>
</body>
</html>\n";
return $content;
}
###############################################################################
#
# print_landmarks - return the landmarks in an easy-to-display sentence.
#
###############################################################################
sub print_landmarks {
my $landmarks=$city->{'location'}->{'landmarks'};
if(ref($landmarks) eq 'ARRAY'){
if (scalar(@$landmarks) eq 1 ){
return "A nearby ".$landmarks->[0]." is a local landmark.";
} elsif( scalar(@$landmarks) >1 ){
my $landmarklist=" and ".(pop(@{$landmarks}));
return "Local landmarks include a ".join(', ', @{$landmarks}) . $landmarklist .".";
}else{
return "";
}
}
}