Skip to content

Commit

Permalink
Merge pull request #56 from Monsoonjr99/v0-4
Browse files Browse the repository at this point in the history
Version 0.4.21
  • Loading branch information
Monsoonjr99 authored Oct 31, 2024
2 parents e276783 + 3cc1e21 commit 9c7be01
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 16 deletions.
8 changes: 8 additions & 0 deletions basin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Basin{
this.godMode = opts.godMode;
this.SHem = opts.hem;
this.actMode = opts.actMode || 0;
if(SEASON_CURVE[this.actMode])
seasonCurve = window[SEASON_CURVE[this.actMode]];
else
seasonCurve = window[SEASON_CURVE.default];
if(opts.year !== undefined)
this.startYear = opts.year;
else if(this.SHem)
Expand Down Expand Up @@ -674,6 +678,10 @@ class Basin{
}
}
this.env.init(envData);
if(SEASON_CURVE[this.actMode])
seasonCurve = window[SEASON_CURVE[this.actMode]];
else
seasonCurve = window[SEASON_CURVE.default];
if(oldNameList){
let desSys = DesignationSystem.convertFromOldNameList(oldNameList);
if(!desSys.naming.annual)
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
About: A p5.js tropical cyclone simulation game

v0.4.21 (2024-10-31):
+ Added "Spooky" simulation mode
> Season peaks at the end of October and is notably explosive
> Implementation is kinda hacky
> Happy Halloween!
v0.4.20 (2024-09-07):
* Fixed text input boxes not working in fullscreen
* Fixed keybinds not working with caps lock enabled
Expand Down
2 changes: 1 addition & 1 deletion constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const TITLE = "Cyclone Simulator";
const VERSION_NUMBER = "0.4.20";
const VERSION_NUMBER = "0.4.21";

const SAVE_FORMAT = 7; // Format #7 in use starting in v0.4
const EARLIEST_COMPATIBLE_FORMAT = 0;
Expand Down
8 changes: 8 additions & 0 deletions environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,12 @@ class Land{
function seasonalSine(t,off){
off = off===undefined ? 5/12 : off;
return sin((TAU*(t-YEAR_LENGTH*off))/YEAR_LENGTH);
}

// quick and sloppy copy-paste of spooky code for Halloween update
// this, the regular season curve, and the wild mode season curve could all be implemented in a more concise way, but that can be done later and this codebase is being retired eventually anyway
function spookySeasonCurve(t,off){
off = off===undefined ? 0 : off;
let n = (1+t/YEAR_LENGTH-off)%1;
return n<5/24 ? map(n,0,5/24,-0.2,-1) : n<5/12 ? map(n,5/24,5/12,-1,0) : n<3/4 ? map(n,5/12,3/4,0,1.2) : n<39/48 ? map(n,3/4,39/48,1.2,1.5) : n<302.5/365.25 ? map(n,39/48,302.5/365.25,1.5,2.2) : n<305/365.25 ? 2.2 : n<81/96 ? map(n,305/365.25,81/96,2.2,0.8) : map(n,81/96,1,0.8,-0.2);
}
54 changes: 41 additions & 13 deletions sim-mode-defs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// ---- Simulation Modes ---- //

const SIMULATION_MODES = ['Normal','Hyper','Wild','Megablobs','Experimental']; // Labels for sim mode selector UI
const SIMULATION_MODES = ['Normal','Hyper','Wild','Megablobs','Experimental','Spooky']; // Labels for sim mode selector UI
const SIM_MODE_NORMAL = 0;
const SIM_MODE_HYPER = 1;
const SIM_MODE_WILD = 2;
const SIM_MODE_MEGABLOBS = 3;
const SIM_MODE_EXPERIMENTAL = 4;
const SIM_MODE_SPOOKY = 5;

// ---- Active Attributes ---- //

Expand All @@ -29,6 +30,14 @@ ACTIVE_ATTRIBS[SIM_MODE_EXPERIMENTAL] = [
'kaboom'
];

// ---- Season Curve ---- //

const SEASON_CURVE = {};

SEASON_CURVE.default = 'seasonalSine';
SEASON_CURVE[SIM_MODE_SPOOKY] = 'spookySeasonCurve';


// ---- Spawn Rules ---- //

const SPAWN_RULES = {};
Expand All @@ -39,6 +48,7 @@ SPAWN_RULES[SIM_MODE_HYPER] = {};
SPAWN_RULES[SIM_MODE_WILD] = {};
SPAWN_RULES[SIM_MODE_MEGABLOBS] = {};
SPAWN_RULES[SIM_MODE_EXPERIMENTAL] = {};
SPAWN_RULES[SIM_MODE_SPOOKY] = {};

// -- Defaults -- //

Expand Down Expand Up @@ -166,10 +176,10 @@ SPAWN_RULES.defaults.archetypes = {

SPAWN_RULES.defaults.doSpawn = function(b){
// tropical waves
if(random()<0.015*sq((seasonalSine(b.tick)+1)/2)) b.spawnArchetype('tw');
if(random()<0.015*sq((seasonCurve(b.tick)+1)/2)) b.spawnArchetype('tw');

// extratropical cyclones
if(random()<0.01-0.002*seasonalSine(b.tick)) b.spawnArchetype('ex');
if(random()<0.01-0.002*seasonCurve(b.tick)) b.spawnArchetype('ex');
};

// -- Normal Mode -- //
Expand All @@ -179,9 +189,9 @@ SPAWN_RULES[SIM_MODE_NORMAL].doSpawn = SPAWN_RULES.defaults.doSpawn;
// -- Hyper Mode -- //

SPAWN_RULES[SIM_MODE_HYPER].doSpawn = function(b){
if(random()<(0.013*sq((seasonalSine(b.tick)+1)/2)+0.002)) b.spawnArchetype('tw');
if(random()<(0.013*sq((seasonCurve(b.tick)+1)/2)+0.002)) b.spawnArchetype('tw');

if(random()<0.01-0.002*seasonalSine(b.tick)) b.spawnArchetype('ex');
if(random()<0.01-0.002*seasonCurve(b.tick)) b.spawnArchetype('ex');
};

// -- Wild Mode -- //
Expand All @@ -202,15 +212,15 @@ SPAWN_RULES[SIM_MODE_WILD].archetypes = {

SPAWN_RULES[SIM_MODE_WILD].doSpawn = function(b){
if(random()<0.015) b.spawnArchetype('tw');
if(random()<0.01-0.002*seasonalSine(b.tick)) b.spawnArchetype('ex');
if(random()<0.01-0.002*seasonCurve(b.tick)) b.spawnArchetype('ex');
};

// -- Megablobs Mode -- //

SPAWN_RULES[SIM_MODE_MEGABLOBS].doSpawn = function(b){
if(random()<(0.013*sq((seasonalSine(b.tick)+1)/2)+0.002)) b.spawnArchetype('tw');
if(random()<(0.013*sq((seasonCurve(b.tick)+1)/2)+0.002)) b.spawnArchetype('tw');

if(random()<0.01-0.002*seasonalSine(b.tick)) b.spawnArchetype('ex');
if(random()<0.01-0.002*seasonCurve(b.tick)) b.spawnArchetype('ex');
};

// -- Experimental Mode -- //
Expand Down Expand Up @@ -267,6 +277,10 @@ SPAWN_RULES[SIM_MODE_EXPERIMENTAL].archetypes = {

SPAWN_RULES[SIM_MODE_EXPERIMENTAL].doSpawn = SPAWN_RULES[SIM_MODE_HYPER].doSpawn;

// -- Spooky Mode -- //

SPAWN_RULES[SIM_MODE_SPOOKY].doSpawn = SPAWN_RULES.defaults.doSpawn;


// ---- Definitions of Environmental Fields ---- //

Expand All @@ -278,6 +292,7 @@ ENV_DEFS[SIM_MODE_HYPER] = {}; // Same for "Hyper" simulation mode
ENV_DEFS[SIM_MODE_WILD] = {}; // "Wild" simulation mode
ENV_DEFS[SIM_MODE_MEGABLOBS] = {}; // "Megablobs" simulation mode
ENV_DEFS[SIM_MODE_EXPERIMENTAL] = {}; // "Experimental" simulation mode
ENV_DEFS[SIM_MODE_SPOOKY] = {}; // "Spooky" simulation mode

// -- Sample Env Field -- //

Expand Down Expand Up @@ -318,7 +333,7 @@ ENV_DEFS.defaults.jetstream = {
let antiPeakLat = u.modifiers.antiPeakLat;
let peakRange = u.modifiers.peakRange;
let antiPeakRange = u.modifiers.antiPeakRange;
let s = seasonalSine(z);
let s = seasonCurve(z);
let l = map(sqrt(map(s,-1,1,0,1)),0,1,antiPeakLat,peakLat);
let r = map(s,-1,1,antiPeakRange,peakRange);
v = map(v,0,1,-r,r);
Expand Down Expand Up @@ -363,6 +378,7 @@ ENV_DEFS[SIM_MODE_MEGABLOBS].jetstream = {
}
};
ENV_DEFS[SIM_MODE_EXPERIMENTAL].jetstream = {};
ENV_DEFS[SIM_MODE_SPOOKY].jetstream = {};

// -- LLSteering -- //

Expand Down Expand Up @@ -448,6 +464,7 @@ ENV_DEFS[SIM_MODE_WILD].LLSteering = {
};
ENV_DEFS[SIM_MODE_MEGABLOBS].LLSteering = {};
ENV_DEFS[SIM_MODE_EXPERIMENTAL].LLSteering = {};
ENV_DEFS[SIM_MODE_SPOOKY].LLSteering = {};

// -- ULSteering -- //

Expand All @@ -461,7 +478,7 @@ ENV_DEFS.defaults.ULSteering = {

let m = u.noise(1);

let s = seasonalSine(z);
let s = seasonCurve(z);
let j0 = u.field('jetstream'); // y-position of jetstream
let j1 = u.field('jetstream',x+dx); // y-position of jetstream dx to the east for differential
let j = abs(y-j0); // distance of point north/south of jetstream
Expand Down Expand Up @@ -572,6 +589,7 @@ ENV_DEFS[SIM_MODE_WILD].ULSteering = {
};
ENV_DEFS[SIM_MODE_MEGABLOBS].ULSteering = {};
ENV_DEFS[SIM_MODE_EXPERIMENTAL].ULSteering = {};
ENV_DEFS[SIM_MODE_SPOOKY].ULSteering = {};

// -- shear -- //

Expand Down Expand Up @@ -613,6 +631,7 @@ ENV_DEFS[SIM_MODE_HYPER].shear = {};
ENV_DEFS[SIM_MODE_WILD].shear = {};
ENV_DEFS[SIM_MODE_MEGABLOBS].shear = {};
ENV_DEFS[SIM_MODE_EXPERIMENTAL].shear = {};
ENV_DEFS[SIM_MODE_SPOOKY].shear = {};

// -- SSTAnomaly -- //

Expand Down Expand Up @@ -676,6 +695,7 @@ ENV_DEFS[SIM_MODE_MEGABLOBS].SSTAnomaly = {
}
};
ENV_DEFS[SIM_MODE_EXPERIMENTAL].SSTAnomaly = {};
ENV_DEFS[SIM_MODE_SPOOKY].SSTAnomaly = {};

// -- SST -- //

Expand All @@ -685,7 +705,7 @@ ENV_DEFS.defaults.SST = {
mapFunc: (u,x,y,z)=>{
if(y<0) return 0;
let anom = u.field('SSTAnomaly');
let s = seasonalSine(z);
let s = seasonCurve(z);
let w = map(cos(map(x,0,WIDTH,0,PI)),-1,1,0,1);
let h0 = y/HEIGHT;
let h1 = (sqrt(h0)+h0)/2;
Expand Down Expand Up @@ -763,6 +783,7 @@ ENV_DEFS[SIM_MODE_EXPERIMENTAL].SST = {
peakSeasonTropicsTemp: 28
}
};
ENV_DEFS[SIM_MODE_SPOOKY].SST = {};

// -- moisture -- //

Expand All @@ -771,7 +792,7 @@ ENV_DEFS.defaults.moisture = {
version: 0,
mapFunc: (u,x,y,z)=>{
let v = u.noise(0);
let s = seasonalSine(z);
let s = seasonCurve(z);
let l = land.get(Coordinate.convertFromXY(u.basin.mapType, x, u.basin.hemY(y)));
let pm = u.modifiers.polarMoisture;
let tm = u.modifiers.tropicalMoisture;
Expand Down Expand Up @@ -827,6 +848,7 @@ ENV_DEFS[SIM_MODE_WILD].moisture = {
};
ENV_DEFS[SIM_MODE_MEGABLOBS].moisture = {};
ENV_DEFS[SIM_MODE_EXPERIMENTAL].moisture = {};
ENV_DEFS[SIM_MODE_SPOOKY].moisture = {};

// ---- Active Storm System Algorithm ---- //

Expand All @@ -838,6 +860,7 @@ STORM_ALGORITHM[SIM_MODE_HYPER] = {};
STORM_ALGORITHM[SIM_MODE_WILD] = {};
STORM_ALGORITHM[SIM_MODE_MEGABLOBS] = {};
STORM_ALGORITHM[SIM_MODE_EXPERIMENTAL] = {};
STORM_ALGORITHM[SIM_MODE_SPOOKY] = {};

// -- Interaction -- //

Expand Down Expand Up @@ -1050,6 +1073,7 @@ STORM_ALGORITHM[SIM_MODE_HYPER].version = 0;
STORM_ALGORITHM[SIM_MODE_WILD].version = 0;
STORM_ALGORITHM[SIM_MODE_MEGABLOBS].version = 0;
STORM_ALGORITHM[SIM_MODE_EXPERIMENTAL].version = 1;
STORM_ALGORITHM[SIM_MODE_SPOOKY].version = 0;

// -- Upgrade -- //
// Converts active attributes in case an active system is loaded after an algorithm change breaks old values
Expand Down Expand Up @@ -1078,4 +1102,8 @@ STORM_ALGORITHM[SIM_MODE_EXPERIMENTAL].upgrade = function(sys,data,oldVersion){
sys.depth = data.depth;
sys.kaboom = 0;
}
};
};

// STORM_ALGORITHM[SIM_MODE_SPOOKY].upgrade = function(sys,data,oldVersion){

// };
3 changes: 2 additions & 1 deletion sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ var paused,
selectedStorm,
renderToDo,
oldMouseX,
oldMouseY;
oldMouseY,
seasonCurve;

function setup(){
setVersion(TITLE + " v",VERSION_NUMBER);
Expand Down
2 changes: 1 addition & 1 deletion ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ UI.init = function(){
}
drawBuffer(landBuffer);
if(simSettings.snowLayers){
if(land.snowDrawn) drawBuffer(snow[floor(map(seasonalSine(viewTick,SNOW_SEASON_OFFSET),-1,1,0,simSettings.snowLayers*10))]);
if(land.snowDrawn) drawBuffer(snow[floor(map(seasonCurve(viewTick,SNOW_SEASON_OFFSET),-1,1,0,simSettings.snowLayers*10))]);
else renderToDo = land.drawSnow();
}
if(simSettings.useShadows){
Expand Down

0 comments on commit 9c7be01

Please sign in to comment.