Merging updates

This commit is contained in:
Travis Weston
2015-02-11 18:55:27 -05:00
parent 7c978f4f15
commit 6ee6470972
10 changed files with 6063 additions and 6063 deletions
+740 -740
View File
File diff suppressed because it is too large Load Diff
+850 -850
View File
File diff suppressed because it is too large Load Diff
+282 -282
View File
@@ -1,282 +1,282 @@
/**
* Events that can occur when the Outside module is active
**/
Events.Outside = [
{ /* Ruined traps */
title: _('A Ruined Trap'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.buildings["trap"]', true) > 0;
},
scenes: {
'start': {
text: [
_('some of the traps have been torn apart.'),
_('large prints lead away, into the forest.')
],
onLoad: function() {
var numWrecked = Math.floor(Math.random() * $SM.get('game.buildings["trap"]', true)) + 1;
$SM.add('game.buildings["trap"]', -numWrecked);
Outside.updateVillage();
Outside.updateTrapButton();
},
notification: _('some traps have been destroyed'),
blink: true,
buttons: {
'track': {
text: _('track them'),
nextScene: {0.5: 'nothing', 1: 'catch'}
},
'ignore': {
text: _('ignore them'),
nextScene: 'end'
}
}
},
'nothing': {
text: [
_('the tracks disappear after just a few minutes.'),
_('the forest is silent.')
],
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
},
'catch': {
text: [
_('not far from the village lies a large beast, its fur matted with blood.'),
_('it puts up little resistance before the knife.')
],
reward: {
fur: 100,
meat: 100,
teeth: 10
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{
title: _('Fire'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.buildings["hut"]', true) > 0 && $SM.get('game.population', true) > 5;
},
scenes: {
'start': {
text: [
_('a fire rampages through one of the huts, destroying it.'),
_('all residents in the hut perished in the fire.')
],
notification: _('a fire has started'),
blink: true,
onLoad: function() {
var population = $SM.get('game.population', true);
var huts = $SM.get('game.buildings["hut"]', true);
$SM.set('game.buildings["hut"]', (huts - 1));
$SM.set('game.population', (population - 4));
},
buttons: {
'mourn': {
text: _('mourn'),
notification: _('some villagers have died'),
nextScene: 'end'
}
}
}
}
},
{ /* Sickness */
title: _('Sickness'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 10 && $SM.get('game.population', true) < 50 && $SM.get('stores.medicine', true) > 0;
},
scenes: {
'start': {
text: [
_('a sickness is spreading through the village.'),
_('medicine is needed immediately.')
],
blink: true,
buttons: {
'heal': {
text: _('1 medicine'),
cost: { 'medicine' : 1 },
nextScene: {1: 'healed'}
},
'ignore': {
text: _('ignore it'),
nextScene: {1: 'death'}
}
}
},
'healed': {
text: [
_('the sickness is cured in time.')
],
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
},
'death': {
text: [
_('the sickness spreads through the village.'),
_('the days are spent with burials.'),
_('the nights are rent with screams.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 20) + 1;
Outside.killVillagers(numKilled);
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{ /* Plague */
title: _('Plague'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 50 && $SM.get('stores.medicine', true) > 0;
},
scenes: {
'start': {
text: [
_('a terrible plague is fast spreading through the village.'),
_('medicine is needed immediately.')
],
blink: true,
buttons: {
/* Because there is a serious need for medicine, the price is raised. */
'buyMedicine': {
text: _('buy medicine'),
cost: { 'scales': 70,
'teeth': 50 },
reward: { 'medicine': 1 }
},
'heal': {
text: _('5 medicine'),
cost: { 'medicine' : 5 },
nextScene: {1: 'healed'}
},
'ignore': {
text: _('do nothing'),
nextScene: {1: 'death'}
}
}
},
'healed': {
text: [
_('the plague is kept from spreading.'),
_('only a few die.'),
_('the rest bury them.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 5) + 2;
Outside.killVillagers(numKilled);
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
},
'death': {
text: [
_('the plague rips through the village.'),
_('the nights are rent with screams.'),
_('the only hope is a quick death.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 80) + 10;
Outside.killVillagers(numKilled);
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{ /* Beast attack */
title: _('A Beast Attack'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0;
},
scenes: {
'start': {
text: [
_('a pack of snarling beasts pours out of the trees.'),
_('the fight is short and bloody, but the beasts are repelled.'),
_('the villagers retreat to mourn the dead.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 10) + 1;
Outside.killVillagers(numKilled);
},
reward: {
fur: 100,
meat: 100,
teeth: 10
},
blink: true,
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{ /* Soldier attack */
title: _('A Military Raid'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0 && $SM.get('game.cityCleared');
},
scenes: {
'start': {
text: [
_('a gunshot rings through the trees.'),
_('well armed men charge out of the forest, firing into the crowd.'),
_('after a skirmish they are driven away, but not without losses.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 40) + 1;
Outside.killVillagers(numKilled);
},
reward: {
bullets: 10,
'cured meat': 50
},
blink: true,
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
}
];
/**
* Events that can occur when the Outside module is active
**/
Events.Outside = [
{ /* Ruined traps */
title: _('A Ruined Trap'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.buildings["trap"]', true) > 0;
},
scenes: {
'start': {
text: [
_('some of the traps have been torn apart.'),
_('large prints lead away, into the forest.')
],
onLoad: function() {
var numWrecked = Math.floor(Math.random() * $SM.get('game.buildings["trap"]', true)) + 1;
$SM.add('game.buildings["trap"]', -numWrecked);
Outside.updateVillage();
Outside.updateTrapButton();
},
notification: _('some traps have been destroyed'),
blink: true,
buttons: {
'track': {
text: _('track them'),
nextScene: {0.5: 'nothing', 1: 'catch'}
},
'ignore': {
text: _('ignore them'),
nextScene: 'end'
}
}
},
'nothing': {
text: [
_('the tracks disappear after just a few minutes.'),
_('the forest is silent.')
],
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
},
'catch': {
text: [
_('not far from the village lies a large beast, its fur matted with blood.'),
_('it puts up little resistance before the knife.')
],
reward: {
fur: 100,
meat: 100,
teeth: 10
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{
title: _('Fire'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.buildings["hut"]', true) > 0 && $SM.get('game.population', true) > 5;
},
scenes: {
'start': {
text: [
_('a fire rampages through one of the huts, destroying it.'),
_('all residents in the hut perished in the fire.')
],
notification: _('a fire has started'),
blink: true,
onLoad: function() {
var population = $SM.get('game.population', true);
var huts = $SM.get('game.buildings["hut"]', true);
$SM.set('game.buildings["hut"]', (huts - 1));
$SM.set('game.population', (population - 4));
},
buttons: {
'mourn': {
text: _('mourn'),
notification: _('some villagers have died'),
nextScene: 'end'
}
}
}
}
},
{ /* Sickness */
title: _('Sickness'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 10 && $SM.get('game.population', true) < 50 && $SM.get('stores.medicine', true) > 0;
},
scenes: {
'start': {
text: [
_('a sickness is spreading through the village.'),
_('medicine is needed immediately.')
],
blink: true,
buttons: {
'heal': {
text: _('1 medicine'),
cost: { 'medicine' : 1 },
nextScene: {1: 'healed'}
},
'ignore': {
text: _('ignore it'),
nextScene: {1: 'death'}
}
}
},
'healed': {
text: [
_('the sickness is cured in time.')
],
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
},
'death': {
text: [
_('the sickness spreads through the village.'),
_('the days are spent with burials.'),
_('the nights are rent with screams.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 20) + 1;
Outside.killVillagers(numKilled);
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{ /* Plague */
title: _('Plague'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 50 && $SM.get('stores.medicine', true) > 0;
},
scenes: {
'start': {
text: [
_('a terrible plague is fast spreading through the village.'),
_('medicine is needed immediately.')
],
blink: true,
buttons: {
/* Because there is a serious need for medicine, the price is raised. */
'buyMedicine': {
text: _('buy medicine'),
cost: { 'scales': 70,
'teeth': 50 },
reward: { 'medicine': 1 }
},
'heal': {
text: _('5 medicine'),
cost: { 'medicine' : 5 },
nextScene: {1: 'healed'}
},
'ignore': {
text: _('do nothing'),
nextScene: {1: 'death'}
}
}
},
'healed': {
text: [
_('the plague is kept from spreading.'),
_('only a few die.'),
_('the rest bury them.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 5) + 2;
Outside.killVillagers(numKilled);
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
},
'death': {
text: [
_('the plague rips through the village.'),
_('the nights are rent with screams.'),
_('the only hope is a quick death.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 80) + 10;
Outside.killVillagers(numKilled);
},
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{ /* Beast attack */
title: _('A Beast Attack'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0;
},
scenes: {
'start': {
text: [
_('a pack of snarling beasts pours out of the trees.'),
_('the fight is short and bloody, but the beasts are repelled.'),
_('the villagers retreat to mourn the dead.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 10) + 1;
Outside.killVillagers(numKilled);
},
reward: {
fur: 100,
meat: 100,
teeth: 10
},
blink: true,
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
},
{ /* Soldier attack */
title: _('A Military Raid'),
isAvailable: function() {
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0 && $SM.get('game.cityCleared');
},
scenes: {
'start': {
text: [
_('a gunshot rings through the trees.'),
_('well armed men charge out of the forest, firing into the crowd.'),
_('after a skirmish they are driven away, but not without losses.')
],
onLoad: function() {
var numKilled = Math.floor(Math.random() * 40) + 1;
Outside.killVillagers(numKilled);
},
reward: {
bullets: 10,
'cured meat': 50
},
blink: true,
buttons: {
'end': {
text: _('go home'),
nextScene: 'end'
}
}
}
}
}
];
+603 -603
View File
File diff suppressed because it is too large Load Diff
+78 -78
View File
@@ -1,78 +1,78 @@
/**
* Module that registers the notification box and handles messages
*/
var Notifications = {
init: function(options) {
this.options = $.extend(
this.options,
options
);
// Create the notifications box
elem = $('<div>').attr({
id: 'notifications',
className: 'notifications'
});
// Create the transparency gradient
$('<div>').attr('id', 'notifyGradient').appendTo(elem);
elem.appendTo('div#wrapper');
},
options: {}, // Nothing for now
elem: null,
notifyQueue: {},
// Allow notification to the player
notify: function(module, text, noQueue) {
if(typeof text == 'undefined') return;
if(text.slice(-1) != ".") text += ".";
if(module != null && Engine.activeModule != module) {
if(!noQueue) {
if(typeof this.notifyQueue[module] == 'undefined') {
this.notifyQueue[module] = [];
}
this.notifyQueue[module].push(text);
}
} else {
Notifications.printMessage(text);
}
Engine.saveGame();
},
clearHidden: function() {
// To fix some memory usage issues, we clear notifications that have been hidden.
// We use position().top here, because we know that the parent will be the same, so the position will be the same.
var bottom = $('#notifyGradient').position().top + $('#notifyGradient').outerHeight(true);
$('.notification').each(function() {
if($(this).position().top > bottom){
$(this).remove();
}
});
},
printMessage: function(t) {
var text = $('<div>').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications');
text.animate({opacity: 1}, 500, 'linear', function() {
// Do this every time we add a new message, this way we never have a large backlog to iterate through. Keeps things faster.
Notifications.clearHidden();
});
},
printQueue: function(module) {
if(typeof this.notifyQueue[module] != 'undefined') {
while(this.notifyQueue[module].length > 0) {
Notifications.printMessage(this.notifyQueue[module].shift());
}
}
}
};
/**
* Module that registers the notification box and handles messages
*/
var Notifications = {
init: function(options) {
this.options = $.extend(
this.options,
options
);
// Create the notifications box
elem = $('<div>').attr({
id: 'notifications',
className: 'notifications'
});
// Create the transparency gradient
$('<div>').attr('id', 'notifyGradient').appendTo(elem);
elem.appendTo('div#wrapper');
},
options: {}, // Nothing for now
elem: null,
notifyQueue: {},
// Allow notification to the player
notify: function(module, text, noQueue) {
if(typeof text == 'undefined') return;
if(text.slice(-1) != ".") text += ".";
if(module != null && Engine.activeModule != module) {
if(!noQueue) {
if(typeof this.notifyQueue[module] == 'undefined') {
this.notifyQueue[module] = [];
}
this.notifyQueue[module].push(text);
}
} else {
Notifications.printMessage(text);
}
Engine.saveGame();
},
clearHidden: function() {
// To fix some memory usage issues, we clear notifications that have been hidden.
// We use position().top here, because we know that the parent will be the same, so the position will be the same.
var bottom = $('#notifyGradient').position().top + $('#notifyGradient').outerHeight(true);
$('.notification').each(function() {
if($(this).position().top > bottom){
$(this).remove();
}
});
},
printMessage: function(t) {
var text = $('<div>').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications');
text.animate({opacity: 1}, 500, 'linear', function() {
// Do this every time we add a new message, this way we never have a large backlog to iterate through. Keeps things faster.
Notifications.clearHidden();
});
},
printQueue: function(module) {
if(typeof this.notifyQueue[module] != 'undefined') {
while(this.notifyQueue[module].length > 0) {
Notifications.printMessage(this.notifyQueue[module].shift());
}
}
}
};
+615 -615
View File
File diff suppressed because it is too large Load Diff
+317 -317
View File
@@ -1,317 +1,317 @@
var Path = {
DEFAULT_BAG_SPACE: 10,
// Everything not in this list weighs 1
Weight: {
'bone spear': 2,
'iron sword': 3,
'steel sword': 5,
'rifle': 5,
'bullets': 0.1,
'energy cell': 0.2,
'laser rifle': 5,
'bolas': 0.5
},
name: 'Path',
options: {}, // Nuthin'
init: function(options) {
this.options = $.extend(
this.options,
options
);
// Init the World
World.init();
// Create the path tab
this.tab = Header.addLocation(_("A Dusty Path"), "path", Path);
// Create the Path panel
this.panel = $('<div>').attr('id', "pathPanel")
.addClass('location')
.appendTo('div#locationSlider');
// Add the outfitting area
var outfitting = $('<div>').attr('id', 'outfitting').appendTo(this.panel);
$('<div>').attr('id', 'bagspace').appendTo(outfitting);
// Add the embark button
new Button.Button({
id: 'embarkButton',
text: _("embark"),
click: Path.embark,
width: '80px',
cooldown: World.DEATH_COOLDOWN
}).appendTo(this.panel);
Path.outfit = $SM.get('outfit');
Engine.updateSlider();
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Path.handleStateUpdates);
},
openPath: function() {
Path.init();
Engine.event('progress', 'path');
Notifications.notify(Room, _('the compass points ' + World.dir));
},
getWeight: function(thing) {
var w = Path.Weight[thing];
if(typeof w != 'number') w = 1;
return w;
},
getCapacity: function() {
if($SM.get('stores.convoy', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 60;
} else if($SM.get('stores.wagon', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 30;
} else if($SM.get('stores.rucksack', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 10;
}
return Path.DEFAULT_BAG_SPACE;
},
getFreeSpace: function() {
var num = 0;
if(Path.outfit) {
for(var k in Path.outfit) {
var n = Path.outfit[k];
if(isNaN(n)) {
// No idea how this happens, but I will fix it here!
Path.outfit[k] = n = 0;
}
num += n * Path.getWeight(k);
}
}
return Path.getCapacity() - num;
},
updatePerks: function(ignoreStores) {
if($SM.get('character.perks')) {
var perks = $('#perks');
var needsAppend = false;
if(perks.length === 0) {
needsAppend = true;
perks = $('<div>').attr('id', 'perks');
}
for(var k in $SM.get('character.perks')) {
var id = 'perk_' + k.replace(' ', '-');
var r = $('#' + id);
if($SM.get('character.perks["'+k+'"]') && r.length === 0) {
r = $('<div>').attr('id', id).addClass('perkRow').appendTo(perks);
$('<div>').addClass('row_key').text(_(k)).appendTo(r);
$('<div>').addClass('tooltip bottom right').text(Engine.Perks[k].desc).appendTo(r);
}
}
if(needsAppend && perks.children().length > 0) {
perks.appendTo(Path.panel);
}
if(!ignoreStores && Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
}
}
},
updateOutfitting: function() {
var outfit = $('div#outfitting');
if(!Path.outfit) {
Path.outfit = {};
}
// Add the armour row
var armour = _("none");
if($SM.get('stores["s armour"]', true) > 0)
armour = _("steel");
else if($SM.get('stores["i armour"]', true) > 0)
armour = _("iron");
else if($SM.get('stores["l armour"]', true) > 0)
armour = _("leather");
var aRow = $('#armourRow');
if(aRow.length === 0) {
aRow = $('<div>').attr('id', 'armourRow').addClass('outfitRow').prependTo(outfit);
$('<div>').addClass('row_key').text(_('armour')).appendTo(aRow);
$('<div>').addClass('row_val').text(armour).appendTo(aRow);
$('<div>').addClass('clear').appendTo(aRow);
} else {
$('.row_val', aRow).text(armour);
}
// Add the water row
var wRow = $('#waterRow');
if(wRow.length === 0) {
wRow = $('<div>').attr('id', 'waterRow').addClass('outfitRow').insertAfter(aRow);
$('<div>').addClass('row_key').text(_('water')).appendTo(wRow);
$('<div>').addClass('row_val').text(World.getMaxWater()).appendTo(wRow);
$('<div>').addClass('clear').appendTo(wRow);
} else {
$('.row_val', wRow).text(World.getMaxWater());
}
var space = Path.getFreeSpace();
var total = 0;
// Add the non-craftables to the craftables
var carryable = $.extend({
'cured meat': { type: 'tool' },
'bullets': { type: 'tool' },
'grenade': {type: 'weapon' },
'bolas': {type: 'weapon' },
'laser rifle': {type: 'weapon' },
'energy cell': {type: 'tool' },
'bayonet': {type: 'weapon' },
'charm': {type: 'tool'},
'medicine': {type: 'tool'}
}, Room.Craftables);
for(var k in carryable) {
var store = carryable[k];
var have = $SM.get('stores["'+k+'"]');
var num = Path.outfit[k];
num = typeof num == 'number' ? num : 0;
if (have < num) { num = have; }
var numAvailable = $SM.get('stores["'+k+'"]', true);
var row = $('div#outfit_row_' + k.replace(' ', '-'), outfit);
if((store.type == 'tool' || store.type == 'weapon') && have > 0) {
total += num * Path.getWeight(k);
if(row.length === 0) {
row = Path.createOutfittingRow(k, num, store.name);
var curPrev = null;
outfit.children().each(function(i) {
var child = $(this);
if(child.attr('id').indexOf('outfit_row_') === 0) {
var cName = child.attr('id').substring(11).replace('-', ' ');
if(cName < k && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
}
});
if(curPrev == null) {
row.insertAfter(wRow);
}
else
{
row.insertAfter(outfit.find('#outfit_row_' + curPrev.replace(' ', '-')));
}
} else {
$('div#' + row.attr('id') + ' > div.row_val > span', outfit).text(num);
$('div#' + row.attr('id') + ' .tooltip .numAvailable', outfit).text(numAvailable - num);
}
if(num === 0) {
$('.dnBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
if(num >= numAvailable || space < Path.getWeight(k)) {
$('.upBtn', row).addClass('disabled');
$('.upManyBtn', row).addClass('disabled');
} else if(space >= Path.getWeight(k)) {
$('.upBtn', row).removeClass('disabled');
$('.upManyBtn', row).removeClass('disabled');
}
} else if(have === 0 && row.length > 0) {
row.remove();
}
}
// Update bagspace
$('#bagspace').text(_('free {0}/{1}', Math.floor(Path.getCapacity() - total) , Path.getCapacity()));
if(Path.outfit['cured meat'] > 0) {
Button.setDisabled($('#embarkButton'), false);
} else {
Button.setDisabled($('#embarkButton'), true);
}
},
createOutfittingRow: function(key, num, name) {
if(!name) name = _(key);
var row = $('<div>').attr('id', 'outfit_row_' + key.replace(' ', '-')).addClass('outfitRow').attr('key',key);
$('<div>').addClass('row_key').text(name).appendTo(row);
var val = $('<div>').addClass('row_val').appendTo(row);
$('<span>').text(num).appendTo(val);
$('<div>').addClass('upBtn').appendTo(val).click([1], Path.increaseSupply);
$('<div>').addClass('dnBtn').appendTo(val).click([1], Path.decreaseSupply);
$('<div>').addClass('upManyBtn').appendTo(val).click([10], Path.increaseSupply);
$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Path.decreaseSupply);
$('<div>').addClass('clear').appendTo(row);
var numAvailable = $SM.get('stores["'+key+'"]', true);
var tt = $('<div>').addClass('tooltip bottom right').appendTo(row);
$('<div>').addClass('row_key').text(_('weight')).appendTo(tt);
$('<div>').addClass('row_val').text(Path.getWeight(key)).appendTo(tt);
$('<div>').addClass('row_key').text(_('available')).appendTo(tt);
$('<div>').addClass('row_val').addClass('numAvailable').text(numAvailable).appendTo(tt);
return row;
},
increaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').attr('key');
Engine.log('increasing ' + supply + ' by up to ' + btn.data);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(Path.getFreeSpace() >= Path.getWeight(supply) && cur < $SM.get('stores["'+supply+'"]', true)) {
var maxExtraByWeight = Math.floor(Path.getFreeSpace() / Path.getWeight(supply));
var maxExtraByStore = $SM.get('stores["'+supply+'"]', true) - cur;
var maxExtraByBtn = btn.data;
Path.outfit[supply] = cur + Math.min(maxExtraByBtn, Math.min(maxExtraByWeight, maxExtraByStore));
$SM.set('outfit['+supply+']', Path.outfit[supply]);
Path.updateOutfitting();
}
},
decreaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').attr('key');
Engine.log('decreasing ' + supply + ' by up to ' + btn.data);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(cur > 0) {
Path.outfit[supply] = Math.max(0, cur - btn.data);
$SM.set('outfit['+supply+']', Path.outfit[supply]);
Path.updateOutfitting();
}
},
onArrival: function(transition_diff) {
Path.setTitle();
Path.updateOutfitting();
Path.updatePerks(true);
$SM.set('outfit', Path.outfit);
Engine.moveStoresView($('#perks'), transition_diff);
},
setTitle: function() {
document.title = _('A Dusty Path');
},
embark: function() {
for(var k in Path.outfit) {
$SM.add('stores["'+k+'"]', -Path.outfit[k]);
}
$SM.remove('outfit');
World.onArrival();
$('#outerSlider').animate({left: '-700px'}, 300);
Engine.activeModule = World;
},
handleStateUpdates: function(e){
if(e.category == 'character' && e.stateName.indexOf('character.perks') === 0 && Engine.activeModule == Path){
Path.updatePerks();
}
}
};
var Path = {
DEFAULT_BAG_SPACE: 10,
// Everything not in this list weighs 1
Weight: {
'bone spear': 2,
'iron sword': 3,
'steel sword': 5,
'rifle': 5,
'bullets': 0.1,
'energy cell': 0.2,
'laser rifle': 5,
'bolas': 0.5
},
name: 'Path',
options: {}, // Nuthin'
init: function(options) {
this.options = $.extend(
this.options,
options
);
// Init the World
World.init();
// Create the path tab
this.tab = Header.addLocation(_("A Dusty Path"), "path", Path);
// Create the Path panel
this.panel = $('<div>').attr('id', "pathPanel")
.addClass('location')
.appendTo('div#locationSlider');
// Add the outfitting area
var outfitting = $('<div>').attr('id', 'outfitting').appendTo(this.panel);
$('<div>').attr('id', 'bagspace').appendTo(outfitting);
// Add the embark button
new Button.Button({
id: 'embarkButton',
text: _("embark"),
click: Path.embark,
width: '80px',
cooldown: World.DEATH_COOLDOWN
}).appendTo(this.panel);
Path.outfit = $SM.get('outfit');
Engine.updateSlider();
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Path.handleStateUpdates);
},
openPath: function() {
Path.init();
Engine.event('progress', 'path');
Notifications.notify(Room, _('the compass points ' + World.dir));
},
getWeight: function(thing) {
var w = Path.Weight[thing];
if(typeof w != 'number') w = 1;
return w;
},
getCapacity: function() {
if($SM.get('stores.convoy', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 60;
} else if($SM.get('stores.wagon', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 30;
} else if($SM.get('stores.rucksack', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 10;
}
return Path.DEFAULT_BAG_SPACE;
},
getFreeSpace: function() {
var num = 0;
if(Path.outfit) {
for(var k in Path.outfit) {
var n = Path.outfit[k];
if(isNaN(n)) {
// No idea how this happens, but I will fix it here!
Path.outfit[k] = n = 0;
}
num += n * Path.getWeight(k);
}
}
return Path.getCapacity() - num;
},
updatePerks: function(ignoreStores) {
if($SM.get('character.perks')) {
var perks = $('#perks');
var needsAppend = false;
if(perks.length === 0) {
needsAppend = true;
perks = $('<div>').attr('id', 'perks');
}
for(var k in $SM.get('character.perks')) {
var id = 'perk_' + k.replace(' ', '-');
var r = $('#' + id);
if($SM.get('character.perks["'+k+'"]') && r.length === 0) {
r = $('<div>').attr('id', id).addClass('perkRow').appendTo(perks);
$('<div>').addClass('row_key').text(_(k)).appendTo(r);
$('<div>').addClass('tooltip bottom right').text(Engine.Perks[k].desc).appendTo(r);
}
}
if(needsAppend && perks.children().length > 0) {
perks.appendTo(Path.panel);
}
if(!ignoreStores && Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
}
}
},
updateOutfitting: function() {
var outfit = $('div#outfitting');
if(!Path.outfit) {
Path.outfit = {};
}
// Add the armour row
var armour = _("none");
if($SM.get('stores["s armour"]', true) > 0)
armour = _("steel");
else if($SM.get('stores["i armour"]', true) > 0)
armour = _("iron");
else if($SM.get('stores["l armour"]', true) > 0)
armour = _("leather");
var aRow = $('#armourRow');
if(aRow.length === 0) {
aRow = $('<div>').attr('id', 'armourRow').addClass('outfitRow').prependTo(outfit);
$('<div>').addClass('row_key').text(_('armour')).appendTo(aRow);
$('<div>').addClass('row_val').text(armour).appendTo(aRow);
$('<div>').addClass('clear').appendTo(aRow);
} else {
$('.row_val', aRow).text(armour);
}
// Add the water row
var wRow = $('#waterRow');
if(wRow.length === 0) {
wRow = $('<div>').attr('id', 'waterRow').addClass('outfitRow').insertAfter(aRow);
$('<div>').addClass('row_key').text(_('water')).appendTo(wRow);
$('<div>').addClass('row_val').text(World.getMaxWater()).appendTo(wRow);
$('<div>').addClass('clear').appendTo(wRow);
} else {
$('.row_val', wRow).text(World.getMaxWater());
}
var space = Path.getFreeSpace();
var total = 0;
// Add the non-craftables to the craftables
var carryable = $.extend({
'cured meat': { type: 'tool' },
'bullets': { type: 'tool' },
'grenade': {type: 'weapon' },
'bolas': {type: 'weapon' },
'laser rifle': {type: 'weapon' },
'energy cell': {type: 'tool' },
'bayonet': {type: 'weapon' },
'charm': {type: 'tool'},
'medicine': {type: 'tool'}
}, Room.Craftables);
for(var k in carryable) {
var store = carryable[k];
var have = $SM.get('stores["'+k+'"]');
var num = Path.outfit[k];
num = typeof num == 'number' ? num : 0;
if (have < num) { num = have; }
var numAvailable = $SM.get('stores["'+k+'"]', true);
var row = $('div#outfit_row_' + k.replace(' ', '-'), outfit);
if((store.type == 'tool' || store.type == 'weapon') && have > 0) {
total += num * Path.getWeight(k);
if(row.length === 0) {
row = Path.createOutfittingRow(k, num, store.name);
var curPrev = null;
outfit.children().each(function(i) {
var child = $(this);
if(child.attr('id').indexOf('outfit_row_') === 0) {
var cName = child.attr('id').substring(11).replace('-', ' ');
if(cName < k && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
}
});
if(curPrev == null) {
row.insertAfter(wRow);
}
else
{
row.insertAfter(outfit.find('#outfit_row_' + curPrev.replace(' ', '-')));
}
} else {
$('div#' + row.attr('id') + ' > div.row_val > span', outfit).text(num);
$('div#' + row.attr('id') + ' .tooltip .numAvailable', outfit).text(numAvailable - num);
}
if(num === 0) {
$('.dnBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
if(num >= numAvailable || space < Path.getWeight(k)) {
$('.upBtn', row).addClass('disabled');
$('.upManyBtn', row).addClass('disabled');
} else if(space >= Path.getWeight(k)) {
$('.upBtn', row).removeClass('disabled');
$('.upManyBtn', row).removeClass('disabled');
}
} else if(have === 0 && row.length > 0) {
row.remove();
}
}
// Update bagspace
$('#bagspace').text(_('free {0}/{1}', Math.floor(Path.getCapacity() - total) , Path.getCapacity()));
if(Path.outfit['cured meat'] > 0) {
Button.setDisabled($('#embarkButton'), false);
} else {
Button.setDisabled($('#embarkButton'), true);
}
},
createOutfittingRow: function(key, num, name) {
if(!name) name = _(key);
var row = $('<div>').attr('id', 'outfit_row_' + key.replace(' ', '-')).addClass('outfitRow').attr('key',key);
$('<div>').addClass('row_key').text(name).appendTo(row);
var val = $('<div>').addClass('row_val').appendTo(row);
$('<span>').text(num).appendTo(val);
$('<div>').addClass('upBtn').appendTo(val).click([1], Path.increaseSupply);
$('<div>').addClass('dnBtn').appendTo(val).click([1], Path.decreaseSupply);
$('<div>').addClass('upManyBtn').appendTo(val).click([10], Path.increaseSupply);
$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Path.decreaseSupply);
$('<div>').addClass('clear').appendTo(row);
var numAvailable = $SM.get('stores["'+key+'"]', true);
var tt = $('<div>').addClass('tooltip bottom right').appendTo(row);
$('<div>').addClass('row_key').text(_('weight')).appendTo(tt);
$('<div>').addClass('row_val').text(Path.getWeight(key)).appendTo(tt);
$('<div>').addClass('row_key').text(_('available')).appendTo(tt);
$('<div>').addClass('row_val').addClass('numAvailable').text(numAvailable).appendTo(tt);
return row;
},
increaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').attr('key');
Engine.log('increasing ' + supply + ' by up to ' + btn.data);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(Path.getFreeSpace() >= Path.getWeight(supply) && cur < $SM.get('stores["'+supply+'"]', true)) {
var maxExtraByWeight = Math.floor(Path.getFreeSpace() / Path.getWeight(supply));
var maxExtraByStore = $SM.get('stores["'+supply+'"]', true) - cur;
var maxExtraByBtn = btn.data;
Path.outfit[supply] = cur + Math.min(maxExtraByBtn, Math.min(maxExtraByWeight, maxExtraByStore));
$SM.set('outfit['+supply+']', Path.outfit[supply]);
Path.updateOutfitting();
}
},
decreaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').attr('key');
Engine.log('decreasing ' + supply + ' by up to ' + btn.data);
var cur = Path.outfit[supply];
cur = typeof cur == 'number' ? cur : 0;
if(cur > 0) {
Path.outfit[supply] = Math.max(0, cur - btn.data);
$SM.set('outfit['+supply+']', Path.outfit[supply]);
Path.updateOutfitting();
}
},
onArrival: function(transition_diff) {
Path.setTitle();
Path.updateOutfitting();
Path.updatePerks(true);
$SM.set('outfit', Path.outfit);
Engine.moveStoresView($('#perks'), transition_diff);
},
setTitle: function() {
document.title = _('A Dusty Path');
},
embark: function() {
for(var k in Path.outfit) {
$SM.add('stores["'+k+'"]', -Path.outfit[k]);
}
$SM.remove('outfit');
World.onArrival();
$('#outerSlider').animate({left: '-700px'}, 300);
Engine.activeModule = World;
},
handleStateUpdates: function(e){
if(e.category == 'character' && e.stateName.indexOf('character.perks') === 0 && Engine.activeModule == Path){
Path.updatePerks();
}
}
};
+1120 -1120
View File
File diff suppressed because it is too large Load Diff
+509 -509
View File
File diff suppressed because it is too large Load Diff
+949 -949
View File
File diff suppressed because it is too large Load Diff