@@ -603,8 +603,8 @@ function generate() {
603603 drawStates ( ) ;
604604 drawBorders ( ) ;
605605 BurgsAndStates . drawStateLabels ( ) ;
606- addZones ( ) ;
607606 addMarkers ( ) ;
607+ addZones ( ) ;
608608 Names . getMapName ( ) ;
609609
610610 console . warn ( `TOTAL: ${ rn ( ( performance . now ( ) - timeStart ) / 1000 , 2 ) } s` ) ;
@@ -1176,16 +1176,21 @@ function rankCells() {
11761176}
11771177
11781178// add a some zones
1179- function addZones ( ) {
1179+ function addZones ( number = 1 ) {
11801180 console . time ( "addZones" ) ;
11811181 const data = [ ] , cells = pack . cells , states = pack . states , burgs = pack . burgs ;
1182- //const used = new Uint8Array(cells.i.length); // to store used cells
1183-
1184- // rebels along a state border
1185- void function addRebels ( ) {
1182+ const used = new Uint8Array ( cells . i . length ) ; // to store used cells
1183+
1184+ if ( Math . random ( ) < .8 * number ) addRebels ( ) ; // rebels along a state border
1185+ for ( let i = 0 ; i < rn ( Math . random ( ) * 1.8 * number ) ; i ++ ) addDisease ( ) ; // disease starting in a random city
1186+ for ( let i = 0 ; i < rn ( Math . random ( ) * 1.8 * number ) ; i ++ ) addDisaster ( ) ; // disaster starting in a random city
1187+ for ( let i = 0 ; i < rn ( Math . random ( ) * 1.8 * number ) ; i ++ ) addEruption ( ) ; // volcanic eruption afecing cells aroung volcanoes
1188+ for ( let i = 0 ; i < rn ( Math . random ( ) * 1.4 * number ) ; i ++ ) addFault ( ) ; // fault line
1189+
1190+ function addRebels ( ) {
11861191 const state = states . find ( s => s . i && s . neighbors . size > 0 && s . neighbors . values ( ) . next ( ) . value ) ;
11871192 if ( ! state ) return ;
1188-
1193+
11891194 const neib = state . neighbors . values ( ) . next ( ) . value ;
11901195 const cellsArray = cells . i . filter ( i => cells . state [ i ] === state . i && cells . c [ i ] . some ( c => cells . state [ c ] === neib ) ) ;
11911196
@@ -1194,10 +1199,9 @@ function addZones() {
11941199 "Insurrection" :2 , "Rebellion" :1 , "Conspiracy" :2 } ) ;
11951200 const name = getAdjective ( states [ neib ] . name ) + " " + rebels ;
11961201 data . push ( { name, type :"Rebels" , cells :cellsArray , fill :"url(#hatch3)" } ) ;
1197- } ( )
1202+ }
11981203
1199- // disease starting in a random city
1200- void function addDisease ( ) {
1204+ function addDisease ( ) {
12011205 const burg = ra ( burgs . filter ( b => b . i && ! b . removed ) ) ; // random burg
12021206 if ( ! burg ) return ;
12031207
@@ -1208,6 +1212,7 @@ function addZones() {
12081212 while ( queue . length ) {
12091213 const next = queue . dequeue ( ) ;
12101214 if ( cells . burg [ next . e ] || cells . pop [ next . e ] ) cellsArray . push ( next . e ) ;
1215+ used [ next . e ] = 1 ;
12111216
12121217 cells . c [ next . e ] . forEach ( function ( e ) {
12131218 const r = cells . road [ next . e ] ;
@@ -1229,20 +1234,20 @@ function addZones() {
12291234 const type = rw ( { "Fever" :5 , "Pestilence" :2 , "Flu" :2 , "Pox" :2 , "Smallpox" :2 , "Plague" :4 , "Cholera" :2 , "Ague" :1 , "Dropsy" :1 , "Leprosy" :2 } ) ;
12301235 const name = rw ( { [ color ( ) ] :4 , [ animal ( ) ] :2 , [ adjective ( ) ] :1 } ) + " " + type ;
12311236 data . push ( { name, type :"Disease" , cells :cellsArray , fill :"url(#hatch12)" } ) ;
1232- } ( )
1237+ }
12331238
1234- // disaster starting in a random city
1235- void function addDisaster ( ) {
1239+ function addDisaster ( ) {
12361240 const burg = ra ( burgs . filter ( b => b . i && ! b . removed ) ) ; // random burg
12371241 if ( ! burg ) return ;
12381242
1239- const cellsArray = [ ] , cost = [ ] , power = rand ( 10 , 30 ) ;
1243+ const cellsArray = [ ] , cost = [ ] , power = rand ( 5 , 28 ) ;
12401244 const queue = new PriorityQueue ( { comparator : ( a , b ) => a . p - b . p } ) ;
12411245 queue . queue ( { e :burg . cell , p :0 } ) ;
12421246
12431247 while ( queue . length ) {
12441248 const next = queue . dequeue ( ) ;
12451249 if ( cells . burg [ next . e ] || cells . pop [ next . e ] ) cellsArray . push ( next . e ) ;
1250+ used [ next . e ] = 1 ;
12461251
12471252 cells . c [ next . e ] . forEach ( function ( e ) {
12481253 const c = rand ( 1 , 10 ) ;
@@ -1256,10 +1261,64 @@ function addZones() {
12561261 } ) ;
12571262 }
12581263
1259- // Volcanic Eruption, Fault Line, Avalanche, Tsunami
1264+ // Avalanche, Tsunami
12601265 const type = rw ( { "Famine" :5 , "Drought" :3 , "Dearth" :1 , "Earthquake" :3 , "Tornadoes" :1 , "Wildfires" :1 , "Flood" :3 } ) ;
1261- data . push ( { name :type , type :"Disaster" , cells :cellsArray , fill :"url(#hatch5)" } ) ;
1262- } ( )
1266+ const name = getAdjective ( burg . name ) + " " + type ;
1267+ data . push ( { name, type :"Disaster" , cells :cellsArray , fill :"url(#hatch5)" } ) ;
1268+ }
1269+
1270+ function addEruption ( ) {
1271+ const volcanoes = [ ] ;
1272+ markers . selectAll ( "use[data-id='#marker_volcano']" ) . each ( function ( ) {
1273+ volcanoes . push ( this . dataset . cell ) ;
1274+ } ) ;
1275+ if ( ! volcanoes . length ) return ;
1276+
1277+ const cell = + ra ( volcanoes ) ;
1278+ const id = markers . select ( "use[data-cell='" + cell + "']" ) . attr ( "id" ) ;
1279+ const note = notes . filter ( n => n . id === id ) ;
1280+
1281+ if ( note [ 0 ] ) note [ 0 ] . legend = note [ 0 ] . legend . replace ( "Active volcano" , "Erupting volcano" ) ;
1282+ const name = note [ 0 ] ? note [ 0 ] . name . replace ( " Volcano" , "" ) + " Eruption" : "Volcano Eruption" ;
1283+
1284+ const cellsArray = [ ] , queue = [ cell ] , power = rand ( 10 , 30 ) ;
1285+
1286+ while ( queue . length ) {
1287+ const q = Math . random ( ) < .5 ? queue . shift ( ) : queue . pop ( ) ;
1288+ cellsArray . push ( q ) ;
1289+ if ( cellsArray . length > power ) break ;
1290+ cells . c [ q ] . forEach ( e => {
1291+ if ( used [ e ] ) return ;
1292+ used [ e ] = 1 ;
1293+ queue . push ( e ) ;
1294+ } ) ;
1295+ }
1296+
1297+ data . push ( { name, type :"Disaster" , cells :cellsArray , fill :"url(#hatch7)" } ) ;
1298+ }
1299+
1300+ function addFault ( ) {
1301+ const elevated = cells . i . filter ( i => cells . h [ i ] > 50 && cells . h [ i ] < 70 && ! used [ i ] ) ;
1302+ if ( ! elevated . length ) return ;
1303+
1304+ const cell = ra ( elevated ) ;
1305+ const cellsArray = [ ] , queue = [ cell ] , power = rand ( 3 , 15 ) ;
1306+
1307+ while ( queue . length ) {
1308+ const q = queue . pop ( ) ;
1309+ cellsArray . push ( q ) ;
1310+ if ( cellsArray . length > power ) break ;
1311+ cells . c [ q ] . forEach ( e => {
1312+ if ( used [ e ] ) return ;
1313+ used [ e ] = 1 ;
1314+ queue . push ( e ) ;
1315+ } ) ;
1316+ }
1317+
1318+ const proper = getAdjective ( Names . getCultureShort ( cells . culture [ cell ] ) ) ;
1319+ const name = proper + " Fault" ;
1320+ data . push ( { name, type :"Disaster" , cells :cellsArray , fill :"url(#hatch2)" } ) ;
1321+ }
12631322
12641323 void function drawZones ( ) {
12651324 zones . selectAll ( "g" ) . data ( data ) . enter ( ) . append ( "g" )
@@ -1286,7 +1345,7 @@ function addMarkers(number = 1) {
12861345 const cell = mounts . splice ( biased ( 0 , mounts . length - 1 , 5 ) , 1 ) ;
12871346 const x = cells . p [ cell ] [ 0 ] , y = cells . p [ cell ] [ 1 ] ;
12881347 const id = getNextId ( "markerElement" ) ;
1289- markers . append ( "use" ) . attr ( "id" , id )
1348+ markers . append ( "use" ) . attr ( "id" , id ) . attr ( "data-cell" , cell )
12901349 . attr ( "xlink:href" , "#marker_volcano" ) . attr ( "data-id" , "#marker_volcano" )
12911350 . attr ( "data-x" , x ) . attr ( "data-y" , y ) . attr ( "x" , x - 15 ) . attr ( "y" , y - 30 )
12921351 . attr ( "data-size" , 1 ) . attr ( "width" , 30 ) . attr ( "height" , 30 ) ;
@@ -1313,7 +1372,7 @@ function addMarkers(number = 1) {
13131372 . attr ( "data-size" , 1 ) . attr ( "width" , 30 ) . attr ( "height" , 30 ) ;
13141373
13151374 const proper = Names . getCulture ( cells . culture [ cell ] ) ;
1316- const temp = convertTemperature ( gauss ( 25 , 15 , 20 , 100 ) ) ;
1375+ const temp = convertTemperature ( gauss ( 30 , 15 , 20 , 100 ) ) ;
13171376 notes . push ( { id, name : proper + " Hot Springs" , legend :`A hot springs area. Temperature: ${ temp } ` } ) ;
13181377 count -- ;
13191378 }
0 commit comments