Skip to content

Commit

Permalink
Merge pull request doublespeakgames#57 from Vermilingua/prestige
Browse files Browse the repository at this point in the history
Prestige System
  • Loading branch information
Continuities committed Oct 16, 2013
2 parents 63a6d98 + 83bf266 commit a895a35
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 10 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<script src="script/path.js"></script>
<script src="script/ship.js"></script>
<script src="script/space.js"></script>
<script src="script/prestige.js"></script>
<!-- Event modules -->
<script src="script/events/global.js"></script>
<script src="script/events/room.js"></script>
Expand Down
6 changes: 6 additions & 0 deletions lib/jquery.min.js

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions script/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var Engine = {
VERSION: 1.3,
MAX_STORE: 99999999999999,
SAVE_DISPLAY: 30 * 1000,
GAME_OVER: false,

//object event types
topics: {},
Expand Down Expand Up @@ -206,9 +207,11 @@ var Engine = {
},

deleteSave: function() {
if(typeof Storage != 'undefined' && localStorage) {
localStorage.clear();
}
if (!Engine.GAME_OVER) {
if(typeof Storage != 'undefined' && localStorage) {
localStorage.clear();
}
}
location.reload();
},

Expand Down
50 changes: 50 additions & 0 deletions script/events/setpieces.js
Original file line number Diff line number Diff line change
Expand Up @@ -3392,5 +3392,55 @@ Events.Setpieces = {
}
}
}
},
"cache": { /* Cache - contains some of supplies from previous game */
title: 'A Destroyed Village',
scenes: {
'start': {
text: [
'a destroyed village stands before you',
'charred bodies littering the ground.'
],
notification: 'you smell the metallic tang of a wanderer afterburner.',
buttons: {
'enter': {
text: 'enter',
nextScene: {1: 'underground'}
},
'leave': {
text: 'leave',
nextScene: 'end'
}
}
},
'underground': {
text: [
'a shack stands at the center of the village.',
'there are still supplies inside.'
],
buttons: {
'take': {
text: 'take',
nextScene: {1: 'exit'}
}
}
},
'exit': {
text: [
'all the work of a previous generation is here.',
'ripe for the picking.'
],
onLoad: function() {
World.markVisited(World.curPos[0], World.curPos[1]);
Prestige.load();
},
buttons: {
'leave': {
text: 'leave',
nextScene: 'end'
}
}
}
}
}
};
103 changes: 103 additions & 0 deletions script/prestige.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
var Prestige = {
name: 'Prestige',

options: {},

init: function(options) {
this.options = $.extend(
this.options,
options
);
},

save: function() {
var prevStores = [ //g = goods, w = weapons, a = ammo
Math.floor($SM.get('stores["wood"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["fur"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["meat"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["iron"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["coal"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["sulphur"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["steel"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["cured meat"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["scales"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["teeth"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["leather"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["bait"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["torch"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["cloth"]') / Prestige.randGen('g')),
Math.floor($SM.get('stores["bone spear"]') / Prestige.randGen('w')),
Math.floor($SM.get('stores["iron sword"]') / Prestige.randGen('w')),
Math.floor($SM.get('stores["steel sword"]') / Prestige.randGen('w')),
Math.floor($SM.get('stores["bayonet"]') / Prestige.randGen('w')),
Math.floor($SM.get('stores["rifle"]') / Prestige.randGen('w')),
Math.floor($SM.get('stores["laser rifle"]') / Prestige.randGen('w')),
Math.floor($SM.get('stores["bullets"]') / Prestige.randGen('a')),
Math.floor($SM.get('stores["energy cell"]') / Prestige.randGen('a')),
Math.floor($SM.get('stores["grenade"]') / Prestige.randGen('a')),
Math.floor($SM.get('stores["bolas"]') / Prestige.randGen('a'))
];
for (var n = 0;n<=23;n++) {
if (isNaN(prevStores[n])) {prevStores[n] = 0};
}
$SM.set('previous.stores', prevStores);
return prevStores;
},

populateNewSave: function(newstate) {
State = {
previous: {
stores: newstate
}
};
Engine.init({state: State});
return State;
},

load: function() {
var prevStores = $SM.get('previous.stores');
$SM.add('stores["wood"]',prevStores[0]),
$SM.add('stores["fur"]',prevStores[1]),
$SM.add('stores["meat"]',prevStores[2]),
$SM.add('stores["iron"]',prevStores[3]),
$SM.add('stores["coal"]',prevStores[4]),
$SM.add('stores["sulphur"]',prevStores[5]),
$SM.add('stores["steel"]',prevStores[6]),
$SM.add('stores["cured meat"]',prevStores[7]),
$SM.add('stores["scales"]',prevStores[8]),
$SM.add('stores["teeth"]',prevStores[9]),
$SM.add('stores["leather"]',prevStores[10]),
$SM.add('stores["bait"]',prevStores[11]),
$SM.add('stores["torch"]',prevStores[12]),
$SM.add('stores["cloth"]',prevStores[13]),
$SM.add('stores["bone spear"]',prevStores[14]),
$SM.add('stores["iron sword"]',prevStores[15]),
$SM.add('stores["steel sword"]',prevStores[16]),
$SM.add('stores["bayonet"]',prevStores[17]),
$SM.add('stores["rifle"]',prevStores[18]),
$SM.add('stores["laser rifle"]',prevStores[19]),
$SM.add('stores["bullets"]',prevStores[20]),
$SM.add('stores["energy cell"]',prevStores[21]),
$SM.add('stores["grenade"]',prevStores[22]),
$SM.add('stores["bolas"]',prevStores[23])
return prevStores;
},

randGen: function(storeType) {
if (storeType == 'g') {
divisor = Math.floor(Math.random()*10)
}
else if (storeType == 'w') {
divisor = Math.floor(Math.floor(Math.random()*10)/2)
}
else if (storeType == 'a') {
divisor = Math.ceil(Math.random()*10*Math.ceil(Math.random()*10))
}
else { divisor = 1 };
if (divisor === 0) {
divisor = 1
};
return divisor;
}

}
11 changes: 9 additions & 2 deletions script/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,18 @@ var Space = {
$('#notifyGradient').attr('style', 'background-color:'+cur+';background:-webkit-' + s + ';background:' + s);
},
complete: function() {
$('#starsContainer').remove();
Engine.GAME_OVER = true;
var backup;
$('#starsContainer').remove();
if(typeof Storage != 'undefined' && localStorage) {
localStorage.clear();
backup = Prestige.save();
localStorage.clear();
}
delete window.State;
$('.deleteSave, .share').remove();
Prestige.populateNewSave(backup);
$('#content, #notifications').remove();
$('.deleteSave, .share').attr('style', 'color: white;');
Engine.options = {};
}
});
Expand Down
12 changes: 7 additions & 5 deletions script/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var World = {
SHIP: 'W',
BOREHOLE: 'B',
BATTLEFIELD: 'F',
SWAMP: 'M'
SWAMP: 'M',
CACHE: 'U'
},
TILE_PROBS: {},
LANDMARKS: {},
Expand Down Expand Up @@ -123,10 +124,11 @@ var World = {
World.LANDMARKS[World.TILE.CAVE] = { num: 5, minRadius: 3, maxRadius: 10, scene: 'cave', label: 'A&nbsp;Damp&nbsp;Cave' };
World.LANDMARKS[World.TILE.TOWN] = { num: 10, minRadius: 10, maxRadius: 20, scene: 'town', label: 'An&nbsp;Abandoned&nbsp;Town' };
World.LANDMARKS[World.TILE.CITY] = { num: 20, minRadius: 20, maxRadius: World.RADIUS * 1.5, scene: 'city', label: 'A&nbsp;Ruined&nbsp;City' };
World.LANDMARKS[World.TILE.SHIP] = {num: 1, minRadius: 28, maxRadius: 28, scene: 'ship', label: 'A&nbsp;Crashed&nbsp;Starship'};
World.LANDMARKS[World.TILE.BOREHOLE] = {num: 10, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'borehole', label: 'A&nbsp;Borehole'};
World.LANDMARKS[World.TILE.BATTLEFIELD] = {num: 5, minRadius: 18, maxRadius: World.RADIUS * 1.5, scene: 'battlefield', label: 'A&nbsp;Battlefield'};
World.LANDMARKS[World.TILE.SWAMP] = {num: 1, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'swamp', label: 'A&nbsp;Murky&nbsp;Swamp'};
World.LANDMARKS[World.TILE.SHIP] = { num: 1, minRadius: 28, maxRadius: 28, scene: 'ship', label: 'A&nbsp;Crashed&nbsp;Starship'};
World.LANDMARKS[World.TILE.BOREHOLE] = { num: 10, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'borehole', label: 'A&nbsp;Borehole'};
World.LANDMARKS[World.TILE.BATTLEFIELD] = { num: 5, minRadius: 18, maxRadius: World.RADIUS * 1.5, scene: 'battlefield', label: 'A&nbsp;Battlefield'};
World.LANDMARKS[World.TILE.SWAMP] = { num: 1, minRadius: 15, maxRadius: World.RADIUS * 1.5, scene: 'swamp', label: 'A&nbsp;Murky&nbsp;Swamp'};
World.LANDMARKS[World.TILE.CACHE] = { num: 1, minRadius: 10, maxRadius: World.RADIUS * 1.5, scene: 'cache', label: 'A&nbsp;Destroyed&nbsp;Village'};

if(typeof $SM.get('features.location.world') == 'undefined') {
$SM.set('features.location.world', true);
Expand Down

0 comments on commit a895a35

Please sign in to comment.