99 Commits

Author SHA1 Message Date
Michael a24d492681 Fixed a bug with the page title. 2013-10-29 18:39:00 -04:00
Michael 5d07c76577 Incremented version 2013-10-29 18:07:17 -04:00
Michael b230d0586a Disallow medicine events before medicine has been discovered. 2013-10-29 18:06:40 -04:00
Michael Townsend a96e9c55c2 Update world.js 2013-10-29 15:54:25 -04:00
Michael 363119717e Added cancel button to the save dialog. 2013-10-17 17:48:48 -04:00
Michael Townsend 701baf86d7 Merge pull request #58 from Vermilingua/importexport
Routine to migrate/backup saves
2013-10-17 06:08:36 -07:00
Vermilingua dc706c21fe added importing and exporting saves with base64 2013-10-17 22:46:33 +11:00
Michael 1ffe8f8aeb A bit of cleanup. 2013-10-16 17:45:41 -04:00
Michael Townsend a895a35939 Merge pull request #57 from Vermilingua/prestige
Prestige System
2013-10-16 14:31:33 -07:00
Vermilingua 83bf266a29 prestige system now absolutely complete 2013-10-16 21:43:40 +11:00
Vermilingua f952b4def1 completed save/load 2013-10-16 21:43:14 +11:00
Vermilingua 1be4d5edc5 started backup/loading mechanic 2013-10-16 21:43:12 +11:00
Vermilingua acc04d0780 set down framework, storage/map gen/etc. 2013-10-16 21:41:47 +11:00
Michael Townsend 63a6d98ffe Merge pull request #55 from Vermilingua/forest
Forest now fits the scene
2013-10-15 07:40:32 -07:00
Vermilingua 36b9cf2142 made the forest suit more 2013-10-15 20:09:28 +11:00
Michael 95faa0ba75 Merge branch 'master' of https://github.com/Continuities/adarkroom.git 2013-10-13 18:53:19 -04:00
Michael 22e480a80b Ignore Eclipse settings. 2013-10-13 18:52:43 -04:00
Michael Townsend 25cae71067 Merge pull request #54 from Vermilingua/warnings
Made the warnings look nicer, and added the as-of-yet mostly unused logo
2013-10-12 10:20:58 -07:00
Vermilingua f6e95850da added safari/opera and got better logos 2013-10-12 13:40:47 +11:00
Vermilingua a89bf8ee8b nicened the warnings 2013-10-12 13:30:30 +11:00
Michael 5ebbefac91 Modified comment text 2013-10-11 17:24:41 -04:00
Michael 084bf15811 Little bug in keynav code. 2013-10-11 16:24:37 -04:00
Michael dde477aade Some general code cleanup. 2013-10-10 20:53:53 -04:00
Michael Townsend fbdc84dcf1 Merge pull request #52 from Bleyddyn/master
Arrow Keys and stores update fix
2013-10-10 17:12:30 -07:00
Andrew Salamon 5f5ff3701e Fixed a problem where the stores view wasn't updating. 2013-10-09 15:32:05 -07:00
Andrew Salamon 5d482f856e Added support for switching from room to outside to path using the arrow keys. 2013-10-09 15:31:43 -07:00
Michael Townsend 30e7a06a44 Merge pull request #50 from LucidCrux/state_manager_2
State manager 2
2013-08-18 19:08:53 -07:00
LucidCrux bb84eafca6 re-enable jQuery from google 2013-07-27 18:12:00 -06:00
LucidCrux f704a2137f turned off debug 2013-07-27 17:22:25 -06:00
LucidCrux 6561e88f9f lots of bugfixes
- bugfix Engine.startThieves call changed to $SM call
- bugfix $SM.remove not deleting state
- bugfix workaround for empty string when creating states
     For some reason splitting "state.sub.sub2["sub3"]" will result in
     empty strings whereas "state.sub.sub2[\'sub3\']" didn't. Maybe a
     javascript regex quirk?

     Had to add a loop to remove '' from the split string array.
- modified collectIncome so that only one update event fires for the 
  whole function, no event if no income was added.
- modified updateBuildButtons so that buttons would show up if the
  building had already been built.
     changed check to be wood != undefined

     Also changed room to display store values of 0 instead of removing 
     the row. It was distracting to have the values shift up and down 
     when tightly managing a resource. If you haven't seen a resource 
     yet, it still doesn't show up.
2013-07-27 17:21:30 -06:00
LucidCrux 36011b5b15 set version to 1.3, add code to update State from 1.2 to 1.3 2013-07-27 12:49:03 -06:00
LucidCrux a8c6790d84 bugfix set ship,world location to true on init 2013-07-27 12:25:15 -06:00
LucidCrux 99800f1abd refactor Outside to use $SM + Room bugfix, \' to "
Refactoring of Outside.js to take better advantage of $SM and simplify
the code.

Includes a small bug fix to Room update handler

Also changed instances of escaped single quote (\') to double (") for
readability and simplicity.

====state changes====
//these were changed for the opposite reason the Room states were. These
seem like states that other locations and events may very well want to
interact with and possibly alter themselves
game.outside.buildings >> game.buildings 
game.outside.population >> game.population
game.outside.workders >> game.workers


====functions removed====
Outside.numBuilding // just a $SM.get, no shortcut really needed since
Outside.numBuilding is a pretty long name
Outside.getPopulation // same here
Outside.addBuilding // just an add
Outside.addBuildings // just addM, but wasn't even actually used


====functions refactored====
Outside.killVillagers //moved updates to handler
Outside.updateWorkersView //added local to reduce gets
Outside.increasePopulation //updates moved to handler
Outside.increaseWorker // updates moved to handler
Outside.decreaseWorkder // updates moved to handler
2013-07-26 19:21:12 -06:00
LucidCrux f4d2e8deae change to property Room.fire, Room.temperature, Room.buttons
Changed these States into properties of room. They are only ever
accessed by Room and there is no real reason to save them. By not
saving the state each time, it also makes the the player start out in
'a dark room' on every load. Rather fitting I think, and gives the fire
a little bit more purpose if you have to rewarm the builder.
2013-07-25 21:05:43 -06:00
LucidCrux 99d57efdc1 bug fix Outside.init > set features.location.outside to true 2013-07-25 20:33:04 -06:00
LucidCrux 2e3f8abd3f add $SM.setget, refactor Room to better use $SM
game.room.builder >> game.builder.level

setget is mainly for use in local copies of states, useful for keeping
code cleaner and less redundant while maintaining set/get of states by
the $SM

====functions refactored====
Room.unlockForext //remove update calls
Room.buy //remove update calls
Room.build //remove update calls
Room.cooFire //added locals to reduce gets
Room.adjustTemp //added locals to reduce gets
Room.updateBuilderState //added local to reduce gets
Room.craftUnlocked //Room unlock is always going to be true, don't need
to check parents to avoid errors anymore
Room.buyUnlocked //Room unlock is always going to be true, don't need to
check parents to avoid errors anymore
2013-07-25 20:31:30 -06:00
LucidCrux f4520bce91 speed up and bug fix 2013-07-25 02:00:41 -06:00
LucidCrux 766d3879c7 Merge remote-tracking branch 'origin/master' into state_manager_2
Conflicts:
	script/events.js
2013-07-24 21:01:59 -06:00
LucidCrux 2018ca3ae8 create and configure callback handlers for state updates
add $.Dispatch to handle object events
add subscribe calls to files
update SM fireUpdate to use new Dispatch

There are some NaN issues right now, no time to bug hunt right now, it
does kind of function though
2013-07-24 18:33:06 -06:00
LucidCrux dee7cbb9b3 refactor Engine.js for use with $SM
====functions removed====
//I just removed these because most were simpler or at least equal as
	direct $SM get/set/add calls, I realize the store ones are kind of
	subjective since calls were about equal, but oh well. If someone
	really 	feels we need the shortcut/named functions for manipulating
	stores specifically, it shouldn't be crazy to reimplement in $SM 
Engine.setStore >> $SM.set
Engine.setStores >> $SM.setM
Engine.addStore >> $SM.add
Engine.addStores >> $SM.addM
Engine.getStore >> $SM.get(requestZero = true)
Engine.storeAvailable >> $SM.get;
Engine.removeIncome >> $SM.remove //updates moved to handler


====functions moved====
//Any moved function I felt was more directly related to States or
	didn't belong where it was
Engine.addPerk > $SM.addPerk //kept function for now because of notify
	call inside, 'deep' state
Engine.hasPerk > $SM.hasPerk //kept function because of 'deep' state
	name
Engine.setIncome > $SM.setIncome //kept because it has internal logic
**Engine.getIncome > $SM.getIncome //**easily removable with
	Outside.updateVillageIncome refactor
Engine.openPath > Path.openPath //Since I'm refactoring anyways
Engine.addStolen > $SM.addStolen //internal logic
Engine.startThieves > $SM.startThieves //not sure $SM is a better place,
	but Engine should be nice and clean by the end of this, handling
	only engine mechanics
Engine.num > $SM.num //after Outside refacter, this is basically just a
	fancy $SM.get
Engine.upgradeState > $SM.updateOldState


====functions refactored====
$SM.addPerk; //updates moved to event handler, no check/create new perk
$SM.hasPerk; //don't need to check exist and ==true
$SM.collectIncome //removed changed check, update calls now handled by
	'stateUpdate' event listening
$SM.addStolen //fix to set stolen items in case a partial steal happens
$SM.startThieves //updates in handler
$SM.updateOldState //use $SM calls, add placeholder for updating to post
$SM state when more finalized 


====functions affected (by removed)====
Engine.init (Engine.getStore, Engine.storeAvailable)
Engine.collectIncome (Engine.addStores)
Engine.num (Engine.getStore)
Engine.travelTo (Engine.storeAvailable)

Room.init (Engine.getStore)
Room.unlockForest (Engine.setStore)
Room.lightFire (Engine.setStore, Engine.getStore, Engine.storeAvailable)
Room.stokeFire (Engine.setStore, Engine.getStore, Engine.storeAvailable)
Room.coolFire (Engine.setStore)
Room.buy (Engine.setStores, Engine.addStore, Engine.getStore)
Room.build (Engine.setStores, Engine.getStore)
Room.craftUnlocked (Engine.getStore, Engine.storeAvailable)
Room.buyUnlocked (Engine.storeAvailable)
Room.updateButton (Engine.storeAvailable)

Outside.gatherWood (Engine.addStores)
Outside.checkTraps (Engine.addStores, Engine.getStore)
Outside.updateVillage (Engine.getStore)

Path.embark (Engine.addStore)
Path.getCapacity (Engine.getStore)
Path.updateOutfitting (Engine.getStore)
Path.createOutfittingRow (Engine.getStore)
Path.increaseSupply (Engine.getStore)

World.goHome (Engine.addStore)
World.updateSupplies (Engine.getStore)
World.checkDanger (Engine.getStore)
World.getMaxHealth (Engine.getStore)
World.getMaxWater (Engine.getStore)

Ship.reinforceHull (Engine.addStore, Engine.getStore)
Ship.upgradeEngine (Engine.addStore, Engine.getStore)

Events.loadScene (Engine.addStores)
Events.updateButtons (Engine.getStore)
Events.buttonClick (Engine.getStore)

Events.Global (Engine.addStores, Engine.removeIncome)
Events.Room (Engine.addStore, Engine.addStores, Engine.getStore,
Engine.storeAvailable)
2013-07-24 17:41:36 -06:00
Michael Townsend 03867cae60 Merge pull request #47 from Yeow-Meng/master
IE<8 Fixes:
2013-07-23 21:09:24 -07:00
Steve Hayes 253f946dbd IE<8 Fixes: Removed trailing commas in string literals and renamed variable char to chara 2013-07-23 23:54:06 -04:00
LucidCrux db4a346d21 create StateManager, change all State calls to managed calls
Introduced state_manager.js almost all State gets/sets are now run
through the manager (alias $SM). For now it was a simple, mostly
straightforward replacement of calls. This means that there are
redundancies and a lot of now unneeded code for things the SM will
handle. However, since I had trouble with making those changes as well
as introducing the manager all at once my first attempt, I am taking the
wiser approach and making "one change" at a time like I should have
instead of being too sure of myself.

At this point, it seems to work, but there may be bugs I didn't catch.
There was also no attempt made to update old saves to work with this. In
theory, it shouldn't be too hard. (included is a list of all state
changes)

TODO:
Save Update.
Refactor: a lot, many many redundancies now.
Refactor: "location centric" to "global centric".
Relocate all calls to different update functions to event listeners
where possible.

======================================================

The changes to State are as follows:

.room (exists) > features.location.room
.room > game.room
.room.builder > game.room.builder
.room.temperature > game.room.temperature
.room.fire > game.room.fire
.room.buttons > game.room.buttons

.outside (exists) > features.location.outside
.outside > game.outside
.outside.population > game.outside.population
.outside.buildings > game.outside.buildings
.outside.workers > game.outside.workers
.outside.seenForest > game.outside.seenForest

.world (exists) > features.location.world
.world > game.world
.world.map > game.world.map
.world.mask > game.world.mask
.starved > character.starved
.dehydrated > character.dehydrated

.ship (exists) > featuers.location.spaceShip
.ship > game.spaceShip
.ship.hull > game.spaceShip.hull
.ship.thrusters > game.spaceShip.thrusters
.ship.seenWarning > game.spaceShip.seenWarning
.ship.seenShip > game.spaceShip.seenShip

.punches > character.punches
.perks > character.perks

.thieves > game.thieves
.stolen > game.stolen
.cityCleared > game.cityCleared

.stores > stores
.income > income
2013-07-23 01:24:47 -06:00
Michael Townsend 1b1088db4f Merge pull request #44 from Zarkonnen/medicine
Fixed issue #42 by fixing wrong city exploration setpiece data.
2013-07-17 06:23:09 -07:00
Zarkonnen 7bf744e386 Fixed issue #42 by fixing wrong city exploration setpiece data. 2013-07-17 09:56:31 +02:00
Michael Townsend 252b731666 Merge pull request #39 from toofarapart/improved_item_dropping
events.js: Item dropping improvements
2013-07-15 08:43:47 -07:00
Michael Townsend d296ea4db9 Merge pull request #38 from Zarkonnen/laser_rifle_fix
Laser rifles are now listed as weapons, fixing issue #37.
2013-07-15 08:40:29 -07:00
Matt Rasmus e80fc4d286 events.js: Item dropping improvements
Item drop menu no longer disappears after clicking to drop something.
2013-07-13 17:00:57 -07:00
Zarkonnen 25f1fff6a1 Laser rifles are now listed as weapons, fixing issue #37. 2013-07-13 21:42:15 +02:00
Michael Townsend 77cac86076 Merge pull request #32 from toofarapart/all_villagers_killed_bug
All villagers killed bug
2013-07-10 19:51:36 -07:00
Matt Rasmus 22b850f1c0 outside.js: Fix incorrect display of workers.
Fixed an issue where the workers view would break temporarily if all the villagers were killed.
2013-07-10 17:56:15 -07:00
Michael Townsend 93f8e52e1f Merge pull request #30 from Zarkonnen/medicine
Medicine
2013-07-10 12:07:05 -07:00
Zarkonnen 3515cbf75f Removed mentions of "you". 2013-07-10 20:50:42 +02:00
Michael Townsend 8cb64ad3d8 Merge pull request #29 from Cogito/roadDrawing
Road drawing improvements
2013-07-10 10:57:13 -07:00
Zarkonnen d4034fe244 Fixed hospital never occurring in city. 2013-07-10 15:10:43 +02:00
Zarkonnen bb953de92b Finished first version of medicine feature. 2013-07-10 12:53:28 +02:00
Andrew Ardill 255bdd68fc world.js: Improve road drawing algorithm
Instead of drawing an 'L' shape road to the village, find the closest road,
outpost or village and draw the road to it. Care is taken to ensure that a
road is drawn if you are standing on top of an outpost, as the outpost may be
created before the tile it stands on is connected to the road network.
2013-07-10 20:52:18 +10:00
Andrew Ardill 26b955fee8 world.js: Increase functionality of getDistance
Allow passing 'from' and 'to' positions to getDistance to find the distance
between them.
2013-07-10 20:52:18 +10:00
Andrew Ardill c4afe143a9 world.js: Introduce World.VILLAGE_POS
This constant gets reused in a few places, so extract it out. Work will be
required to migrate existing code away from hard coding World.RADIUS in places
where we are talking about the village location.
2013-07-10 20:52:18 +10:00
Andrew Ardill b97f5d9914 world.js: Introduce function to copy positions 2013-07-10 20:52:17 +10:00
Michael Townsend 05fef5664d Merge pull request #27 from toofarapart/fade_to_black
(SPOILERS) A nice fade to black...
2013-07-09 19:47:45 -07:00
Michael Townsend f56697d9d0 Merge pull request #25 from toofarapart/persistent_stores_view
Stores panel now persists on all non-world/non-space views.
2013-07-08 14:25:20 -07:00
Matt Rasmus eaf2fcdfbb Keep showing the weapons panel while in the Path screen. 2013-07-08 13:58:16 -07:00
Matt Rasmus de2ad91053 Weapons panel hides when not in Room. 2013-07-08 13:10:49 -07:00
Michael Townsend b8dd1125d4 Merge pull request #21 from Zarkonnen/master
Converted zero/max buttons to +-10 buttons
2013-07-08 12:45:01 -07:00
Zarkonnen 4334f36e57 Bugfixes. 2013-07-08 21:39:28 +02:00
Michael Townsend ea0aff072f Merge pull request #28 from toofarapart/disappearing_restart_fix
(SPOILERS) Fixed a bug in which the share/restart buttons disappeared...
2013-07-08 11:55:56 -07:00
Zarkonnen 4641b0b145 Initial medicine implementation. Needs more events. 2013-07-08 19:16:16 +02:00
Matt Rasmus 0b6144660f Fixed a bug in which the share/restart buttons would disappear in certain situations. 2013-07-07 13:25:30 -07:00
Matt Rasmus 4326b2aa2a Game fades to black at the end, and stays that way until the player clicks restart. 2013-07-07 11:41:51 -07:00
Michael Townsend 54cea31db9 Merge pull request #26 from dhutty/patch-1
spelling
2013-07-07 09:09:42 -07:00
Michael Townsend 53ff72d218 Merge pull request #24 from jvantuyl/master
a grammar fix
2013-07-07 09:07:38 -07:00
dhutty aeedc5d10c spelling 2013-07-07 10:18:59 -04:00
Matt Rasmus 8dabee851d Stores panel now persists on all non-world/non-space views. 2013-07-06 14:56:27 -07:00
Jayson Vantuyl 536f09dce3 a grammar fix
"bundle of sticks", not "bundle of stick"
2013-07-06 13:53:33 -07:00
Michael Townsend 12258689e8 Merge pull request #22 from engstrom/master
Moved EatMeatButton to beginning of combat UI
2013-07-06 09:53:24 -07:00
Michael Townsend 95fddcbb2c Merge pull request #20 from evilDave/swipes
Added swipe support
2013-07-06 09:51:54 -07:00
Michael Townsend 79c0185e7e Merge pull request #23 from jvantuyl/master
Minor Spelling Fix
2013-07-06 09:50:29 -07:00
Jayson Vantuyl b14ad39c5a minor spelling fix 2013-07-05 23:43:43 -07:00
engstrom fa655aef1c Moved EatMeatButton to beginning of combat UI 2013-07-05 18:41:22 -06:00
Michael Townsend 1aaabed944 Merge pull request #18 from Erid/patch-1
Changed browser's img alt text
2013-07-05 06:43:47 -07:00
Michael Townsend e83dcd3945 Merge pull request #17 from engstrom/patch-1
Formatting the readme
2013-07-05 06:43:16 -07:00
David Clark e9679b3f26 Add swipe support. Modules can implement swipeLeft (etc). Swipes control movement in the World module (map). 2013-07-05 22:36:49 +10:00
Zarkonnen ae044376db Converted min/max buttons to +-10 buttons. Also made code shorter. 2013-07-05 13:47:23 +02:00
Elías Balioceda Fernández b1af589d53 Changed browser's img alt text
Just a minor fix
2013-07-04 21:39:55 -06:00
Dustin Engstrom 555a924fb0 Formatting the readme 2013-07-04 18:42:55 -06:00
Michael Townsend 7f1efd4ad2 Update LICENSE.md
Switched from GPLv3 to MPLv2
2013-07-04 15:21:49 -04:00
Michael Townsend 98719ccf0c Merge pull request #13 from Zarkonnen/master
Max/zero buttons
2013-07-04 07:50:07 -07:00
Michael Townsend 6a7df4d17c Fixed non-combat meat eating 2013-07-04 07:28:19 -07:00
Zarkonnen 6d99cb7c3a Added max/zero buttons to worker assignment and expedition supply packing to prevent eg having to click 50x to fill food supplies. 2013-07-04 16:15:29 +02:00
Michael Townsend cab220a5ac Merge pull request #10 from dmnd/master
Add an 'eat meat' button to the loot screen
2013-07-04 06:59:09 -07:00
Michael Townsend 242ef7f0b9 Merge pull request #7 from Cogito/moveInterface
Improve movement interface to allow click events
2013-07-04 06:55:50 -07:00
Michael Townsend 8743b16e09 Merge pull request #9 from Starefossen/patch-2
Adds link to play game online
2013-07-04 06:51:26 -07:00
Desmond Brand a86c61aaf0 Add an 'eat meat' button to the loot screen
When I played this, I would often madly try to click the 'eat meat' button
after I won a fight, only to have the 'leave' button appear in its place,
causing me to lose my chance at both healing and looting.

This patch adds an 'eat meat' button to the loot screen to avoid this UI
problem.
2013-07-04 02:56:54 -07:00
Hans Kristian Flaatten 2c8e410eab Adds link to play game online 2013-07-04 11:17:04 +02:00
Andrew Ardill 6fb7f248f7 world.js: Trigger movement with clicks on the map
Clicking on the map in different quadrants will move you in that direction.
Clicks are measured relative to the centre of the current location centre of
the map. Click above the player to move up, click below to move down etc.

This should enable better gameplay on touch devices.
2013-07-04 16:13:30 +10:00
Andrew Ardill d0a171e95b world.js: Refactor move commands out of keyDown
In order to better handle move commands, refactor them out of the keyDown
event handler. This will enable using other input methods to trigger a move
command, such as mouse clicks or touch events.
2013-07-04 14:49:21 +10:00
Michael Townsend 9327358008 Merge pull request #1 from daturkel/patch-1
Added a note to mobileWarning about arrow keys
2013-07-03 10:46:45 -07:00
Dan Turkel a37bb40c81 Added a note to mobileWarning about arrow keys
An HN commenter noted that he ignored the mobilewarning and tried the game and found it worked. That is, until he got to the Embark stage and found himself arrow key-less. This warning is slightly more verbose to avoid similar situations.
2013-07-03 13:44:45 -04:00
33 changed files with 3913 additions and 1065 deletions
+1
View File
@@ -0,0 +1 @@
/.settings
+6
View File
@@ -5,7 +5,13 @@
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
+345 -161
View File
@@ -1,189 +1,373 @@
GNU GENERAL PUBLIC LICENSE
Mozilla Public License Version 2.0
==================================
Version 3, 29 June 2007
1. Definitions
--------------
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
The GNU General Public License is a free, copyleft license for software and other kinds of works.
1.3. "Contribution"
means Covered Software of a particular Contributor.
The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things.
1.5. "Incompatible With Secondary Licenses"
means
To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others.
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users.
1.8. "License"
means this document.
Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS
0. Definitions.
1.10. "Modifications"
means any of the following:
“This License” refers to version 3 of the GNU General Public License.
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
“Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks.
(b) any new file in Source Code Form that contains any Covered
Software.
“The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
A “covered work” means either the unmodified Program or a work based on the Program.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying.
2. License Grants and Conditions
--------------------------------
An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion.
1. Source Code.
2.1. Grants
The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work.
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language.
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it.
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work.
2.2. Effective Date
The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source.
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
The Corresponding Source for a work in source code form is that same work.
2. Basic Permissions.
2.3. Limitations on Grant Scope
All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures.
When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified it, and giving a relevant date.
b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”.
c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so.
A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways:
a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b.
d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d.
A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work.
A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product.
“Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).
The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying.
7. Additional Terms.
“Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or authors of the material; or
e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors.
All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11).
However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice.
Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License.
An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it.
11. Patents.
A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”.
A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version.
In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party.
If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it.
A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation.
If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program.
Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.
+4 -2
View File
@@ -1,4 +1,6 @@
adarkroom
A Dark Room
=========
A Dark Room - A Minimalist Text Adventure
A Minimalist Text Adventure Game
[Click to play](http://rawgithub.com/Continuities/adarkroom/master/index.html)
+28 -12
View File
@@ -3,25 +3,41 @@
<head>
<title>A Dark Room</title>
<style>
body {
background-color: #000000;
color: #FFFFFF;
}
a {
color: #FFFFFF;
}
div {
width: 960px;
margin: auto;
text-align: center;
margin-top: 100px;
margin-top: 20px;
}
.browser {
width:102.4px;
height:102.4px;
}
</style>
</head>
<body>
<div>
<strong>
A Dark Room makes use of HTML5 and CSS3, which your current browser does not appear to support.<br/>
Please update your browser for the best experience:<br/>
</strong>
<a href='http://www.mozilla.org/en-US/firefox/new/'><img src='img/firefox.png' alt='Firefox' /></a>
<a href='https://www.google.com/intl/en/chrome/browser/'><img src='img/chrome.png' alt='Firefox' /></a>
<a href='http://windows.microsoft.com/en-CA/internet-explorer/download-ie'><img src='img/ie.png' alt='Firefox' /></a>
<br/><br/>
Or you can <a href='index.html?ignorebrowser=true'>play anyway</a>, but it probably won't work!
</div>
<center>
<img src="img/Logo1.jpg" />
<div>
<strong>
A Dark Room makes use of HTML5 and CSS3, which your current browser does not appear to support.<br/>
Please <a href="http://browsehappy.com">update your browser</a> for the best experience:<br/>
</strong>
<a href='http://www.mozilla.org/en-US/firefox/new/'><img class="browser" src='img/firefox.png' alt='Firefox' title='Firefox' /></a>
<a href='https://www.google.com/intl/en/chrome/browser/'><img class="browser" src='img/chrome.png' alt='Chrome' title='Chrome' /></a>
<a href='http://windows.microsoft.com/en-CA/internet-explorer/download-ie'><img class="browser" src='img/ie.png' alt='Internet Explorer' title='Internet Explorer' /></a>
<a href='http://www.opera.com/computer'><img class="browser" src='img/opera.png' alt='Opera' title='Opera' /></a>
<a href='http://www.apple.com/safari/'><img class="browser" src='img/safari.png' alt='Safari' title='Safari' /></a>
<br/><br/>
Or you can <a href='index.html?ignorebrowser=true'>play anyway</a>, but it probably won't work!
</div>
</center>
</body>
</html>
+42 -13
View File
@@ -55,7 +55,14 @@ div#header {
cursor: pointer;
}
.deleteSave:hover, .share:hover {
.manualSave {
position: absolute;
right: 120px;
bottom: 10px;
cursor: pointer;
}
.deleteSave:hover, .share:hover, .manualSave:hover {
text-decoration: underline;
}
@@ -194,15 +201,22 @@ div.button div.cooldown {
/* Up/Down buttons. They're complicated! */
.upBtn, .dnBtn {
.upBtn, .dnBtn, .upManyBtn, .dnManyBtn {
position: absolute;
width: 14px;
height: 15px;
right: 0px;
cursor: pointer;
}
.upBtn.disabled, .dnBtn.disabled {
.upBtn, .dnBtn {
right: 0px;
}
.upManyBtn, .dnManyBtn {
right: -11px;
}
.upBtn.disabled, .dnBtn.disabled, .upManyBtn.disabled, .dnManyBtn.disabled {
cursor: default;
}
@@ -210,7 +224,11 @@ div.button div.cooldown {
top: -2px;
}
.upBtn:after, .upBtn:before {
.upManyBtn {
top: -2px;
}
.upBtn:after, .upBtn:before, .upManyBtn:after, .upManyBtn:before {
position: absolute;
border: medium solid transparent;
content: " ";
@@ -219,15 +237,15 @@ div.button div.cooldown {
bottom: 4px;
}
.upBtn:after {
.upBtn:after, .upManyBtn:after {
border-color: transparent transparent white;
}
.upBtn:before {
.upBtn:before, .upManyBtn:before {
border-color: transparent transparent black;
}
.upBtn.disabled:before {
.upBtn.disabled:before, .upManyBtn.disabled:before {
border-color: transparent transparent #999;
}
@@ -236,7 +254,11 @@ div.button div.cooldown {
bottom: -3px;
}
.dnBtn:after, .dnBtn:before {
.dnManyBtn {
bottom: -3px;
}
.dnBtn:after, .dnBtn:before, .dnManyBtn:after, .dnManyBtn:before {
position: absolute;
border: medium solid transparent;
content: " ";
@@ -251,21 +273,27 @@ div.button div.cooldown {
margin-left: -3px;
}
.upBtn:before, .dnBtn:before {
.upBtn:before, .dnBtn:before, .upManyBtn:before, .dnManyBtn:before {
border-width: 5px;
left: 50%;
margin-left: -5px;
}
.dnBtn:after {
.upManyBtn:after, .dnManyBtn:after {
border-width: 2px;
left: 50%;
margin-left: -2px;
}
.dnBtn:after, .dnManyBtn:after {
border-color: white transparent transparent;
}
.dnBtn:before {
.dnBtn:before, .dnManyBtn:before {
border-color: black transparent transparent;
}
.dnBtn.disabled:before {
.dnBtn.disabled:before, .dnManyBtn.disabled:before {
border-color: #999 transparent transparent;
}
@@ -417,6 +445,7 @@ body.noMask #description {
#buttons > .button {
margin: 0 5px 5px;
margin-right: 15px;
}
/* Combat! */
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 119 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 191 KiB

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 20 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

+9 -3
View File
@@ -2,12 +2,12 @@
<html itemscope itemtype="http://schema.org/CreativeWork">
<head>
<!--
A Dark Room (v1.2)
A Dark Room (v1.3.1)
==================
A minimalist text adventure by Michael Townsend.
A minimalist text adventure by Michael Townsend and all his friends.
Inspired by Candy Box (http://candies.aniwey.net/)
Please don't steal me.
Contribute on GitHub! (https://github.com/Continuities/adarkroom/)
-->
<title>A Dark Room</title>
<meta itemprop="description" name="description" property="og:description" content="A minimalist text adventure">
@@ -16,9 +16,14 @@
<link rel="shortcut icon" href="favicon.ico" />
<link rel="image_src" href="img/adr.png" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<!-- <script src="lib/jquery.min.js"></script> -->
<script src="lib/jquery.color-2.1.2.min.js"></script>
<script src="lib/jquery.event.move.js"></script>
<script src="lib/jquery.event.swipe.js"></script>
<script src="lib/base64.js"></script>
<script src="script/Button.js"></script>
<script src="script/engine.js"></script>
<script src="script/state_manager.js"></script>
<script src="script/header.js"></script>
<script src="script/notifications.js"></script>
<script src="script/events.js"></script>
@@ -28,6 +33,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>
+141
View File
@@ -0,0 +1,141 @@
/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode : function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = Base64._utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
}
return output;
},
// public method for decoding
decode : function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = this._keyStr.indexOf(input.charAt(i++));
enc2 = this._keyStr.indexOf(input.charAt(i++));
enc3 = this._keyStr.indexOf(input.charAt(i++));
enc4 = this._keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = Base64._utf8_decode(output);
return output;
},
// private method for UTF-8 encoding
_utf8_encode : function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
// private method for UTF-8 decoding
_utf8_decode : function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
}
else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}
+580
View File
@@ -0,0 +1,580 @@
// jquery.event.move
//
// 1.3.1
//
// Stephen Band
//
// Triggers 'movestart', 'move' and 'moveend' events after
// mousemoves following a mousedown cross a distance threshold,
// similar to the native 'dragstart', 'drag' and 'dragend' events.
// Move events are throttled to animation frames. Move event objects
// have the properties:
//
// pageX:
// pageY: Page coordinates of pointer.
// startX:
// startY: Page coordinates of pointer at movestart.
// distX:
// distY: Distance the pointer has moved since movestart.
// deltaX:
// deltaY: Distance the finger has moved since last event.
// velocityX:
// velocityY: Average velocity over last few events.
(function (module) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], module);
} else {
// Browser globals
module(jQuery);
}
})(function(jQuery, undefined){
var // Number of pixels a pressed pointer travels before movestart
// event is fired.
threshold = 6,
add = jQuery.event.add,
remove = jQuery.event.remove,
// Just sugar, so we can have arguments in the same order as
// add and remove.
trigger = function(node, type, data) {
jQuery.event.trigger(type, data, node);
},
// Shim for requestAnimationFrame, falling back to timer. See:
// see http://paulirish.com/2011/requestanimationframe-for-smart-animating/
requestFrame = (function(){
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(fn, element){
return window.setTimeout(function(){
fn();
}, 25);
}
);
})(),
ignoreTags = {
textarea: true,
input: true,
select: true,
button: true
},
mouseevents = {
move: 'mousemove',
cancel: 'mouseup dragstart',
end: 'mouseup'
},
touchevents = {
move: 'touchmove',
cancel: 'touchend',
end: 'touchend'
};
// Constructors
function Timer(fn){
var callback = fn,
active = false,
running = false;
function trigger(time) {
if (active){
callback();
requestFrame(trigger);
running = true;
active = false;
}
else {
running = false;
}
}
this.kick = function(fn) {
active = true;
if (!running) { trigger(); }
};
this.end = function(fn) {
var cb = callback;
if (!fn) { return; }
// If the timer is not running, simply call the end callback.
if (!running) {
fn();
}
// If the timer is running, and has been kicked lately, then
// queue up the current callback and the end callback, otherwise
// just the end callback.
else {
callback = active ?
function(){ cb(); fn(); } :
fn ;
active = true;
}
};
}
// Functions
function returnTrue() {
return true;
}
function returnFalse() {
return false;
}
function preventDefault(e) {
e.preventDefault();
}
function preventIgnoreTags(e) {
// Don't prevent interaction with form elements.
if (ignoreTags[ e.target.tagName.toLowerCase() ]) { return; }
e.preventDefault();
}
function isLeftButton(e) {
// Ignore mousedowns on any button other than the left (or primary)
// mouse button, or when a modifier key is pressed.
return (e.which === 1 && !e.ctrlKey && !e.altKey);
}
function identifiedTouch(touchList, id) {
var i, l;
if (touchList.identifiedTouch) {
return touchList.identifiedTouch(id);
}
// touchList.identifiedTouch() does not exist in
// webkit yet… we must do the search ourselves...
i = -1;
l = touchList.length;
while (++i < l) {
if (touchList[i].identifier === id) {
return touchList[i];
}
}
}
function changedTouch(e, event) {
var touch = identifiedTouch(e.changedTouches, event.identifier);
// This isn't the touch you're looking for.
if (!touch) { return; }
// Chrome Android (at least) includes touches that have not
// changed in e.changedTouches. That's a bit annoying. Check
// that this touch has changed.
if (touch.pageX === event.pageX && touch.pageY === event.pageY) { return; }
return touch;
}
// Handlers that decide when the first movestart is triggered
function mousedown(e){
var data;
if (!isLeftButton(e)) { return; }
data = {
target: e.target,
startX: e.pageX,
startY: e.pageY,
timeStamp: e.timeStamp
};
add(document, mouseevents.move, mousemove, data);
add(document, mouseevents.cancel, mouseend, data);
}
function mousemove(e){
var data = e.data;
checkThreshold(e, data, e, removeMouse);
}
function mouseend(e) {
removeMouse();
}
function removeMouse() {
remove(document, mouseevents.move, mousemove);
remove(document, mouseevents.cancel, mouseend);
}
function touchstart(e) {
var touch, template;
// Don't get in the way of interaction with form elements.
if (ignoreTags[ e.target.tagName.toLowerCase() ]) { return; }
touch = e.changedTouches[0];
// iOS live updates the touch objects whereas Android gives us copies.
// That means we can't trust the touchstart object to stay the same,
// so we must copy the data. This object acts as a template for
// movestart, move and moveend event objects.
template = {
target: touch.target,
startX: touch.pageX,
startY: touch.pageY,
timeStamp: e.timeStamp,
identifier: touch.identifier
};
// Use the touch identifier as a namespace, so that we can later
// remove handlers pertaining only to this touch.
add(document, touchevents.move + '.' + touch.identifier, touchmove, template);
add(document, touchevents.cancel + '.' + touch.identifier, touchend, template);
}
function touchmove(e){
var data = e.data,
touch = changedTouch(e, data);
if (!touch) { return; }
checkThreshold(e, data, touch, removeTouch);
}
function touchend(e) {
var template = e.data,
touch = identifiedTouch(e.changedTouches, template.identifier);
if (!touch) { return; }
removeTouch(template.identifier);
}
function removeTouch(identifier) {
remove(document, '.' + identifier, touchmove);
remove(document, '.' + identifier, touchend);
}
// Logic for deciding when to trigger a movestart.
function checkThreshold(e, template, touch, fn) {
var distX = touch.pageX - template.startX,
distY = touch.pageY - template.startY;
// Do nothing if the threshold has not been crossed.
if ((distX * distX) + (distY * distY) < (threshold * threshold)) { return; }
triggerStart(e, template, touch, distX, distY, fn);
}
function handled() {
// this._handled should return false once, and after return true.
this._handled = returnTrue;
return false;
}
function flagAsHandled(e) {
e._handled();
}
function triggerStart(e, template, touch, distX, distY, fn) {
var node = template.target,
touches, time;
touches = e.targetTouches;
time = e.timeStamp - template.timeStamp;
// Create a movestart object with some special properties that
// are passed only to the movestart handlers.
template.type = 'movestart';
template.distX = distX;
template.distY = distY;
template.deltaX = distX;
template.deltaY = distY;
template.pageX = touch.pageX;
template.pageY = touch.pageY;
template.velocityX = distX / time;
template.velocityY = distY / time;
template.targetTouches = touches;
template.finger = touches ?
touches.length :
1 ;
// The _handled method is fired to tell the default movestart
// handler that one of the move events is bound.
template._handled = handled;
// Pass the touchmove event so it can be prevented if or when
// movestart is handled.
template._preventTouchmoveDefault = function() {
e.preventDefault();
};
// Trigger the movestart event.
trigger(template.target, template);
// Unbind handlers that tracked the touch or mouse up till now.
fn(template.identifier);
}
// Handlers that control what happens following a movestart
function activeMousemove(e) {
var event = e.data.event,
timer = e.data.timer;
updateEvent(event, e, e.timeStamp, timer);
}
function activeMouseend(e) {
var event = e.data.event,
timer = e.data.timer;
removeActiveMouse();
endEvent(event, timer, function() {
// Unbind the click suppressor, waiting until after mouseup
// has been handled.
setTimeout(function(){
remove(event.target, 'click', returnFalse);
}, 0);
});
}
function removeActiveMouse(event) {
remove(document, mouseevents.move, activeMousemove);
remove(document, mouseevents.end, activeMouseend);
}
function activeTouchmove(e) {
var event = e.data.event,
timer = e.data.timer,
touch = changedTouch(e, event);
if (!touch) { return; }
// Stop the interface from gesturing
e.preventDefault();
event.targetTouches = e.targetTouches;
updateEvent(event, touch, e.timeStamp, timer);
}
function activeTouchend(e) {
var event = e.data.event,
timer = e.data.timer,
touch = identifiedTouch(e.changedTouches, event.identifier);
// This isn't the touch you're looking for.
if (!touch) { return; }
removeActiveTouch(event);
endEvent(event, timer);
}
function removeActiveTouch(event) {
remove(document, '.' + event.identifier, activeTouchmove);
remove(document, '.' + event.identifier, activeTouchend);
}
// Logic for triggering move and moveend events
function updateEvent(event, touch, timeStamp, timer) {
var time = timeStamp - event.timeStamp;
event.type = 'move';
event.distX = touch.pageX - event.startX;
event.distY = touch.pageY - event.startY;
event.deltaX = touch.pageX - event.pageX;
event.deltaY = touch.pageY - event.pageY;
// Average the velocity of the last few events using a decay
// curve to even out spurious jumps in values.
event.velocityX = 0.3 * event.velocityX + 0.7 * event.deltaX / time;
event.velocityY = 0.3 * event.velocityY + 0.7 * event.deltaY / time;
event.pageX = touch.pageX;
event.pageY = touch.pageY;
timer.kick();
}
function endEvent(event, timer, fn) {
timer.end(function(){
event.type = 'moveend';
trigger(event.target, event);
return fn && fn();
});
}
// jQuery special event definition
function setup(data, namespaces, eventHandle) {
// Stop the node from being dragged
//add(this, 'dragstart.move drag.move', preventDefault);
// Prevent text selection and touch interface scrolling
//add(this, 'mousedown.move', preventIgnoreTags);
// Tell movestart default handler that we've handled this
add(this, 'movestart.move', flagAsHandled);
// Don't bind to the DOM. For speed.
return true;
}
function teardown(namespaces) {
remove(this, 'dragstart drag', preventDefault);
remove(this, 'mousedown touchstart', preventIgnoreTags);
remove(this, 'movestart', flagAsHandled);
// Don't bind to the DOM. For speed.
return true;
}
function addMethod(handleObj) {
// We're not interested in preventing defaults for handlers that
// come from internal move or moveend bindings
if (handleObj.namespace === "move" || handleObj.namespace === "moveend") {
return;
}
// Stop the node from being dragged
add(this, 'dragstart.' + handleObj.guid + ' drag.' + handleObj.guid, preventDefault, undefined, handleObj.selector);
// Prevent text selection and touch interface scrolling
add(this, 'mousedown.' + handleObj.guid, preventIgnoreTags, undefined, handleObj.selector);
}
function removeMethod(handleObj) {
if (handleObj.namespace === "move" || handleObj.namespace === "moveend") {
return;
}
remove(this, 'dragstart.' + handleObj.guid + ' drag.' + handleObj.guid);
remove(this, 'mousedown.' + handleObj.guid);
}
jQuery.event.special.movestart = {
setup: setup,
teardown: teardown,
add: addMethod,
remove: removeMethod,
_default: function(e) {
var template, data;
// If no move events were bound to any ancestors of this
// target, high tail it out of here.
if (!e._handled()) { return; }
template = {
target: e.target,
startX: e.startX,
startY: e.startY,
pageX: e.pageX,
pageY: e.pageY,
distX: e.distX,
distY: e.distY,
deltaX: e.deltaX,
deltaY: e.deltaY,
velocityX: e.velocityX,
velocityY: e.velocityY,
timeStamp: e.timeStamp,
identifier: e.identifier,
targetTouches: e.targetTouches,
finger: e.finger
};
data = {
event: template,
timer: new Timer(function(time){
trigger(e.target, template);
})
};
if (e.identifier === undefined) {
// We're dealing with a mouse
// Stop clicks from propagating during a move
add(e.target, 'click', returnFalse);
add(document, mouseevents.move, activeMousemove, data);
add(document, mouseevents.end, activeMouseend, data);
}
else {
// We're dealing with a touch. Stop touchmove doing
// anything defaulty.
e._preventTouchmoveDefault();
add(document, touchevents.move + '.' + e.identifier, activeTouchmove, data);
add(document, touchevents.end + '.' + e.identifier, activeTouchend, data);
}
}
};
jQuery.event.special.move = {
setup: function() {
// Bind a noop to movestart. Why? It's the movestart
// setup that decides whether other move events are fired.
add(this, 'movestart.move', jQuery.noop);
},
teardown: function() {
remove(this, 'movestart.move', jQuery.noop);
}
};
jQuery.event.special.moveend = {
setup: function() {
// Bind a noop to movestart. Why? It's the movestart
// setup that decides whether other move events are fired.
add(this, 'movestart.moveend', jQuery.noop);
},
teardown: function() {
remove(this, 'movestart.moveend', jQuery.noop);
}
};
add(document, 'mousedown.move', mousedown);
add(document, 'touchstart.move', touchstart);
// Make jQuery copy touch event properties over to the jQuery event
// object, if they are not already listed. But only do the ones we
// really need. IE7/8 do not have Array#indexOf(), but nor do they
// have touch events, so let's assume we can ignore them.
if (typeof Array.prototype.indexOf === 'function') {
(function(jQuery, undefined){
var props = ["changedTouches", "targetTouches"],
l = props.length;
while (l--) {
if (jQuery.event.props.indexOf(props[l]) === -1) {
jQuery.event.props.push(props[l]);
}
}
})(jQuery);
};
});
+130
View File
@@ -0,0 +1,130 @@
// jQuery.event.swipe
// 0.5
// Stephen Band
// Dependencies
// jQuery.event.move 1.2
// One of swipeleft, swiperight, swipeup or swipedown is triggered on
// moveend, when the move has covered a threshold ratio of the dimension
// of the target node, or has gone really fast. Threshold and velocity
// sensitivity changed with:
//
// jQuery.event.special.swipe.settings.threshold
// jQuery.event.special.swipe.settings.sensitivity
(function (module) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], module);
} else {
// Browser globals
module(jQuery);
}
})(function(jQuery, undefined){
var add = jQuery.event.add,
remove = jQuery.event.remove,
// Just sugar, so we can have arguments in the same order as
// add and remove.
trigger = function(node, type, data) {
jQuery.event.trigger(type, data, node);
},
settings = {
// Ratio of distance over target finger must travel to be
// considered a swipe.
threshold: 0.4,
// Faster fingers can travel shorter distances to be considered
// swipes. 'sensitivity' controls how much. Bigger is shorter.
sensitivity: 6
};
function moveend(e) {
var w, h, event;
w = e.target.offsetWidth;
h = e.target.offsetHeight;
// Copy over some useful properties from the move event
event = {
distX: e.distX,
distY: e.distY,
velocityX: e.velocityX,
velocityY: e.velocityY,
finger: e.finger
};
// Find out which of the four directions was swiped
if (e.distX > e.distY) {
if (e.distX > -e.distY) {
if (e.distX/w > settings.threshold || e.velocityX * e.distX/w * settings.sensitivity > 1) {
event.type = 'swiperight';
trigger(e.currentTarget, event);
}
}
else {
if (-e.distY/h > settings.threshold || e.velocityY * e.distY/w * settings.sensitivity > 1) {
event.type = 'swipeup';
trigger(e.currentTarget, event);
}
}
}
else {
if (e.distX > -e.distY) {
if (e.distY/h > settings.threshold || e.velocityY * e.distY/w * settings.sensitivity > 1) {
event.type = 'swipedown';
trigger(e.currentTarget, event);
}
}
else {
if (-e.distX/w > settings.threshold || e.velocityX * e.distX/w * settings.sensitivity > 1) {
event.type = 'swipeleft';
trigger(e.currentTarget, event);
}
}
}
}
function getData(node) {
var data = jQuery.data(node, 'event_swipe');
if (!data) {
data = { count: 0 };
jQuery.data(node, 'event_swipe', data);
}
return data;
}
jQuery.event.special.swipe =
jQuery.event.special.swipeleft =
jQuery.event.special.swiperight =
jQuery.event.special.swipeup =
jQuery.event.special.swipedown = {
setup: function( data, namespaces, eventHandle ) {
var data = getData(this);
// If another swipe event is already setup, don't setup again.
if (data.count++ > 0) { return; }
add(this, 'moveend', moveend);
return true;
},
teardown: function() {
var data = getData(this);
// If another swipe event is still setup, don't teardown.
if (--data.count > 0) { return; }
remove(this, 'moveend', moveend);
return true;
},
settings: settings
};
});
+6
View File
File diff suppressed because one or more lines are too long
+19 -9
View File
@@ -3,21 +3,31 @@
<head>
<title>A Dark Room</title>
<style>
body {
background-color: #000000;
color: #FFFFFF;
}
a {
color: #FFFFFF;
}
div {
width: 960px;
margin: auto;
text-align: center;
margin-top: 100px;
margin-top: 20px;
}
</style>
</head>
<body>
<div>
<strong>
A Dark Room isn't really mobile-friendly<br/>
Sorry about that!<br/>
</strong><br/>
Of course you can <a href='index.html?ignorebrowser=true'>play anyway</a>, but it probably won't work!
</div>
<center>
<img src="img/Logo1.jpg" />
<div>
<strong>
A Dark Room isn't really mobile-friendly, and it requires arrow keys.<br/>
Sorry about that!<br/>
</strong><br/>
Of course you can <a href='index.html?ignorebrowser=true'>play anyway</a>, but it probably won't work!
</div>
</center>
</body>
</html>
</html>
+213 -245
View File
@@ -7,8 +7,13 @@ var Engine = {
* That would be so elegant and awesome.
*/
SITE_URL: encodeURIComponent("http://adarkroom.doublespeakgames.com"),
VERSION: 1.3,
MAX_STORE: 99999999999999,
SAVE_DISPLAY: 30 * 1000,
GAME_OVER: false,
//object event types
topics: {},
Perks: {
'boxer': {
@@ -100,22 +105,39 @@ var Engine = {
.text('share.')
.click(Engine.share)
.appendTo('body');
$('<span>')
.addClass('manualSave')
.text('save.')
.click(Engine.exportImport)
.appendTo('body');
// Register keypress handlers
$('body').off('keydown').keydown(Engine.keyDown);
$('body').off('keyup').keyup(Engine.keyUp);
// Register swipe handlers
swipeElement = $('#outerSlider');
swipeElement.on('swipeleft', Engine.swipeLeft);
swipeElement.on('swiperight', Engine.swipeRight);
swipeElement.on('swipeup', Engine.swipeUp);
swipeElement.on('swipedown', Engine.swipeDown);
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Engine.handleStateUpdates);
$SM.init();
Notifications.init();
Events.init();
Room.init();
if(Engine.storeAvailable('wood')) {
if($SM.get('stores.wood')) {
Outside.init();
}
if(Engine.getStore('compass') > 0) {
if($SM.get('stores.compass', true) > 0) {
Path.init();
}
if(State.ship) {
if($SM.get('features.location.spaceShip')) {
Ship.init();
}
@@ -152,43 +174,72 @@ var Engine = {
var savedState = JSON.parse(localStorage.gameState);
if(savedState) {
State = savedState;
Engine.upgradeState();
$SM.updateOldState();
Engine.log("loaded save!");
}
} catch(e) {
State = {
version: 1.2,
stores: {},
perks: {}
};
State = {};
$SM.set('version', Engine.VERSION);
Engine.event('progress', 'new game');
}
},
upgradeState: function() {
/* Use this function to make old
* save games compatible with newer versions */
if(typeof State.version != 'number') {
Engine.log('upgraded save to v1.0');
State.version = 1.0;
}
if(State.version == 1.0) {
// v1.1 introduced the Lodge, so get rid of lodgeless hunters
delete State.outside.workers.hunter;
delete State.income.hunter;
Engine.log('upgraded save to v1.1');
State.version = 1.1;
}
if(State.version == 1.1) {
//v1.2 added the Swamp to the map, so add it to already generated maps
if(State.world) {
World.placeLandmark(15, World.RADIUS * 1.5, World.TILE.SWAMP, State.world.map);
exportImport: function() {
Events.startEvent({
title: 'Export / Import',
scenes: {
start: {
text: ['export or import save data, for backing up',
'or migrating computers'],
buttons: {
'export': {
text: 'export',
nextScene: 'end',
onChoose: Engine.export64
},
'import': {
text: 'import',
nextScene: {1: 'confirm'},
},
'cancel': {
text: 'cancel',
nextScene: 'end'
}
}
},
'confirm': {
text: ['are you sure?',
'if the code is invalid, all data will be lost.',
'this is irreversible.'],
buttons: {
'yes': {
text: 'yes',
nextScene: 'end',
onChoose: Engine.import64
},
'no': {
text: 'no',
nextScene: 'end'
}
}
}
}
Engine.log('upgraded save to v1.2');
State.version = 1.2;
}
},
});
},
export64: function() {
Engine.saveGame();
var string64 = Base64.encode(localStorage.gameState);
prompt("save this.",string64);
},
import64: function() {
var string64 = prompt("put the save code here.","");
var decodedSave = Base64.decode(string64);
localStorage.gameState = decodedSave;
location.reload();
},
event: function(cat, act) {
if(typeof ga === 'function') {
ga('send', 'event', cat, act);
@@ -218,9 +269,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();
},
@@ -282,227 +335,62 @@ var Engine = {
travelTo: function(module) {
if(Engine.activeModule != module) {
var currentIndex = Engine.activeModule ? $('.location').index(Engine.activeModule.panel) : 1;
Engine.activeModule = module;
$('div.headerButton').removeClass('selected');
module.tab.addClass('selected');
var slider = $('#locationSlider');
var stores = $('#storesContainer');
var panelIndex = $('.location').index(module.panel);
var diff = Math.abs(panelIndex - currentIndex);
slider.animate({left: -(panelIndex * 700) + 'px'}, 300 * diff);
module.onArrival();
if($SM.get('stores.wood') != undefined) {
// FIXME Why does this work if there's an animation queue...?
stores.animate({right: -(panelIndex * 700) + 'px'}, 300 * diff);
}
Engine.activeModule = module;
module.onArrival(diff);
if(Engine.activeModule == Room || Engine.activeModule == Path) {
// Don't fade out the weapons if we're switching to a module
// where we're going to keep showing them anyway.
if (module != Room && module != Path) {
$('div#weapons').animate({opacity: 0}, 300);
}
}
if(module == Room || module == Path) {
$('div#weapons').animate({opacity: 1}, 300);
}
Notifications.printQueue(module);
}
},
addPerk: function(name) {
if(!State.perks) {
State.perks = {};
// Move the stores panel beneath top_container (or to top: 0px if top_container
// either hasn't been filled in or is null) using transition_diff to sync with
// the animation in Engine.travelTo().
moveStoresView: function(top_container, transition_diff) {
var stores = $('#storesContainer');
// If we don't have a storesContainer yet, leave.
if(typeof(stores) === 'undefined') return;
if(typeof(transition_diff) === 'undefined') transition_diff = 1;
if(top_container === null) {
stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff});
}
State.perks[name] = true;
Notifications.notify(null, Engine.Perks[name].notify);
if(Engine.activeModule == Path) {
Path.updatePerks();
else if(!top_container.length) {
stores.animate({top: '0px'}, {queue: false, duration: 300 * transition_diff});
}
},
hasPerk: function(name) {
return typeof State.perks == 'object' && State.perks[name] == true;
},
setStore: function(name, number) {
if(typeof State.stores == 'undefined') {
State.stores = {};
}
if(number > Engine.MAX_STORE) number = Engine.MAX_STORE;
State.stores[name] = number;
Room.updateStoresView();
Room.updateBuildButtons();
if(State.outside) {
Outside.updateVillage();
}
Engine.saveGame();
},
setStores: function(list) {
if(typeof State.stores == 'undefined') {
State.stores = {};
}
for(k in list) {
State.stores[k] = list[k] > Engine.MAX_STORE ? Engine.MAX_STORE : list[k];
}
Room.updateStoresView();
Room.updateBuildButtons();
if(State.outside) {
Outside.updateVillage();
}
Engine.saveGame();
},
addStore: function(name, number) {
if(typeof State.stores == 'undefined') {
State.stores = {};
}
var num = State.stores[name];
if(typeof num != 'number' || isNaN(num) || num < 0) num = 0;
num += number;
if(num > Engine.MAX_STORE) num = Engine.MAX_STORE;
State.stores[name] = num;
Room.updateStoresView();
Room.updateBuildButtons();
Outside.updateVillage();
if(Engine.activeModule == Path) {
Path.updateOutfitting();
}
Engine.saveGame();
},
addStores: function(list, ignoreCosts) {
if(typeof State.stores == 'undefined') {
State.stores = {};
}
// Make sure any income costs can be paid
if(!ignoreCosts) {
for(k in list) {
var num = State.stores[k];
if(typeof num != 'number' || isNaN(num) || num < 0) num = 0;
if(num + list[k] < 0) {
return false;
}
}
}
// Actually do the update
for(k in list) {
var num = State.stores[k];
if(typeof num != 'number') num = 0;
num += list[k];
num = num < 0 ? 0 : num;
num = num > Engine.MAX_STORE ? Engine.MAX_STORE : num;
State.stores[k] = num;
}
Room.updateStoresView();
Room.updateBuildButtons();
Outside.updateVillage();
if(Engine.activeModule == Path) {
Path.updateOutfitting();
}
Engine.saveGame();
return true;
},
storeAvailable: function(name) {
return typeof State.stores[name] == 'number';
},
getStore: function(name) {
if(typeof State.stores == 'undefined' || typeof State.stores[name] == 'undefined' ) {
return 0;
}
return State.stores[name];
},
setIncome: function(source, options) {
if(typeof State.income == 'undefined') {
State.income = {};
}
var existing = State.income[source];
if(typeof existing != 'undefined') {
options.timeLeft = existing.timeLeft;
}
State.income[source] = options;
},
getIncome: function(source) {
if(typeof State.income == 'undefined') {
State.income = {};
}
var existing = State.income[source];
if(typeof existing != 'undefined') {
return existing;
}
return {};
},
removeIncome: function(source) {
if(State.income) {
delete State.income[source];
}
Room.updateIncomeView();
},
collectIncome: function() {
if(typeof State.income != 'undefined' && Engine.activeModule != Space) {
var changed = false;
for(var source in State.income) {
var income = State.income[source];
if(typeof income.timeLeft != 'number')
{
income.timeLeft = 0;
}
income.timeLeft--;
if(income.timeLeft <= 0) {
Engine.log('collection income from ' + source);
if(source == 'thieves') {
Engine.addStolen(income.stores);
}
changed = Engine.addStores(income.stores) || changed;
if(typeof income.delay == 'number') {
income.timeLeft = income.delay;
}
}
}
if(changed) {
Room.updateStoresView();
Room.updateBuildButtons();
Engine.saveGame();
if(Events.activeEvent() != null) {
Events.updateButtons();
}
}
}
Engine._incomeTimeout = setTimeout(Engine.collectIncome, 1000);
},
openPath: function() {
Path.init();
Engine.event('progress', 'path');
Notifications.notify(Room, 'the compass points ' + World.dir);
},
addStolen: function(stores) {
if(!State.stolen) State.stolen = {};
for(var k in stores) {
if(!State.stolen[k]) State.stolen[k] = 0;
State.stolen[k] -= stores[k];
}
},
startThieves: function() {
State.thieves = 1;
Engine.setIncome('thieves', {
delay: 10,
stores: {
'wood': -10,
'fur': -5,
'meat': -5
}
});
Room.updateIncomeView();
},
num: function(name, craftable) {
switch(craftable.type) {
case 'good':
case 'tool':
case 'weapon':
case 'upgrade':
return Engine.getStore(name);
case 'building':
return Outside.numBuilding(name);
else {
stores.animate({top: top_container.height() + 26 + 'px'},
{queue: false, duration: 300 * transition_diff});
}
},
@@ -541,10 +429,90 @@ var Engine = {
if(Engine.activeModule.keyUp) {
Engine.activeModule.keyUp(e);
}
else
{
switch(e.which) {
case 38: // Up
case 87:
Engine.log('up');
break;
case 40: // Down
case 83:
Engine.log('down');
break;
case 37: // Left
case 65:
if(Engine.activeModule == Ship && Path.tab)
Engine.travelTo(Path);
else if(Engine.activeModule == Path && Outside.tab)
Engine.travelTo(Outside);
else if(Engine.activeModule == Outside && Room.tab)
Engine.travelTo(Room);
Engine.log('left');
break;
case 39: // Right
case 68:
if(Engine.activeModule == Room && Outside.tab)
Engine.travelTo(Outside);
else if(Engine.activeModule == Outside && Path.tab)
Engine.travelTo(Path);
else if(Engine.activeModule == Path && Ship.tab)
Engine.travelTo(Ship);
Engine.log('right');
break;
}
}
return false;
},
swipeLeft: function(e) {
if(Engine.activeModule.swipeLeft) {
Engine.activeModule.swipeLeft(e);
}
},
swipeRight: function(e) {
if(Engine.activeModule.swipeRight) {
Engine.activeModule.swipeRight(e);
}
},
swipeUp: function(e) {
if(Engine.activeModule.swipeUp) {
Engine.activeModule.swipeUp(e);
}
},
swipeDown: function(e) {
if(Engine.activeModule.swipeDown) {
Engine.activeModule.swipeDown(e);
}
},
handleStateUpdates: function(e){
}
};
//create jQuery Callbacks() to handle object events
$.Dispatch = function( id ) {
var callbacks,
topic = id && Engine.topics[ id ];
if ( !topic ) {
callbacks = jQuery.Callbacks();
topic = {
publish: callbacks.fire,
subscribe: callbacks.add,
unsubscribe: callbacks.remove
};
if ( id ) {
Engine.topics[ id ] = topic;
}
}
return topic;
};
$(function() {
Engine.init();
});
});
+133 -53
View File
@@ -7,6 +7,7 @@ var Events = {
_PANEL_FADE: 200,
_FIGHT_SPEED: 100,
_EAT_COOLDOWN: 5,
_MEDS_COOLDOWN: 7,
STUN_DURATION: 4000,
init: function(options) {
@@ -25,11 +26,14 @@ var Events = {
Events.eventStack = [];
Events.scheduleNextEvent();
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Events.handleStateUpdates);
},
options: {}, // Nothing for now
activeEvent: null,
activeEvent: null,
activeScene: null,
eventPanel: null,
@@ -40,7 +44,7 @@ var Events = {
// Scene reward
if(scene.reward) {
Engine.addStores(scene.reward, true);
$SM.addM('stores', scene.reward);
}
// onLoad
@@ -73,7 +77,7 @@ var Events = {
Events.createFighterDiv('@', World.health, World.getMaxHealth()).attr('id', 'wanderer').appendTo(desc);
// Draw the enemy
Events.createFighterDiv(scene.char, scene.health, scene.health).attr('id', 'enemy').appendTo(desc);
Events.createFighterDiv(scene.chara, scene.health, scene.health).attr('id', 'enemy').appendTo(desc);
// Draw the action buttons
var btns = $('#buttons', Events.eventPanel());
@@ -103,27 +107,60 @@ var Events = {
Events.createAttackButton('fists').prependTo(btns);
}
var eat = new Button.Button({
id: 'eat',
text: 'eat meat',
cooldown: Events._EAT_COOLDOWN,
click: Events.eatMeat,
cost: { 'cured meat': 1 }
}).appendTo(btns);
if(Path.outfit['cured meat'] == 0) {
Button.setDisabled(eat, true);
}
Events.createEatMeatButton().appendTo(btns);
if((Path.outfit['medicine'] || 0) != 0) {
Events.createUseMedsButton().appendTo(btns);
}
// Set up the enemy attack timer
Events._enemyAttackTimer = setTimeout(Events.enemyAttack, scene.attackDelay * 1000);
},
createEatMeatButton: function(cooldown) {
if (cooldown == null) {
cooldown = Events._EAT_COOLDOWN;
}
var btn = new Button.Button({
id: 'eat',
text: 'eat meat',
cooldown: cooldown,
click: Events.eatMeat,
cost: { 'cured meat': 1 }
});
if(Path.outfit['cured meat'] == 0) {
Button.setDisabled(btn, true);
}
return btn;
},
createUseMedsButton: function(cooldown) {
if (cooldown == null) {
cooldown = Events._MEDS_COOLDOWN;
}
var btn = new Button.Button({
id: 'meds',
text: 'use meds',
cooldown: cooldown,
click: Events.useMeds,
cost: { 'medicine': 1 }
});
if((Path.outfit['medicine'] || 0) == 0) {
Button.setDisabled(btn, true);
}
return btn;
},
createAttackButton: function(weaponName) {
var weapon = World.Weapons[weaponName];
var cd = weapon.cooldown;
if(weapon.type == 'unarmed') {
if(Engine.hasPerk('unarmed master')) {
if($SM.hasPerk('unarmed master')) {
cd /= 2;
}
}
@@ -161,20 +198,46 @@ var Events = {
},
eatMeat: function() {
if(Events.activeEvent() && Path.outfit['cured meat'] > 0) {
if(Path.outfit['cured meat'] > 0) {
Path.outfit['cured meat']--;
World.updateSupplies();
if(Path.outfit['cured meat'] == 0) {
Button.setDisabled($('#eat'), true);
}
var w = $('#wanderer');
var hp = w.data('hp');
var hp = World.health;
hp += World.meatHeal();
hp = hp > World.getMaxHealth() ? World.getMaxHealth() : hp;
w.data('hp', hp);
World.setHp(hp);
Events.updateFighterDiv(w);
Events.drawFloatText('+' + World.meatHeal(), '#wanderer .hp');
if(Events.activeEvent()) {
var w = $('#wanderer');
w.data('hp', hp);
Events.updateFighterDiv(w);
Events.drawFloatText('+' + World.meatHeal(), '#wanderer .hp');
}
}
},
useMeds: function() {
if(Path.outfit['medicine'] > 0) {
Path.outfit['medicine']--;
World.updateSupplies();
if(Path.outfit['medicine'] == 0) {
Button.setDisabled($('#meds'), true);
}
var hp = World.health;
hp += World.medsHeal();
hp = hp > World.getMaxHealth() ? World.getMaxHealth() : hp;
World.setHp(hp);
if(Events.activeEvent()) {
var w = $('#wanderer');
w.data('hp', hp);
Events.updateFighterDiv(w);
Events.drawFloatText('+' + World.medsHeal(), '#wanderer .hp');
}
}
},
@@ -183,14 +246,14 @@ var Events = {
var weaponName = btn.attr('id').substring(7).replace('-', ' ');
var weapon = World.Weapons[weaponName];
if(weapon.type == 'unarmed') {
if(!State.punches) State.punches = 0;
State.punches++;
if(State.punches == 50 && !Engine.hasPerk('boxer')) {
Engine.addPerk('boxer');
} else if(State.punches == 150 && !Engine.hasPerk('martial artist')) {
Engine.addPerk('martial artist');
} else if(State.punches == 300 && !Engine.hasPerk('unarmed master')) {
Engine.addPerk('unarmed master');
if(!$SM.get('character.punches')) $SM.set('character.punches', 0);
$SM.add('character.punches', 1);
if($SM.get('character.punches') == 50 && !$SM.hasPerk('boxer')) {
$SM.addPerk('boxer');
} else if($SM.get('character.punches') == 150 && !$SM.hasPerk('martial artist')) {
$SM.addPerk('martial artist');
} else if($SM.get('character.punches') == 300 && !$SM.hasPerk('unarmed master')) {
$SM.addPerk('unarmed master');
}
}
@@ -234,16 +297,16 @@ var Events = {
if(Math.random() <= World.getHitChance()) {
dmg = weapon.damage;
if(typeof dmg == 'number') {
if(weapon.type == 'unarmed' && Engine.hasPerk('boxer')) {
dmg *= 2
}
if(weapon.type == 'unarmed' && Engine.hasPerk('martial artist')) {
dmg *= 3;
}
if(weapon.type == 'unarmed' && Engine.hasPerk('unarmed master')) {
if(weapon.type == 'unarmed' && $SM.hasPerk('boxer')) {
dmg *= 2;
}
if(weapon.type == 'melee' && Engine.hasPerk('barbarian')) {
if(weapon.type == 'unarmed' && $SM.hasPerk('martial artist')) {
dmg *= 3;
}
if(weapon.type == 'unarmed' && $SM.hasPerk('unarmed master')) {
dmg *= 2;
}
if(weapon.type == 'melee' && $SM.hasPerk('barbarian')) {
dmg = Math.floor(dmg * 1.5);
}
}
@@ -273,7 +336,7 @@ var Events = {
fighter.stop(true, true).animate(start, Events._FIGHT_SPEED, function() {
var enemyHp = enemy.data('hp');
var msg;
var msg = "";
if(typeof dmg == 'number') {
if(dmg < 0) {
msg = 'miss';
@@ -318,7 +381,7 @@ var Events = {
$('<div>').css(start).addClass('bullet').text('o').appendTo('#description')
.animate(end, Events._FIGHT_SPEED * 2, 'linear', function() {
var enemyHp = enemy.data('hp');
var msg;
var msg = "";
if(typeof dmg == 'number') {
if(dmg < 0) {
msg = 'miss';
@@ -357,7 +420,7 @@ var Events = {
if(!$('#enemy').data('stunned')) {
var toHit = scene.hit;
toHit *= Engine.hasPerk('evasive') ? 0.8 : 1;
toHit *= $SM.hasPerk('evasive') ? 0.8 : 1;
var dmg = -1;
if(Math.random() <= toHit) {
dmg = scene.damage;
@@ -410,6 +473,11 @@ var Events = {
},
text: 'leave'
}).appendTo(btns);
Events.createEatMeatButton(0).appendTo(btns);
if((Path.outfit['medicine'] || 0) != 0) {
Events.createUseMedsButton(0).appendTo(btns);
}
}
} catch(e) {
// It is possible to die and win if the timing is perfect. Just let it fail.
@@ -440,7 +508,7 @@ var Events = {
dropStuff: function(e) {
e.stopPropagation();
var btn = $(this)
var btn = $(this);
var thing = btn.data('thing');
var num = btn.data('num');
var lootButtons = $('#lootButtons');
@@ -461,7 +529,6 @@ var Events = {
Path.outfit[thing] -= num;
Events.getLoot(btn.closest('.button'));
World.updateSupplies();
$('#dropMenu').remove();
},
getLoot: function(btn) {
@@ -470,7 +537,6 @@ var Events = {
var weight = Path.getWeight(name);
var freeSpace = Path.getFreeSpace();
if(weight <= freeSpace) {
var loot = Events.activeEvent().scenes[Events.activeScene].loot[name];
var num = btn.data('numLeft');
num--;
btn.data('numLeft', num);
@@ -483,6 +549,7 @@ var Events = {
}
});
} else {
// #dropMenu gets removed by this.
btn.text(name + ' [' + num + ']');
}
var curNum = Path.outfit[name];
@@ -490,7 +557,14 @@ var Events = {
curNum++;
Path.outfit[name] = curNum;
World.updateSupplies();
} else {
// Update weight and free space variables so we can decide
// whether or not to bring up/update the drop menu.
weight = Path.getWeight(name);
freeSpace = Path.getFreeSpace();
}
if(weight > freeSpace && btn.data('numLeft') > 0) {
// Draw the drop menu
Engine.log('drop menu');
$('#dropMenu').remove();
@@ -520,8 +594,8 @@ var Events = {
}
},
createFighterDiv: function(char, hp, maxhp) {
var fighter = $('<div>').addClass('fighter').text(char).data('hp', hp).data('maxHp', maxhp);
createFighterDiv: function(chara, hp, maxhp) {
var fighter = $('<div>').addClass('fighter').text(chara).data('hp', hp).data('maxHp', maxhp);
$('<div>').addClass('hp').text(hp+'/'+maxhp).appendTo(fighter);
return fighter;
},
@@ -574,7 +648,7 @@ var Events = {
} else if(b.cost) {
var disabled = false;
for(var store in b.cost) {
var num = Engine.activeModule == World ? Path.outfit[store] : Engine.getStore(store);
var num = Engine.activeModule == World ? Path.outfit[store] : $SM.get('stores["'+store+'"]', true);
if(typeof num != 'number') num = 0;
if(num < b.cost[store]) {
// Too expensive
@@ -593,7 +667,7 @@ var Events = {
var costMod = {};
if(info.cost) {
for(var store in info.cost) {
var num = Engine.activeModule == World ? Path.outfit[store] : Engine.getStore(store);
var num = Engine.activeModule == World ? Path.outfit[store] : $SM.get('stores["'+store+'"]', true);
if(typeof num != 'number') num = 0;
if(num < info.cost[store]) {
// Too expensive
@@ -607,7 +681,7 @@ var Events = {
}
World.updateSupplies();
} else {
Engine.addStores(costMod);
$SM.addM('stores', costMod);
}
}
@@ -617,7 +691,7 @@ var Events = {
// Reward
if(info.reward) {
Engine.addStores(info.reward);
$SM.addM('stores', info.reward);
}
Events.updateButtons();
@@ -716,7 +790,7 @@ var Events = {
scheduleNextEvent: function(scale) {
var nextEvent = Math.floor(Math.random()*(Events._EVENT_TIME_RANGE[1] - Events._EVENT_TIME_RANGE[0])) + Events._EVENT_TIME_RANGE[0];
if(scale > 0) { nextEvent *= scale }
if(scale > 0) { nextEvent *= scale; }
Engine.log('next event scheduled in ' + nextEvent + ' minutes');
Events._eventTimeout = setTimeout(Events.triggerEvent, nextEvent * 60 * 1000);
},
@@ -730,6 +804,12 @@ var Events = {
Engine.keyLock = false;
// Force refocus on the body. I hate you, IE.
$('body').focus();
});
}
});
},
handleStateUpdates: function(e){
if(e.category == 'stores' && Events.activeEvent() != null){
Events.updateButtons();
}
}
};
+91 -36
View File
@@ -12,7 +12,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'snarling beast',
char: 'B',
chara: 'B',
damage: 1,
hit: 0.8,
attackDelay: 1,
@@ -47,7 +47,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'gaunt man',
char: 'G',
chara: 'G',
damage: 2,
hit: 0.8,
attackDelay: 2,
@@ -82,7 +82,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'strange bird',
char: 'B',
chara: 'B',
damage: 3,
hit: 0.8,
attackDelay: 2,
@@ -109,6 +109,46 @@ Events.Encounters = [
}
},
/* Tier 2*/
{ /* Shivering Man */
title: 'A Shivering Man',
isAvailable: function() {
return World.getDistance() > 10 && World.getDistance() <= 20 && World.getTerrain() == World.TILE.BARRENS;
},
scenes: {
'start': {
combat: true,
enemy: 'shivering man',
chara: 'S',
damage: 5,
hit: 0.5,
attackDelay: 1,
health: 20,
loot: {
'cloth': {
min: 1,
max: 1,
chance: 0.2
},
'teeth': {
min: 1,
max: 2,
chance: 0.8
},
'leather': {
min: 1,
max: 1,
chance: 0.2
},
'medicine': {
min: 1,
max: 3,
chance: 0.7
}
},
notification: 'a shivering man approaches and attacks with surprising strength'
}
}
},
{ /* Man-eater */
title: 'A Man-Eater',
isAvailable: function() {
@@ -118,7 +158,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'man-eater',
char: 'E',
chara: 'E',
damage: 3,
hit: 0.8,
attackDelay: 1,
@@ -153,7 +193,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'scavenger',
char: 'S',
chara: 'S',
damage: 4,
hit: 0.8,
attackDelay: 2,
@@ -169,11 +209,16 @@ Events.Encounters = [
max: 10,
chance: 0.8
},
'iron': {
min: 1,
max: 5,
chance: 0.5
}
'iron': {
min: 1,
max: 5,
chance: 0.5
},
'medicine': {
min: 1,
max: 2,
chance: 0.1
}
},
notification: 'a scavenger draws close, hoping for an easy score'
}
@@ -188,7 +233,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'lizard',
char: 'L',
chara: 'L',
damage: 5,
hit: 0.8,
attackDelay: 2,
@@ -224,7 +269,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'feral terror',
char: 'F',
chara: 'F',
damage: 6,
hit: 0.8,
attackDelay: 1,
@@ -260,7 +305,7 @@ Events.Encounters = [
combat: true,
enemy: 'soldier',
ranged: true,
char: 'D',
chara: 'D',
damage: 8,
hit: 0.8,
attackDelay: 2,
@@ -271,16 +316,21 @@ Events.Encounters = [
max: 10,
chance: 0.8
},
'bullets': {
min: 1,
max: 5,
chance: 0.5
},
'rifle': {
min: 1,
max: 1,
chance: 0.2
}
'bullets': {
min: 1,
max: 5,
chance: 0.5
},
'rifle': {
min: 1,
max: 1,
chance: 0.2
},
'medicine': {
min: 1,
max: 2,
chance: 0.1
}
},
notification: 'a soldier opens fire from across the desert'
}
@@ -295,7 +345,7 @@ Events.Encounters = [
'start': {
combat: true,
enemy: 'sniper',
char: 'S',
chara: 'S',
damage: 15,
hit: 0.8,
attackDelay: 4,
@@ -307,19 +357,24 @@ Events.Encounters = [
max: 10,
chance: 0.8
},
'bullets': {
min: 1,
max: 5,
chance: 0.5
},
'rifle': {
min: 1,
max: 1,
chance: 0.2
}
'bullets': {
min: 1,
max: 5,
chance: 0.5
},
'rifle': {
min: 1,
max: 1,
chance: 0.2
},
'medicine': {
min: 1,
max: 2,
chance: 0.1
}
},
notification: 'a shot rings out, from somewhere in the long grass'
}
}
},
];
}
];
+7 -7
View File
@@ -5,7 +5,7 @@ Events.Global = [
{ /* The Thief */
title: 'The Thief',
isAvailable: function() {
return (Engine.activeModule == Room || Engine.activeModule == Outside) && State.thieves == 1;
return (Engine.activeModule == Room || Engine.activeModule == Outside) && $SM.get('game.thieves') == 1;
},
scenes: {
'start': {
@@ -32,9 +32,9 @@ Events.Global = [
'the point is made. in the next few days, the missing supplies are returned.'
],
onLoad: function() {
State.thieves = 2;
Engine.removeIncome('thieves');
Engine.addStores(State.stolen);
$SM.set('game.thieves', 2);
$SM.remove('income.thieves');
$SM.addM('stores', $SM.get('game.stolen'));
},
buttons: {
'leave': {
@@ -49,9 +49,9 @@ Events.Global = [
"shares what he knows about sneaking before he goes."
],
onLoad: function() {
State.thieves = 2;
Engine.removeIncome('thieves');
Engine.addPerk('stealthy');
$SM.set('game.thieves', 2);
$SM.remove('income.thieves');
$SM.addPerk('stealthy');
},
buttons: {
'leave': {
+122 -5
View File
@@ -5,7 +5,7 @@ Events.Outside = [
{ /* Ruined traps */
title: 'A Ruined Trap',
isAvailable: function() {
return Engine.activeModule == Outside && Outside.numBuilding('trap') > 0;
return Engine.activeModule == Outside && $SM.get('game.buildings["trap"]', true) > 0;
},
scenes: {
'start': {
@@ -14,8 +14,8 @@ Events.Outside = [
'large prints lead away, into the forest.'
],
onLoad: function() {
var numWrecked = Math.floor(Math.random() * Outside.numBuilding('trap')) + 1;
Outside.addBuilding('trap', -numWrecked);
var numWrecked = Math.floor(Math.random() * $SM.get('game.buildings["trap"]', true)) + 1;
$SM.add('game.buildings["trap"]', -numWrecked);
Outside.updateVillage();
Outside.updateTrapButton();
},
@@ -63,10 +63,127 @@ Events.Outside = [
}
},
{ /* 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.'
],
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.'
],
buttons: {
'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 && Outside.getPopulation() > 0;
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0;
},
scenes: {
'start': {
@@ -97,7 +214,7 @@ Events.Outside = [
{ /* Soldier attack */
title: 'A Military Raid',
isAvailable: function() {
return Engine.activeModule == Outside && Outside.getPopulation() > 0 && State.cityCleared;
return Engine.activeModule == Outside && $SM.get('game.population', true) > 0 && $SM.get('game.cityCleared');;
},
scenes: {
'start': {
+124 -37
View File
@@ -5,7 +5,7 @@ Events.Room = [
{ /* The Nomad -- Merchant */
title: 'The Nomad',
isAvailable: function() {
return Engine.activeModule == Room && Engine.getStore('fur') > 0;
return Engine.activeModule == Room && $SM.get('stores.fur', true) > 0;
},
scenes: {
'start': {
@@ -33,13 +33,13 @@ Events.Room = [
},
'buyCompass': {
available: function() {
return Engine.getStore('compass') < 1;
return $SM.get('stores.compass', true) < 1;
},
text: 'buy compass',
cost: { fur: 300, scales: 15, teeth: 5 },
reward: { 'compass': 1 },
notification: 'the old compass is dented and dusty, but it looks to work.',
onChoose: Engine.openPath
onChoose: Path.openPath
},
'goodbye': {
text: 'say goodbye',
@@ -51,7 +51,7 @@ Events.Room = [
}, { /* Noises Outside -- gain wood/fur */
title: 'Noises',
isAvailable: function() {
return Engine.activeModule == Room && Engine.storeAvailable('wood');
return Engine.activeModule == Room && $SM.get('stores.wood');
},
scenes: {
'start': {
@@ -86,7 +86,7 @@ Events.Room = [
'stuff': {
reward: { wood: 100, fur: 10 },
text: [
'a bundle of stick lies just beyond the threshold, wrapped in course furs.',
'a bundle of sticks lies just beyond the threshold, wrapped in coarse furs.',
'the night is silent.'
],
buttons: {
@@ -101,7 +101,7 @@ Events.Room = [
{ /* Noises Inside -- trade wood for better good */
title: 'Noises',
isAvailable: function() {
return Engine.activeModule == Room && Engine.storeAvailable('wood');
return Engine.activeModule == Room && $SM.get('stores.wood');
},
scenes: {
start: {
@@ -127,12 +127,12 @@ Events.Room = [
'the ground is littered with small scales'
],
onLoad: function() {
var numWood = Engine.getStore('wood');
var numWood = $SM.get('stores.wood', true);
numWood = Math.floor(numWood * 0.1);
if(numWood == 0) numWood = 1;
var numScales = Math.floor(numWood / 5);
if(numScales == 0) numScales = 1;
Engine.addStores({wood: -numWood, scales: numScales});
$SM.addM('stores', {'wood': -numWood, 'scales': numScales});
},
buttons: {
'leave': {
@@ -147,12 +147,12 @@ Events.Room = [
'the ground is littered with small teeth'
],
onLoad: function() {
var numWood = Engine.getStore('wood');
var numWood = $SM.get('stores.wood', true);
numWood = Math.floor(numWood * 0.1);
if(numWood == 0) numWood = 1;
var numTeeth = Math.floor(numWood / 5);
if(numTeeth == 0) numTeeth = 1;
Engine.addStores({wood: -numWood, teeth: numTeeth});
$SM.addM('stores', {'wood': -numWood, 'teeth': numTeeth});
},
buttons: {
'leave': {
@@ -167,12 +167,12 @@ Events.Room = [
'the ground is littered with scraps of cloth'
],
onLoad: function() {
var numWood = Engine.getStore('wood');
var numWood = $SM.get('stores.wood', true);
numWood = Math.floor(numWood * 0.1);
if(numWood == 0) numWood = 1;
var numCloth = Math.floor(numWood / 5);
if(numCloth == 0) numCloth = 1;
Engine.addStores({wood: -numWood, cloth: numCloth});
$SM.addM('stores', {'wood': -numWood, 'cloth': numCloth});
},
buttons: {
'leave': {
@@ -186,7 +186,7 @@ Events.Room = [
{ /* The Beggar -- trade fur for better good */
title: 'The Beggar',
isAvailable: function() {
return Engine.activeModule == Room && Engine.storeAvailable('fur');
return Engine.activeModule == Room && $SM.get('stores.fur');
},
scenes: {
start: {
@@ -215,7 +215,7 @@ Events.Room = [
scales: {
reward: { scales: 20 },
text: [
'the beggar thanks you.',
'the beggar expresses his thanks.',
'leaves a pile of small scales behind.'
],
buttons: {
@@ -228,7 +228,7 @@ Events.Room = [
teeth: {
reward: { teeth: 20 },
text: [
'the beggar thanks you.',
'the beggar expresses his thanks.',
'leaves a pile of small teeth behind.'
],
buttons: {
@@ -241,7 +241,7 @@ Events.Room = [
cloth: {
reward: { cloth: 20 },
text: [
'the beggar thanks you.',
'the beggar expresses his thanks.',
'leaves some scraps of cloth behind.'
],
buttons: {
@@ -257,7 +257,7 @@ Events.Room = [
{ /* Mysterious Wanderer -- wood gambling */
title: 'The Mysterious Wanderer',
isAvailable: function() {
return Engine.activeModule == Room && Engine.storeAvailable('wood');
return Engine.activeModule == Room && $SM.get('stores.wood');
},
scenes: {
start: {
@@ -285,12 +285,12 @@ Events.Room = [
},
'100wood': {
text: [
'the wanderer leaves, cart loaded with wood',
'the wanderer leaves, cart loaded with wood'
],
onLoad: function() {
if(Math.random() < 0.5) {
setTimeout(function() {
Engine.addStore('wood', 300);
$SM.add('stores.wood', 300);
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with wood.');
}, 60 * 1000);
}
@@ -304,12 +304,12 @@ Events.Room = [
},
'500wood': {
text: [
'the wanderer leaves, cart loaded with wood',
'the wanderer leaves, cart loaded with wood'
],
onLoad: function() {
if(Math.random() < 0.3) {
setTimeout(function() {
Engine.addStore('wood', 1500);
$SM.add('stores.wood', 1500);
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with wood.');
}, 60 * 1000);
}
@@ -327,7 +327,7 @@ Events.Room = [
{ /* Mysterious Wanderer -- fur gambling */
title: 'The Mysterious Wanderer',
isAvailable: function() {
return Engine.activeModule == Room && Engine.storeAvailable('fur');
return Engine.activeModule == Room && $SM.get('stores.fur');
},
scenes: {
start: {
@@ -355,12 +355,12 @@ Events.Room = [
},
'100fur': {
text: [
'the wanderer leaves, cart loaded with furs',
'the wanderer leaves, cart loaded with furs'
],
onLoad: function() {
if(Math.random() < 0.5) {
setTimeout(function() {
Engine.addStore('fur', 300);
$SM.add('stores.fur', 300);
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with furs.');
}, 60 * 1000);
}
@@ -374,12 +374,12 @@ Events.Room = [
},
'500fur': {
text: [
'the wanderer leaves, cart loaded with furs',
'the wanderer leaves, cart loaded with furs'
],
onLoad: function() {
if(Math.random() < 0.3) {
setTimeout(function() {
Engine.addStore('fur', 1500);
$SM.add('stores.fur', 1500);
Notifications.notify(Room, 'the mysterious wanderer returns, cart piled high with furs.');
}, 60 * 1000);
}
@@ -397,7 +397,7 @@ Events.Room = [
{ /* The Scout -- Map Merchant */
title: 'The Scout',
isAvailable: function() {
return Engine.activeModule == Room && typeof State.world == 'object';
return Engine.activeModule == Room && $SM.get('features.location.world');
},
scenes: {
'start': {
@@ -417,10 +417,10 @@ Events.Room = [
text: 'learn scouting',
cost: { 'fur': 1000, 'scales': 50, 'teeth': 20 },
available: function() {
return !Engine.hasPerk('scout');
return !$SM.hasPerk('scout');
},
onChoose: function() {
Engine.addPerk('scout');
$SM.addPerk('scout');
}
},
'leave': {
@@ -435,7 +435,7 @@ Events.Room = [
{ /* The Wandering Master */
title: 'The Master',
isAvailable: function() {
return Engine.activeModule == Room && typeof State.world == 'object';
return Engine.activeModule == Room && $SM.get('features.location.world');
},
scenes: {
'start': {
@@ -468,30 +468,30 @@ Events.Room = [
'evasion': {
text: 'evasion',
available: function() {
return !Engine.hasPerk('evasive');
return !$SM.hasPerk('evasive');
},
onChoose: function() {
Engine.addPerk('evasive');
$SM.addPerk('evasive');
},
nextScene: 'end'
},
'precision': {
text: 'precision',
available: function() {
return !Engine.hasPerk('precise');
return !$SM.hasPerk('precise');
},
onChoose: function() {
Engine.addPerk('precise');
$SM.addPerk('precise');
},
nextScene: 'end'
},
'force': {
text: 'force',
available: function() {
return !Engine.hasPerk('barbarian');
return !$SM.hasPerk('barbarian');
},
onChoose: function() {
Engine.addPerk('barbarian');
$SM.addPerk('barbarian');
},
nextScene: 'end'
},
@@ -502,5 +502,92 @@ Events.Room = [
}
}
}
},
{ /* The Sick Man */
title: 'The Sick Man',
isAvailable: function() {
return Engine.activeModule == Room && $SM.get('stores.medicine', true) > 0;
},
scenes: {
'start': {
text: [
"a man hobbles up, coughing.",
"he begs for medicine."
],
notification: 'a sick man hobbles up',
buttons: {
'help': {
text: 'give 1 medicine',
cost: { 'medicine': 1 },
notification: 'the man swallows the medicine eagerly',
nextScene: { 0.1: 'alloy', 0.3: 'cells', 0.5: 'scales', 1.0: 'nothing' }
},
'ignore': {
text: 'tell him to leave',
nextScene: 'end'
}
}
},
'alloy': {
text: [
"the man is thankful.",
'he leaves a reward.',
'some weird metal he picked up on his travels.'
],
onLoad: function() {
$SM.add('stores["alien alloy"]', 1);
},
buttons: {
'bye': {
text: 'say goodbye',
nextScene: 'end'
}
}
},
'cells': {
text: [
"the man is thankful.",
'he leaves a reward.',
'some weird glowing boxes he picked up on his travels.'
],
onLoad: function() {
$SM.add('stores["energy cell"]', 3);
},
buttons: {
'bye': {
text: 'say goodbye',
nextScene: 'end'
}
}
},
'scales': {
text: [
"the man is thankful.",
'he leaves a reward.',
'all he has are some scales.'
],
onLoad: function() {
$SM.add('stores.scales', 5);
},
buttons: {
'bye': {
text: 'say goodbye',
nextScene: 'end'
}
}
},
'nothing': {
text: [
"the man expresses his thanks and hobbles off."
],
buttons: {
'bye': {
text: 'say goodbye',
nextScene: 'end'
}
}
}
}
}
]
];
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -43,8 +43,8 @@ var Notifications = {
Engine.saveGame();
},
printMessage: function(text) {
var text = $('<div>').addClass('notification').css('opacity', '0').text(text).prependTo('div#notifications');
printMessage: function(t) {
var text = $('<div>').addClass('notification').css('opacity', '0').text(t).prependTo('div#notifications');
text.animate({opacity: 1}, 500, 'linear');
},
+117 -127
View File
@@ -135,12 +135,14 @@ var Outside = {
.addClass('location')
.appendTo('div#locationSlider');
if(typeof State.outside == 'undefined') {
State.outside = {
buildings: {},
population: 0,
workers: {}
}
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Outside.handleStateUpdates);
if(typeof $SM.get('features.location.outside') == 'undefined') {
$SM.set('features.location.outside', true);
if(!$SM.get('game.buildings')) $SM.set('game.buildings', {});
if(!$SM.get('game.population')) $SM.set('game.population', 0);
if(!$SM.get('game.workers')) $SM.set('game.workers', {});
}
this.updateVillage();
@@ -158,46 +160,12 @@ var Outside = {
}).appendTo('div#outsidePanel');
},
numBuilding: function(bName) {
return State.outside &&
State.outside.buildings &&
State.outside.buildings[bName] ? State.outside.buildings[bName] : 0;
},
addBuilding: function(bName, num) {
var cur = State.outside.buildings[bName];
if(typeof cur != 'number') cur = 0;
cur += num;
if(cur < 0) cur = 0;
State.outside.buildings[bName] = cur;
this.updateVillage();
Engine.saveGame();
},
addBuildings: function(list) {
for(k in list) {
var num = State.outside.buildings[k];
if(typeof num != 'number') num = 0;
num += list[k];
State.outside.buildings[k] = num;
}
this.updateVillage();
Engine.saveGame();
},
getMaxPopulation: function() {
return Outside.numBuilding('hut') * 4;
},
getPopulation: function() {
if(State.outside && State.outside.population) {
return State.outside.population;
}
return 0;
return $SM.get('game.buildings["hut"]', true) * 4;
},
increasePopulation: function() {
var space = Outside.getMaxPopulation() - State.outside.population;
var space = Outside.getMaxPopulation() - $SM.get('game.population');
if(space > 0) {
var num = Math.floor(Math.random()*(space/2) + space/2);
if(num == 0) num = 1;
@@ -213,36 +181,30 @@ var Outside = {
Notifications.notify(null, "the town's booming. word does get around.");
}
Engine.log('population increased by ' + num);
State.outside.population += num;
Outside.updateVillage();
Outside.updateWorkersView();
Outside.updateVillageIncome();
$SM.add('game.population', num);
}
Outside.schedulePopIncrease();
},
killVillagers: function(num) {
State.outside.population -= num;
if(State.outside.population < 0) {
State.outside.population = 0;
$SM.add('game.population', num * -1);
if($SM.get('game.population') < 0) {
$SM.set('game.population', 0);
}
var remaining = Outside.getNumGatherers();
if(remaining < 0) {
var gap = -remaining;
for(var k in State.outside.workers) {
var num = State.outside.workers[k];
for(var k in $SM.get('game.workers')) {
var num = $SM.get('game.workers["'+k+'"]');
if(num < gap) {
gap -= num;
State.outside.workers[k] = 0;
$SM.set('game.workers["'+k+'"]', 0);
} else {
State.outside.workers[k] -= gap;
$SM.add('game.workers["'+k+'"]', gap * -1);
break;
}
}
}
Outside.updateVillage();
Outside.updateWorkersView();
Outside.updateVillageIncome();
},
schedulePopIncrease: function() {
@@ -252,21 +214,26 @@ var Outside = {
},
updateWorkersView: function() {
if(State.outside.population == 0) return;
var workers = $('div#workers');
// If our population is 0 and we don't already have a workers view,
// there's nothing to do here.
if(!workers.length && $SM.get('game.population') == 0) return;
var needsAppend = false;
if(workers.length == 0) {
needsAppend = true;
workers = $('<div>').attr('id', 'workers').css('opacity', 0);
}
var numGatherers = State.outside.population;
var numGatherers = $SM.get('game.population');
var gatherer = $('div#workers_row_gatherer', workers);
for(var k in State.outside.workers) {
for(var k in $SM.get('game.workers')) {
var workerCount = $SM.get('game.workers["'+k+'"]');
var row = $('div#workers_row_' + k.replace(' ', '-'), workers);
if(row.length == 0) {
row = Outside.makeWorkerRow(k, State.outside.workers[k]);
row = Outside.makeWorkerRow(k, workerCount);
var curPrev = null;
workers.children().each(function(i) {
@@ -291,13 +258,15 @@ var Outside = {
}
} else {
$('div#' + row.attr('id') + ' > div.row_val > span', workers).text(State.outside.workers[k]);
$('div#' + row.attr('id') + ' > div.row_val > span', workers).text(workerCount);
}
numGatherers -= State.outside.workers[k];
if(State.outside.workers[k] == 0) {
numGatherers -= workerCount;
if(workerCount == 0) {
$('.dnBtn', row).addClass('disabled');
$('.dnManyBtn', row).addClass('disabled');
} else {
$('.dnBtn', row).removeClass('disabled');
$('.dnManyBtn', row).removeClass('disabled');
}
}
@@ -310,8 +279,10 @@ var Outside = {
if(numGatherers == 0) {
$('.upBtn', '#workers').addClass('disabled');
$('.upManyBtn', '#workers').addClass('disabled');
} else {
$('.upBtn', '#workers').removeClass('disabled');
$('.upManyBtn', '#workers').removeClass('disabled');
}
@@ -321,9 +292,9 @@ var Outside = {
},
getNumGatherers: function() {
var num = State.outside.population;
for(var k in State.outside.workers) {
num -= State.outside.workers[k];
var num = $SM.get('game.population');
for(var k in $SM.get('game.workers')) {
num -= $SM.get('game.workers["'+k+'"]');
}
return num;
},
@@ -338,8 +309,10 @@ var Outside = {
$('<span>').text(num).appendTo(val);
if(name != 'gatherer') {
$('<div>').addClass('upBtn').appendTo(val).click(Outside.increaseWorker);
$('<div>').addClass('dnBtn').appendTo(val).click(Outside.decreaseWorker);
$('<div>').addClass('upManyBtn').appendTo(val).click([10], Outside.increaseWorker);
$('<div>').addClass('upBtn').appendTo(val).click([1], Outside.increaseWorker);
$('<div>').addClass('dnBtn').appendTo(val).click([1], Outside.decreaseWorker);
$('<div>').addClass('dnManyBtn').appendTo(val).click([10], Outside.decreaseWorker);
}
$('<div>').addClass('clear').appendTo(row);
@@ -359,56 +332,54 @@ var Outside = {
increaseWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(Outside.getNumGatherers() > 0) {
Engine.log('increasing ' + worker);
State.outside.workers[worker]++;
Outside.updateVillageIncome();
Outside.updateWorkersView();
var increaseAmt = Math.min(Outside.getNumGatherers(), btn.data);
Engine.log('increasing ' + worker + ' by ' + increaseAmt);
$SM.add('game.workers["'+worker+'"]', increaseAmt);
}
},
decreaseWorker: function(btn) {
var worker = $(this).closest('.workerRow').children('.row_key').text();
if(State.outside.workers[worker] > 0) {
Engine.log('decreasing ' + worker);
State.outside.workers[worker]--;
Outside.updateVillageIncome();
Outside.updateWorkersView();
if($SM.get('game.workers["'+worker+'"]') > 0) {
var decreaseAmt = Math.min($SM.get('game.workers["'+worker+'"]') || 0, btn.data);
Engine.log('decreasing ' + worker + ' by ' + decreaseAmt);
$SM.add('game.workers["'+worker+'"]', decreaseAmt * -1);
}
},
updateVillageRow: function(name, num, village) {
var id = 'building_row_' + name.replace(' ', '-');
var row = $('div#' + id, village);
if(row.length == 0 && num > 0) {
var row = $('<div>').attr('id', id).addClass('storeRow');
$('<div>').addClass('row_key').text(name).appendTo(row);
$('<div>').addClass('row_val').text(num).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
var curPrev = null;
village.children().each(function(i) {
var child = $(this);
if(child.attr('id') != 'population') {
var cName = child.attr('id').substring(13).replace('-', ' ');
if(cName < name && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
if(row.length == 0 && num > 0) {
row = $('<div>').attr('id', id).addClass('storeRow');
$('<div>').addClass('row_key').text(name).appendTo(row);
$('<div>').addClass('row_val').text(num).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
var curPrev = null;
village.children().each(function(i) {
var child = $(this);
if(child.attr('id') != 'population') {
var cName = child.attr('id').substring(13).replace('-', ' ');
if(cName < name && (curPrev == null || cName > curPrev)) {
curPrev = cName;
}
});
if(curPrev == null) {
row.prependTo(village);
} else {
row.insertAfter('#building_row_' + curPrev.replace(' ', '-'));
}
} else if(num > 0) {
$('div#' + row.attr('id') + ' > div.row_val', village).text(num);
} else if(num == 0) {
row.remove();
});
if(curPrev == null) {
row.prependTo(village);
} else {
row.insertAfter('#building_row_' + curPrev.replace(' ', '-'));
}
} else if(num > 0) {
$('div#' + row.attr('id') + ' > div.row_val', village).text(num);
} else if(num == 0) {
row.remove();
}
},
updateVillage: function() {
updateVillage: function(ignoreStores) {
var village = $('div#village');
var pop = $('div#population');
var population = $('div#population');
var needsAppend = false;
if(village.length == 0) {
needsAppend = true;
@@ -416,10 +387,10 @@ var Outside = {
population = $('<div>').attr('id', 'population').appendTo(village);
}
for(var k in State.outside.buildings) {
for(var k in $SM.get('game.buildings')) {
if(k == 'trap') {
var numTraps = State.outside.buildings[k];
var numBait = Engine.getStore('bait');
var numTraps = $SM.get('game.buildings["'+k+'"]');
var numBait = $SM.get('stores.bait', true);
var traps = numTraps - numBait;
traps = traps < 0 ? 0 : traps;
Outside.updateVillageRow(k, traps, village);
@@ -428,14 +399,14 @@ var Outside = {
if(Outside.checkWorker(k)) {
Outside.updateWorkersView();
}
Outside.updateVillageRow(k, State.outside.buildings[k], village);
Outside.updateVillageRow(k, $SM.get('game.buildings["'+k+'"]'), village);
}
}
population.text('pop ' + State.outside.population + '/' + this.getMaxPopulation());
population.text('pop ' + $SM.get('game.population') + '/' + this.getMaxPopulation());
var hasPeeps;
if(Outside.numBuilding('hut') == 0) {
if($SM.get('game.buildings["hut"]', true) == 0) {
hasPeeps = false;
village.addClass('noHuts');
} else {
@@ -453,6 +424,10 @@ var Outside = {
}
this.setTitle();
if(!ignoreStores && Engine.activeModule === Outside && village.children().length > 1) {
$('#storesContainer').css({top: village.height() + 26 + 'px'});
}
},
checkWorker: function(name) {
@@ -465,17 +440,17 @@ var Outside = {
'sulphur mine': ['sulphur miner'],
'steelworks': ['steelworker'],
'armoury' : ['armourer']
}
};
var jobs = jobMap[name];
var added = false;
if(typeof jobs == 'object') {
for(var i = 0, len = jobs.length; i < len; i++) {
var job = jobs[i];
if(typeof State.outside.buildings[name] == 'number' &&
typeof State.outside.workers[job] != 'number') {
Engine.log('adding ' + job + ' to the workers list')
State.outside.workers[job] = 0;
if(typeof $SM.get('game.buildings["'+name+'"]') == 'number' &&
typeof $SM.get('game.workers["'+job+'"]') != 'number') {
Engine.log('adding ' + job + ' to the workers list');
$SM.set('game.workers["'+job+'"]', 0);
added = true;
}
}
@@ -486,14 +461,14 @@ var Outside = {
updateVillageIncome: function() {
for(var worker in Outside._INCOME) {
var income = Outside._INCOME[worker];
var num = worker == 'gatherer' ? Outside.getNumGatherers() : State.outside.workers[worker];
var num = worker == 'gatherer' ? Outside.getNumGatherers() : $SM.get('game.workers["'+worker+'"]');
if(typeof num == 'number') {
var stores = {};
if(num < 0) num = 0;
var tooltip = $('.tooltip', 'div#workers_row_' + worker.replace(' ', '-'));
tooltip.empty();
var needsUpdate = false;
var curIncome = Engine.getIncome(worker);
var curIncome = $SM.getIncome(worker);
for(var store in income.stores) {
stores[store] = income.stores[store] * num;
if(curIncome[store] != stores[store]) needsUpdate = true;
@@ -503,7 +478,7 @@ var Outside = {
row.appendTo(tooltip);
}
if(needsUpdate) {
Engine.setIncome(worker, {
$SM.setIncome(worker, {
delay: income.delay,
stores: stores
});
@@ -515,7 +490,7 @@ var Outside = {
updateTrapButton: function() {
var btn = $('div#trapsButton');
if(Outside.numBuilding('trap') > 0) {
if($SM.get('game.buildings["trap"]', true) > 0) {
if(btn.length == 0) {
new Button.Button({
id: 'trapsButton',
@@ -535,7 +510,7 @@ var Outside = {
},
setTitle: function() {
var numHuts = this.numBuilding('hut');
var numHuts = $SM.get('game.buildings["hut"]', true);
var title;
if(numHuts == 0) {
title = "A Silent Forest";
@@ -557,32 +532,36 @@ var Outside = {
$('#location_outside').text(title);
},
onArrival: function() {
onArrival: function(transition_diff) {
Outside.setTitle();
if(!State.seenForest) {
if(!$SM.get('game.outside.seenForest')) {
Notifications.notify(Outside, "the sky is grey and the wind blows relentlessly");
State.seenForest = true;
$SM.set('game.outside.seenForest', true);
}
Outside.updateTrapButton();
Outside.updateVillage(true);
Engine.moveStoresView($('#village'), transition_diff);
},
gatherWood: function() {
Notifications.notify(Outside, "dry brush and dead branches litter the forest floor")
Engine.setStore('wood', Engine.getStore('wood') + (Outside.numBuilding('cart') > 0 ? 50 : 10));
Notifications.notify(Outside, "dry brush and dead branches litter the forest floor");
var gatherAmt = $SM.get('game.buildings["cart"]', true) > 0 ? 50 : 10;
$SM.add('stores.wood', gatherAmt);
},
checkTraps: function() {
var drops = {};
var msg = [];
var numTraps = Outside.numBuilding('trap');
var numBait = Engine.getStore('bait');
var numTraps = $SM.get('game.buildings["trap"]', true);
var numBait = $SM.get('stores.bait', true);
var numDrops = numTraps + (numBait < numTraps ? numBait : numTraps);
for(var i = 0; i < numDrops; i++) {
var roll = Math.random();
for(var j in Outside.TrapDrops) {
var drop = Outside.TrapDrops[j];
if(roll < drop.rollUnder) {
var num = drops[drop.name]
var num = drops[drop.name];
if(typeof num == 'undefined') {
num = 0;
msg.push(drop.message);
@@ -606,6 +585,17 @@ var Outside = {
drops['bait'] = -baitUsed;
Notifications.notify(Outside, s);
Engine.addStores(drops);
$SM.addM('stores', drops);
},
handleStateUpdates: function(e){
if(e.category == 'stores'){
Outside.updateVillage();
} else if(e.stateName.indexOf('game.workers') == 0
|| e.stateName.indexOf('game.population') == 0){
Outside.updateVillage();
Outside.updateWorkersView();
Outside.updateVillageIncome();
};
}
}
};
+57 -26
View File
@@ -35,7 +35,7 @@ var Path = {
// Add the outfitting area
var outfitting = $('<div>').attr('id', 'outfitting').appendTo(this.panel);
var bagspace = $('<div>').attr('id', 'bagspace').appendTo(outfitting);
$('<div>').attr('id', 'bagspace').appendTo(outfitting);
// Add the embark button
new Button.Button({
@@ -49,6 +49,15 @@ var Path = {
Path.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) {
@@ -59,11 +68,11 @@ var Path = {
},
getCapacity: function() {
if(Engine.getStore('convoy') > 0) {
if($SM.get('stores.convoy', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 60;
} else if(Engine.getStore('wagon') > 0) {
} else if($SM.get('stores.wagon', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 30;
} else if(Engine.getStore('rucksack') > 0) {
} else if($SM.get('stores.rucksack', true) > 0) {
return Path.DEFAULT_BAG_SPACE + 10;
}
return Path.DEFAULT_BAG_SPACE;
@@ -85,17 +94,17 @@ var Path = {
},
updatePerks: function() {
if(State.perks) {
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 State.perks) {
for(var k in $SM.get('character.perks')) {
var id = 'perk_' + k.replace(' ', '-');
var r = $('#' + id);
if(State.perks[k] && r.length == 0) {
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);
@@ -105,6 +114,10 @@ var Path = {
if(needsAppend && perks.children().length > 0) {
perks.appendTo(Path.panel);
}
if(Engine.activeModule === Path) {
$('#storesContainer').css({top: perks.height() + 26 + 'px'});
}
}
},
@@ -117,11 +130,11 @@ var Path = {
// Add the armour row
var armour = "none";
if(Engine.getStore('s armour') > 0)
if($SM.get('stores["s armour"]', true) > 0)
armour = "steel";
else if(Engine.getStore('i armour') > 0)
else if($SM.get('stores["i armour"]', true) > 0)
armour = "iron";
else if(Engine.getStore('l armour') > 0)
else if($SM.get('stores["l armour"]', true) > 0)
armour = "leather";
var aRow = $('#armourRow');
if(aRow.length == 0) {
@@ -156,15 +169,16 @@ var Path = {
'laser rifle': {type: 'weapon' },
'energy cell': {type: 'tool' },
'bayonet': {type: 'weapon' },
'charm': {type: 'tool'}
'charm': {type: 'tool'},
'medicine': {type: 'tool'}
}, Room.Craftables);
for(var k in carryable) {
var store = carryable[k];
var have = State.stores[k];
var have = $SM.get('stores["'+k+'"]');
var num = Path.outfit[k];
num = typeof num == 'number' ? num : 0;
var numAvailable = Engine.getStore(k);
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);
@@ -194,13 +208,17 @@ var Path = {
}
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();
@@ -223,11 +241,13 @@ var Path = {
var val = $('<div>').addClass('row_val').appendTo(row);
$('<span>').text(num).appendTo(val);
$('<div>').addClass('upBtn').appendTo(val).click(Path.increaseSupply);
$('<div>').addClass('dnBtn').appendTo(val).click(Path.decreaseSupply);
$('<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 = Engine.getStore(name);
var numAvailable = $SM.get('stores["'+name+'"]', 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(name)).appendTo(tt);
@@ -237,32 +257,37 @@ var Path = {
return row;
},
increaseSupply: function() {
increaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('increasing ' + supply);
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 < Engine.getStore(supply)) {
Path.outfit[supply] = cur + 1;
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));
Path.updateOutfitting();
}
},
decreaseSupply: function() {
decreaseSupply: function(btn) {
var supply = $(this).closest('.outfitRow').children('.row_key').text().replace('-', ' ');
Engine.log('decreasing ' + supply);
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] = cur - 1;
Path.outfit[supply] = Math.max(0, cur - btn.data);
Path.updateOutfitting();
}
},
onArrival: function() {
onArrival: function(transition_diff) {
Path.setTitle();
Path.updateOutfitting();
Path.updatePerks();
Engine.moveStoresView($('#perks'), transition_diff);
},
setTitle: function() {
@@ -271,10 +296,16 @@ var Path = {
embark: function() {
for(var k in Path.outfit) {
Engine.addStore(k, -Path.outfit[k]);
$SM.add('stores["'+k+'"]', -Path.outfit[k]);
}
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();
};
}
}
};
+106
View File
@@ -0,0 +1,106 @@
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;
}
};
+167 -128
View File
@@ -9,6 +9,10 @@ var Room = {
_STOKE_COOLDOWN: 10, // cooldown to stoke the fire
_NEED_WOOD_DELAY: 15 * 1000, // from when the stranger shows up, to when you need wood
fire:null,
temperature:null,
buttons:{},
Craftables: {
'trap': {
button: null,
@@ -18,7 +22,7 @@ var Room = {
maxMsg: "more traps won't help now",
type: 'building',
cost: function() {
var n = Outside.numBuilding('trap');
var n = $SM.get('game.buildings["trap"]', true);
return {
'wood': 10 + (n*10)
};
@@ -44,7 +48,7 @@ var Room = {
maxMsg: 'no more room for huts.',
type: 'building',
cost: function() {
var n = Outside.numBuilding('hut');
var n = $SM.get('game.buildings["hut"]', true);
return {
'wood': 100 + (n*50)
};
@@ -61,7 +65,7 @@ var Room = {
wood: 200,
fur: 10,
meat: 5
}
};
}
},
'trading post': {
@@ -257,7 +261,7 @@ var Room = {
return {
'leather': 200,
'iron': 100
}
};
}
},
's armour': {
@@ -268,7 +272,7 @@ var Room = {
return {
'leather': 200,
'steel': 100
}
};
}
},
'iron sword': {
@@ -303,7 +307,7 @@ var Room = {
'wood': 200,
'steel': 50,
'sulphur': 50
}
};
}
}
},
@@ -327,7 +331,7 @@ var Room = {
return {
'fur': 150,
'scales': 50
}
};
}
},
'coal': {
@@ -336,7 +340,7 @@ var Room = {
return {
'fur': 200,
'teeth': 50
}
};
}
},
'steel': {
@@ -346,7 +350,15 @@ var Room = {
'fur': 300,
'scales': 50,
'teeth': 50
}
};
}
},
'medicine': {
type: 'good',
cost: function() {
return {
'scales': 50, 'teeth': 30
};
}
},
'bullets': {
@@ -354,7 +366,7 @@ var Room = {
cost: function() {
return {
'scales': 10
}
};
}
},
'energy cell': {
@@ -363,7 +375,7 @@ var Room = {
return {
'scales': 10,
'teeth': 10
}
};
}
},
'bolas': {
@@ -371,7 +383,7 @@ var Room = {
cost: function() {
return {
'teeth': 10
}
};
}
},
'grenade': {
@@ -380,7 +392,7 @@ var Room = {
return {
'scales': 100,
'teeth': 50
}
};
}
},
'bayonet': {
@@ -389,7 +401,7 @@ var Room = {
return {
'scales': 500,
'teeth': 250
}
};
}
},
'alien alloy': {
@@ -399,7 +411,7 @@ var Room = {
'fur': 1500,
'scales': 750,
'teeth': 300
}
};
}
},
'compass': {
@@ -415,6 +427,12 @@ var Room = {
}
},
MiscItems: {
'laser rifle': {
type: 'weapon'
}
},
name: "Room",
init: function(options) {
this.options = $.extend(
@@ -423,21 +441,21 @@ var Room = {
);
if(Engine._debug) {
this._ROOM_WARM_DELAY = 1;
this._BUILDER_STATE_DELAY = 1;
this._ROOM_WARM_DELAY = 5000;
this._BUILDER_STATE_DELAY = 5000;
this._STOKE_COOLDOWN = 0;
this._NEED_WOOD_DELAY = 1;
this._NEED_WOOD_DELAY = 5000;
}
if(typeof State.room == 'undefined') {
State.room = {
temperature: this.TempEnum.Cold,
fire: this.FireEnum.Dead,
buttons: {},
builder: -1
};
if(typeof $SM.get('features.location.room') == 'undefined') {
$SM.set('features.location.room', true);
$SM.set('game.builder.level', -1);
}
Room.temperature = this.TempEnum.Cold;
Room.fire = this.FireEnum.Dead;
// Create the room tab
this.tab = Header.addLocation("A Dark Room", "room", Room);
@@ -450,7 +468,7 @@ var Room = {
Engine.updateSlider();
// Create the light button
var lbtn = new Button.Button({
new Button.Button({
id: 'lightButton',
text: 'light fire',
click: Room.lightFire,
@@ -460,7 +478,7 @@ var Room = {
}).appendTo('div#roomPanel');
// Create the stoke button
var btn = new Button.Button({
new Button.Button({
id: 'stokeButton',
text: "stoke fire",
click: Room.stokeFire,
@@ -472,6 +490,9 @@ var Room = {
// Create the stores container
$('<div>').attr('id', 'storesContainer').appendTo('div#roomPanel');
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Room.handleStateUpdates);
Room.updateButton();
Room.updateStoresView();
Room.updateIncomeView();
@@ -488,36 +509,38 @@ var Room = {
* 3 - Sleeping
* 4 - Helping
*/
if(State.room.builder >= 0 && State.room.builder < 3) {
if($SM.get('game.builder.level') >= 0 && $SM.get('game.builder.level') < 3) {
Room._builderTimer = setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
}
if(State.room.builder == 1 && Engine.getStore('wood') < 0) {
if($SM.get('game.builder.level') == 1 && $SM.get('stores.wood', true) < 0) {
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
}
setTimeout(Engine.collectIncome, 1000);
setTimeout($SM.collectIncome, 1000);
Notifications.notify(Room, "the room is " + State.room.temperature.text);
Notifications.notify(Room, "the fire is " + State.room.fire.text);
Notifications.notify(Room, "the room is " + Room.temperature.text);
Notifications.notify(Room, "the fire is " + Room.fire.text);
},
options: {}, // Nothing for now
onArrival: function() {
onArrival: function(transition_diff) {
Room.setTitle();
if(Room.changed) {
Notifications.notify(Room, "the fire is " + State.room.fire.text);
Notifications.notify(Room, "the room is " + State.room.temperature.text);
Notifications.notify(Room, "the fire is " + Room.fire.text);
Notifications.notify(Room, "the room is " + Room.temperature.text);
Room.changed = false;
}
if(State.room.builder == 3) {
State.room.builder++;
Engine.setIncome('builder', {
if($SM.get('game.builder.level') == 3) {
$SM.add('game.builder.level', 1);
$SM.setIncome('builder', {
delay: 10,
stores: {'wood' : 2 }
});
Room.updateIncomeView();
Notifications.notify(Room, "the stranger is standing by the fire. she says she can help. says she builds things.")
Notifications.notify(Room, "the stranger is standing by the fire. she says she can help. says she builds things.");
}
Engine.moveStoresView(null, transition_diff);
},
TempEnum: {
@@ -553,7 +576,7 @@ var Room = {
},
setTitle: function() {
var title = State.room.fire.value < 2 ? "A Dark Room" : "A Firelit Room";
var title = Room.fire.value < 2 ? "A Dark Room" : "A Firelit Room";
if(Engine.activeModule == this) {
document.title = title;
}
@@ -563,7 +586,7 @@ var Room = {
updateButton: function() {
var light = $('#lightButton.button');
var stoke = $('#stokeButton.button');
if(State.room.fire.value == Room.FireEnum.Dead.value && stoke.css('display') != 'none') {
if(Room.fire.value == Room.FireEnum.Dead.value && stoke.css('display') != 'none') {
stoke.hide();
light.show();
if(stoke.hasClass('disabled')) {
@@ -577,7 +600,7 @@ var Room = {
}
}
if(!Engine.storeAvailable('wood')) {
if(!$SM.get('stores.wood')) {
light.addClass('free');
stoke.addClass('free');
} else {
@@ -589,30 +612,30 @@ var Room = {
_fireTimer: null,
_tempTimer: null,
lightFire: function() {
var wood = Engine.getStore('wood');
if(Engine.storeAvailable('wood') && wood < 5) {
var wood = $SM.get('stores.wood');
if(wood < 5) {
Notifications.notify(Room, "not enough wood to get the fire going");
Button.clearCooldown($('#lightButton.button'));
return;
} else if(wood > 4) {
Engine.setStore('wood', wood - 5);
$SM.set('stores.wood', wood - 5);
}
State.room.fire = Room.FireEnum.Burning;
Room.fire = Room.FireEnum.Burning;
Room.onFireChange();
},
stokeFire: function() {
var wood = Engine.getStore('wood');
if(Engine.storeAvailable('wood') && wood == 0) {
var wood = $SM.get('stores.wood');
if(wood === 0) {
Notifications.notify(Room, "the wood has run out");
Button.clearCooldown($('#stokeButton.button'));
return;
}
if(wood > 0) {
Engine.setStore('wood', wood - 1);
$SM.set('stores.wood', wood - 1);
}
if(State.room.fire.value < 4) {
State.room.fire = Room.FireEnum.fromInt(State.room.fire.value + 1);
if(Room.fire.value < 4) {
Room.fire = Room.FireEnum.fromInt(Room.fire.value + 1);
}
Room.onFireChange();
},
@@ -621,9 +644,9 @@ var Room = {
if(Engine.activeModule != Room) {
Room.changed = true;
}
Notifications.notify(Room, "the fire is " + State.room.fire.text, true);
if(State.room.fire.value > 1 && State.room.builder < 0) {
State.room.builder = 0;
Notifications.notify(Room, "the fire is " + Room.fire.text, true);
if(Room.fire.value > 1 && $SM.get('game.builder.level') < 0) {
$SM.set('game.builder.level', 0);
Notifications.notify(Room, "the light from the fire spills from the windows, out into the dark");
setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
}
@@ -634,54 +657,54 @@ var Room = {
},
coolFire: function() {
if(State.room.fire.value <= Room.FireEnum.Flickering.value &&
State.room.builder > 3 && Engine.getStore('wood') > 0) {
var wood = $SM.get('stores.wood');
if(Room.fire.value <= Room.FireEnum.Flickering.value &&
$SM.get('game.builder.level') > 3 && wood > 0) {
Notifications.notify(Room, "builder stokes the fire", true);
Engine.setStore('wood', Engine.getStore('wood') - 1);
State.room.fire = Room.FireEnum.fromInt(State.room.fire.value + 1);
$SM.set('stores.wood', wood - 1);
Room.fire = Room.FireEnum.fromInt(Room.fire.value + 1);
}
if(State.room.fire.value > 0) {
State.room.fire = Room.FireEnum.fromInt(State.room.fire.value - 1);
if(Room.fire.value > 0) {
Room.fire = Room.FireEnum.fromInt(Room.fire.value - 1);
Room._fireTimer = setTimeout(Room.coolFire, Room._FIRE_COOL_DELAY);
Room.onFireChange();
}
},
adjustTemp: function() {
var old = State.room.temperature.value;
if(State.room.temperature.value > 0 && State.room.temperature.value > State.room.fire.value) {
State.room.temperature = Room.TempEnum.fromInt(State.room.temperature.value - 1);
Notifications.notify(Room, "the room is " + State.room.temperature.text, true);
var old = Room.temperature.value;
if(Room.temperature.value > 0 && Room.temperature.value > Room.fire.value) {
Room.temperature = Room.TempEnum.fromInt(Room.temperature.value - 1);
Notifications.notify(Room, "the room is " + Room.temperature.text, true);
}
if(State.room.temperature.value < 4 && State.room.temperature.value < State.room.fire.value) {
State.room.temperature = Room.TempEnum.fromInt(State.room.temperature.value + 1);
Notifications.notify(Room, "the room is " + State.room.temperature.text, true);
if(Room.temperature.value < 4 && Room.temperature.value < Room.fire.value) {
Room.temperature = Room.TempEnum.fromInt(Room.temperature.value + 1);
Notifications.notify(Room, "the room is " + Room.temperature.text, true);
}
if(State.room.temperature.value != old) {
if(Room.temperature.value != old) {
Room.changed = true;
}
Room._tempTimer = setTimeout(Room.adjustTemp, Room._ROOM_WARM_DELAY);
},
unlockForest: function() {
Engine.setStore('wood', 4);
Room.updateButton();
$SM.set('stores.wood', 4);
Outside.init();
Room.updateStoresView();
Notifications.notify(Room, "the wind howls outside");
Notifications.notify(Room, "the wood is running out");
Engine.event('progress', 'outside');
},
updateBuilderState: function() {
if(State.room.builder == 0) {
var lBuilder = $SM.get('game.builder.level');
if(lBuilder == 0) {
Notifications.notify(Room, "a ragged stranger stumbles through the door and collapses in the corner");
State.room.builder = 1;
lBuilder = $SM.setget('game.builder.level', 1);
setTimeout(Room.unlockForest, Room._NEED_WOOD_DELAY);
}
else if(State.room.builder < 3 && State.room.temperature.value >= Room.TempEnum.Warm.value) {
var msg;
switch(State.room.builder) {
else if(lBuilder < 3 && Room.temperature.value >= Room.TempEnum.Warm.value) {
var msg = "";
switch(lBuilder) {
case 1:
msg = "the stranger shivers, and mumbles quietly. her words are unintelligible.";
break;
@@ -690,11 +713,11 @@ var Room = {
break;
}
Notifications.notify(Room, msg);
if(State.room.builder < 3) {
State.room.builder++;
if(lBuilder < 3) {
lBuilder = $SM.setget('game.builder.level', lBuilder + 1);
}
}
if(State.room.builder < 3) {
if(lBuilder < 3) {
setTimeout(Room.updateBuilderState, Room._BUILDER_STATE_DELAY);
}
Engine.saveGame();
@@ -716,13 +739,15 @@ var Room = {
}).css('opacity', 0);
wNeedsAppend = true;
}
for(var k in State.stores) {
for(var k in $SM.get('stores')) {
var type = null;
if(Room.Craftables[k]) {
type = Room.Craftables[k].type;
} else if(Room.TradeGoods[k]) {
type = Room.TradeGoods[k].type;
} else if (Room.MiscItems[k]) {
type = Room.MiscItems[k].type;
}
var location;
@@ -740,22 +765,23 @@ var Room = {
var id = "row_" + k.replace(' ', '-');
var row = $('div#' + id, location);
var num = State.stores[k];
var num = $SM.get('stores["'+k+'"]');
if(typeof num != 'number' || isNaN(num)) {
// No idea how counts get corrupted, but I have reason to believe that they occassionally do.
// Build a little fence around it!
num = State.stores[k] = 0;
num = 0;
$SM.set('stores["'+k+'"]', 0);
}
// thieves?
if(typeof State.thieves == 'undefined' && num > 5000 && State.world) {
Engine.startThieves();
if(typeof $SM.get('game.thieves') == 'undefined' && num > 5000 && $SM.get('features.location.world')) {
$SM.startThieves();
}
if(row.length == 0 && num > 0) {
var row = $('<div>').attr('id', id).addClass('storeRow');
row = $('<div>').attr('id', id).addClass('storeRow');
$('<div>').addClass('row_key').text(k).appendTo(row);
$('<div>').addClass('row_val').text(Math.floor(num)).appendTo(row);
$('<div>').addClass('clear').appendTo(row);
@@ -773,10 +799,8 @@ var Room = {
row.insertAfter(location.find('#row_' + curPrev.replace(' ', '-')));
}
newRow = true;
} else if(num> 0){
} else if(num>= 0){
$('div#' + row.attr('id') + ' > div.row_val', location).text(Math.floor(num));
} else if(num == 0) {
row.remove();
}
}
@@ -793,18 +817,22 @@ var Room = {
if(newRow) {
Room.updateIncomeView();
}
if($("div#outsidePanel").length) {
Outside.updateVillage();
}
},
updateIncomeView: function() {
var stores = $('div#stores');
if(stores.length == 0 || typeof State.income == 'undefined') return;
if(stores.length == 0 || typeof $SM.get('income') == 'undefined') return;
$('div.storeRow', stores).each(function(index, el) {
el = $(el);
$('div.tooltip', el).remove();
var tt = $('<div>').addClass('tooltip bottom right');
var storeName = el.attr('id').substring(4).replace('-', ' ');
for(var incomeSource in State.income) {
var income = State.income[incomeSource];
for(var incomeSource in $SM.get('income')) {
var income = $SM.get('income["'+incomeSource+'"]');
for(var store in income.stores) {
if(store == storeName && income.stores[store] != 0) {
$('<div>').addClass('row_key').text(incomeSource).appendTo(tt);
@@ -824,7 +852,7 @@ var Room = {
buy: function(buyBtn) {
var thing = $(buyBtn).attr('buildThing');
var good = Room.TradeGoods[thing];
var numThings = Engine.getStore(thing);
var numThings = $SM.get('stores["'+thing+'"]', true);
if(numThings < 0) numThings = 0;
if(good.maximum <= numThings) {
return;
@@ -833,7 +861,7 @@ var Room = {
var storeMod = {};
var cost = good.cost();
for(var k in cost) {
var have = Engine.getStore(k)
var have = $SM.get('stores["'+k+'"]', true);
if(have < cost[k]) {
Notifications.notify(Room, "not enough " + k);
return false;
@@ -841,22 +869,20 @@ var Room = {
storeMod[k] = have - cost[k];
}
}
Engine.setStores(storeMod);
$SM.setM('stores', storeMod);
Notifications.notify(Room, good.buildMsg);
Engine.addStore(thing, 1);
Room.updateBuildButtons();
$SM.add('stores["'+thing+'"]', 1);
if(thing == 'compass') {
Engine.openPath();
Path.openPath();
}
},
build: function(buildBtn) {
var thing = $(buildBtn).attr('buildThing');
if(State.room.temperature.value <= Room.TempEnum.Cold.value) {
if(Room.temperature.value <= Room.TempEnum.Cold.value) {
Notifications.notify(Room, "builder just shivers");
return false;
}
@@ -868,10 +894,10 @@ var Room = {
case 'weapon':
case 'tool':
case 'upgrade':
numThings = Engine.getStore(thing);
numThings = $SM.get('stores["'+thing+'"]', true);
break;
case 'building':
numThings = Outside.numBuilding(thing);
numThings = $SM.get('game.buildings["'+thing+'"]', true);
break;
}
@@ -883,7 +909,7 @@ var Room = {
var storeMod = {};
var cost = craftable.cost();
for(var k in cost) {
var have = Engine.getStore(k)
var have = $SM.get('stores["'+k+'"]', true);
if(have < cost[k]) {
Notifications.notify(Room, "not enough " + k);
return false;
@@ -891,7 +917,7 @@ var Room = {
storeMod[k] = have - cost[k];
}
}
Engine.setStores(storeMod);
$SM.setM('stores', storeMod);
Notifications.notify(Room, craftable.buildMsg);
@@ -900,15 +926,12 @@ var Room = {
case 'weapon':
case 'upgrade':
case 'tool':
Engine.addStore(thing, 1);
$SM.add('stores["'+thing+'"]', 1);
break;
case 'building':
Outside.addBuilding(thing, 1);
$SM.add('game.buildings["'+thing+'"]', 1);
break;
}
Room.updateBuildButtons();
}
},
needsWorkshop: function(type) {
@@ -916,38 +939,42 @@ var Room = {
},
craftUnlocked: function(thing) {
if(typeof State.room != 'undefined' &&
typeof State.room.buttons != 'undefined' &&
State.room.buttons[thing]) {
if(Room.buttons[thing]) {
return true;
}
if(State.room.builder < 4) return false;
if($SM.get('game.builder.level') < 4) return false;
var craftable = Room.Craftables[thing];
if(Room.needsWorkshop(craftable.type) && Outside.numBuilding('workshop') == 0) return false;
if(Room.needsWorkshop(craftable.type) && $SM.get('game.buildings["workshop"]', true) == 0) return false;
var cost = craftable.cost();
//show button if one has already been built
if($SM.get('game.buildings["'+thing+'"]') > 0){
Room.buttons[thing] = true;
return true;
}
// Show buttons if we have at least 1/2 the wood, and all other components have been seen.
if(Engine.getStore('wood') < cost['wood'] * 0.5) {
if($SM.get('stores.wood', true) < cost['wood'] * 0.5) {
return false;
}
for(var c in cost) {
if(!Engine.storeAvailable(c)) {
if(!$SM.get('stores["'+c+'"]')) {
return false;
}
}
State.room.buttons[thing] = true;
Notifications.notify(Room, craftable.availableMsg);
Room.buttons[thing] = true;
//don't notify if it has already been built before
if(!$SM.get('game.buildings["'+thing+'"]')){
Notifications.notify(Room, craftable.availableMsg);
}
return true;
},
buyUnlocked: function(thing) {
if(typeof State.room != 'undefined' &&
typeof State.room.buttons != 'undefined' &&
State.room.buttons[thing]) {
if(Room.buttons[thing]) {
return true;
} else if(Outside.numBuilding('trading post') > 0) {
if(thing == 'compass' || Engine.storeAvailable(thing)) {
} else if($SM.get('game.buildings["trading post"]', true) > 0) {
if(thing == 'compass' || $SM.get('stores["'+thing+'"]')) {
// Allow the purchase of stuff once you've seen it
return true;
}
@@ -965,21 +992,21 @@ var Room = {
var craftSection = $('#craftBtns');
var cNeedsAppend = false;
if(craftSection.length == 0 && Outside.numBuilding('workshop') > 0) {
if(craftSection.length == 0 && $SM.get('game.buildings["workshop"]', true) > 0) {
craftSection = $('<div>').attr('id', 'craftBtns').css('opacity', 0);
cNeedsAppend = true;
}
var buySection = $('#buyBtns');
var bNeedsAppend = false;
if(buySection.length == 0 && Outside.numBuilding('trading post') > 0) {
if(buySection.length == 0 && $SM.get('game.buildings["trading post"]', true) > 0) {
buySection = $('<div>').attr('id', 'buyBtns').css('opacity', 0);
bNeedsAppend = true;
}
for(var k in Room.Craftables) {
craftable = Room.Craftables[k];
var max = Engine.num(k, craftable) + 1 > craftable.maximum;
var max = $SM.num(k, craftable) + 1 > craftable.maximum;
if(craftable.button == null) {
if(Room.craftUnlocked(k)) {
var loc = Room.needsWorkshop(craftable.type) ? craftSection : buildSection;
@@ -1014,7 +1041,7 @@ var Room = {
for(var k in Room.TradeGoods) {
good = Room.TradeGoods[k];
var max = Engine.num(k, good) + 1 > good.maximum;
var max = $SM.num(k, good) + 1 > good.maximum;
if(good.button == null) {
if(Room.buyUnlocked(k)) {
good.button = new Button.Button({
@@ -1054,5 +1081,17 @@ var Room = {
if(bNeedsAppend && buildSection.children().length > 0) {
buySection.appendTo('div#roomPanel').animate({opacity: 1}, 300, 'linear');
}
},
handleStateUpdates: function(e){
if(e.category == 'stores'){
Room.updateStoresView();
Room.updateBuildButtons();
} else if(e.category == 'income'){
Room.updateStoresView();
Room.updateIncomeView();
} else if(e.stateName.indexOf('game.buildings') == 0){
Room.updateBuildButtons();
}
}
};
};
+31 -22
View File
@@ -15,11 +15,12 @@ var Ship = {
options
);
if(!State.ship) {
State.ship = {
if(!$SM.get('features.location.spaceShip')) {
$SM.set('features.location.spaceShip', true);
$SM.setM('game.spaceShip', {
hull: Ship.BASE_HULL,
thrusters: Ship.BASE_THRUSTERS
}
});
}
// Create the Ship tab
@@ -35,13 +36,13 @@ var Ship = {
// Draw the hull label
var hullRow = $('<div>').attr('id', 'hullRow').appendTo('div#shipPanel');
$('<div>').addClass('row_key').text('hull:').appendTo(hullRow);
$('<div>').addClass('row_val').text(State.ship.hull).appendTo(hullRow);
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.hull')).appendTo(hullRow);
$('<div>').addClass('clear').appendTo(hullRow);
// Draw the thrusters label
var engineRow = $('<div>').attr('id', 'engineRow').appendTo('div#shipPanel');
$('<div>').addClass('row_key').text('engine:').appendTo(engineRow);
$('<div>').addClass('row_val').text(State.ship.thrusters).appendTo(engineRow);
$('<div>').addClass('row_val').text($SM.get('game.spaceShip.thrusters')).appendTo(engineRow);
$('<div>').addClass('clear').appendTo(engineRow);
// Draw the reinforce button
@@ -71,23 +72,27 @@ var Ship = {
cooldown: Ship.LIFTOFF_COOLDOWN
}).appendTo('div#shipPanel');
if(State.ship.hull <= 0) {
if($SM.get('game.spaceShip.hull') <= 0) {
Button.setDisabled(b, true);
}
// Init Space
Space.init();
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Ship.handleStateUpdates);
},
options: {}, // Nothing for now
onArrival: function() {
onArrival: function(transition_diff) {
Ship.setTitle();
if(!State.seenShip) {
if(!$SM.get('game.spaceShip.seenShip')) {
Notifications.notify(Ship, 'somewhere above the debris cloud, the wanderer fleet hovers. been on this rock too long.');
State.seenShip = true;
Engine.saveGame();
$SM.set('game.spaceShip.seenShip', true);
}
Engine.moveStoresView(null, transition_diff);
},
setTitle: function() {
@@ -97,34 +102,34 @@ var Ship = {
},
reinforceHull: function() {
if(Engine.getStore('alien alloy') < Ship.ALLOY_PER_HULL) {
if($SM.get('stores["alien alloy"]', true) < Ship.ALLOY_PER_HULL) {
Notifications.notify(Ship, "not enough alien alloy");
return false;
}
Engine.addStore('alien alloy', -Ship.ALLOY_PER_HULL);
State.ship.hull++;
if(State.ship.hull > 0) {
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_HULL);
$SM.add('game.spaceShip.hull', 1);
if($SM.get('game.spaceShip.hull') > 0) {
Button.setDisabled($('#liftoffButton', Ship.panel), false);
}
$('#hullRow .row_val', Ship.panel).text(State.ship.hull);
$('#hullRow .row_val', Ship.panel).text($SM.get('game.spaceShip.hull'));
},
upgradeEngine: function() {
if(Engine.getStore('alien alloy') < Ship.ALLOY_PER_THRUSTER) {
if($SM.get('stores["alien alloy"]', true) < Ship.ALLOY_PER_THRUSTER) {
Notifications.notify(Ship, "not enough alien alloy");
return false;
}
Engine.addStore('alien alloy', -Ship.ALLOY_PER_THRUSTER);
State.ship.thrusters++;
$('#engineRow .row_val', Ship.panel).text(State.ship.thrusters);
$SM.add('stores["alien alloy"]', -Ship.ALLOY_PER_THRUSTER);
$SM.add('game.spaceShip.thrusters', 1);
$('#engineRow .row_val', Ship.panel).text($SM.get('game.spaceShip.thrusters'));
},
getMaxHull: function() {
return State.ship.hull;
return $SM.get('game.spaceShip.hull');
},
checkLiftOff: function() {
if(!State.ship.seenWarning) {
if(!$SM.get('game.spaceShip.seenWarning')) {
Events.startEvent({
title: 'Ready to Leave?',
scenes: {
@@ -136,7 +141,7 @@ var Ship = {
'fly': {
text: 'lift off',
onChoose: function() {
State.ship.seenWarning = true;
$SM.set('game.spaceShip.seenWarning', true);
Ship.liftOff();
},
nextScene: 'end'
@@ -161,5 +166,9 @@ var Ship = {
$('#outerSlider').animate({top: '700px'}, 300);
Space.onArrival();
Engine.activeModule = Space;
},
handleStateUpdates: function(e){
}
};
+25 -15
View File
@@ -41,6 +41,9 @@ var Space = {
var h = $('<div>').attr('id', 'hullRemaining').appendTo(this.panel);
$('<div>').addClass('row_key').text('hull: ').appendTo(h);
$('<div>').addClass('row_val').appendTo(h);
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(Space.handleStateUpdates);
},
options: {}, // Nothing for now
@@ -87,7 +90,7 @@ var Space = {
},
getSpeed: function() {
return Space.SHIP_SPEED + State.ship.thrusters;
return Space.SHIP_SPEED + $SM.get('game.spaceShip.thrusters');
},
updateHull: function() {
@@ -100,7 +103,7 @@ var Space = {
if(r < 0.2)
c = '#';
else if(r < 0.4)
c = '$'
c = '$';
else if(r < 0.6)
c = '%';
else if(r < 0.8)
@@ -109,7 +112,7 @@ var Space = {
c = 'H';
var x = Math.floor(Math.random() * 700);
var a = $('<div>').addClass('asteroid').text(c).appendTo('#spacePanel').css('left', x + 'px')
var a = $('<div>').addClass('asteroid').text(c).appendTo('#spacePanel').css('left', x + 'px');
a.data({
xMin: x,
xMax: x + a.width(),
@@ -216,7 +219,7 @@ var Space = {
Space.ship.css({
left: x + 'px',
top: y + 'px',
top: y + 'px'
});
Space.lastMove = Date.now();
@@ -247,7 +250,7 @@ var Space = {
}
}, 1000);
setTimeout(function() {
Space._panelTimeout = setTimeout(function() {
$('#spacePanel, .deleteSave, .share').animate({color: 'white'}, 500, 'linear');
}, Space.FTB_SPEED / 2);
@@ -308,6 +311,7 @@ var Space = {
Space.done = true;
clearInterval(Space._timer);
clearInterval(Space._shipTimer);
clearTimeout(Space._panelTimeout);
// Craaaaash!
$('body').removeClass('noMask').stop().animate({
@@ -369,9 +373,10 @@ var Space = {
$('#locationSlider, #worldPanel, #spacePanel, #notifications').remove();
$('#header').empty();
setTimeout(function() {
$('body').removeClass('noMask').stop().animate({
$('body').stop();
$('#starsContainer').animate({
opacity: 0,
'background-color': '#FFF'
'background-color': '#000'
}, {
duration: 2000,
progress: function() {
@@ -381,18 +386,19 @@ var Space = {
$('#notifyGradient').attr('style', 'background-color:'+cur+';background:-webkit-' + s + ';background:' + s);
},
complete: function() {
$('#starsContainer, .deleteSave, .share').remove();
Engine.GAME_OVER = true;
var backup;
$('#starsContainer').remove();
if(typeof Storage != 'undefined' && localStorage) {
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 = {};
setTimeout(function() {
Engine.init();
$('body').animate({
opacity: 1
}, 500, 'linear');
}, 2000);
}
});
}, 2000);
@@ -449,5 +455,9 @@ var Space = {
Engine.log('right off');
break;
}
},
handleStateUpdates: function(e){
}
};
};
+404
View File
@@ -0,0 +1,404 @@
/*
* Module for handling States
*
* All states should be get and set through the StateManager ($SM).
*
* The manager is intended to handle all needed checks and error catching.
* This includes creating the parents of layered/deep states so undefined states
* do not need to be tested for and created beforehand.
*
* When a state is changed, an update event is sent out containing the name of the state
* changed or in the case of multiple changes (.setM, .addM) the parent class changed.
* Event: type: 'stateUpdate', stateName: <path of state or parent state>
*
* Original file created by: Michael Galusha
*/
var StateManager = {
MAX_STORE: 99999999999999,
options: {},
init: function(options) {
this.options = $.extend(
this.options,
options
);
//create categories
var cats = [
'features', //big features like buildings, location availability, unlocks, etc
'stores', //little stuff, items, weapons, etc
'character', //this is for player's character stats such as perks
'income',
'timers',
'game', //mostly location related: fire temp, workers, population, world map, etc
'playStats' //anything play related: play time, loads, etc
];
for(var which in cats) {
if(!$SM.get(cats[which])) $SM.set(cats[which], {});
};
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe($SM.handleStateUpdates);
},
//create all parents and then set state
createState: function(stateName, value) {
var words = stateName.split(/[.\[\]'"]+/);
//for some reason there are sometimes empty strings
for (var i = 0; i < words.length; i++) {
if (words[i] == '') {
words.splice(i, 1);
i--;
}
};
var obj = State;
var w = null;
for(var i=0, len=words.length-1;i<len;i++){
w = words[i];
if(obj[w] === undefined ) obj[w] = {};
obj = obj[w];
}
obj[words[i]] = value;
return obj;
},
//set single state
//if noEvent is true, the update event won't trigger, useful for setting multiple states first
set: function(stateName, value, noEvent) {
var fullPath = $SM.buildPath(stateName);
//make sure the value isn't over the engine maximum
if(typeof value == 'number' && value > $SM.MAX_STORE) value = $SM.MAX_STORE;
try{
eval('('+fullPath+') = value');
} catch (e) {
//parent doesn't exist, so make parent
$SM.createState(stateName, value);
}
//stores values can not be negative
if(stateName.indexOf('stores') == 0 && $SM.get(stateName, true) < 0) {
eval('('+fullPath+') = 0');
Engine.log('WARNING: state:' + stateName + ' can not be a negative value. Set to 0 instead.');
}
if(!noEvent) {
Engine.saveGame();
$SM.fireUpdate(stateName);
}
},
//sets a list of states
setM: function(parentName, list, noEvent) {
$SM.buildPath(parentName);
//make sure the state exists to avoid errors,
if($SM.get(parentName) == undefined) $SM.set(parentName, {}, true);
for(var k in list){
$SM.set(parentName+'["'+k+'"]', list[k], true);
}
if(!noEvent) {
Engine.saveGame();
$SM.fireUpdate(parentName);
}
},
//shortcut for altering number values, return 1 if state wasn't a number
add: function(stateName, value, noEvent) {
var err = 0;
//0 if undefined, null (but not {}) should allow adding to new objects
//could also add in a true = 1 thing, to have something go from existing (true)
//to be a count, but that might be unwanted behavior (add with loose eval probably will happen anyways)
var old = $SM.get(stateName, true);
//check for NaN (old != old) and non number values
if(old != old){
Engine.log('WARNING: '+stateName+' was corrupted (NaN). Resetting to 0.');
old = 0;
$SM.set(stateName, old + value, noEvent);
} else if(typeof old != 'number' || typeof value != 'number'){
Engine.log('WARNING: Can not do math with state:'+stateName+' or value:'+value+' because at least one is not a number.');
err = 1;
} else {
$SM.set(stateName, old + value, noEvent); //setState handles event and save
}
return err;
},
//alters multiple number values, return number of fails
addM: function(parentName, list, noEvent) {
var err = 0;
//make sure the parent exists to avoid errors
if($SM.get(parentName) == undefined) $SM.set(parentName, {}, true);
for(var k in list){
if(!$SM.add(parentName+'["'+k+'"]', list[k], true)) err++;
}
if(!noEvent) {
Engine.saveGame();
$SM.fireUpdate(parentName);
}
return err;
},
//return state, undefined or 0
get: function(stateName, requestZero) {
var whichState = null;
var fullPath = $SM.buildPath(stateName);
//catch errors if parent of state doesn't exist
try{
eval('whichState = ('+fullPath+')');
} catch (e) {
whichState = undefined;
}
//prevents repeated if undefined, null, false or {}, then x = 0 situations
if((!whichState || whichState == {}) && requestZero) return 0;
else return whichState;
},
//mainly for local copy use, add(M) can fail so we can't shortcut them
//since set does not fail, we know state exists and can simply return the object
setget: function(stateName, value, noEvent){
$SM.set(stateName, value, noEvent);
return eval('('+$SM.buildPath(stateName)+')');
},
remove: function(stateName, noEvent) {
var whichState = $SM.buildPath(stateName);
try{
eval('(delete '+whichState+')');
} catch (e) {
//it didn't exist in the first place
Engine.log('WARNING: Tried to remove non-existant state \''+stateName+'\'.');
}
if(!noEvent){
Engine.saveGame();
$SM.fireUpdate(stateName);
};
},
//creates full reference from input
//hopefully this won't ever need to be more complicated
buildPath: function(input){
var dot = (input.charAt(0) == '[')? '' : '.'; //if it starts with [foo] no dot to join
return 'State' + dot + input;
},
fireUpdate: function(stateName, save){
var category = $SM.getCategory(stateName);
if(stateName == undefined) stateName = category = 'all'; //best if this doesn't happen as it will trigger more stuff
$.Dispatch('stateUpdate').publish({'category': category, 'stateName':stateName});
if(save) Engine.saveGame();
},
getCategory: function(stateName){
var firstOB = stateName.indexOf('[');
var firstDot = stateName.indexOf('.');
var cutoff = null;
if(firstOB == -1 || firstDot == -1){
cutoff = firstOB > firstDot ? firstOB : firstDot;
} else {
cutoff = firstOB < firstDot ? firstOB : firstDot;
}
if (cutoff == -1){
return stateName;
} else {
return stateName.substr(0,cutoff);
}
},
//Use this function to make old save games compatible with new version
updateOldState: function(){
var version = $SM.get('version');
if(typeof version != 'number') version = 1.0;
if(version == 1.0) {
// v1.1 introduced the Lodge, so get rid of lodgeless hunters
$SM.remove('outside.workers.hunter', true);
$SM.remove('income.hunter', true);
Engine.log('upgraded save to v1.1');
version = 1.1;
};
if(version == 1.1) {
//v1.2 added the Swamp to the map, so add it to already generated maps
if($SM.get('world')) {
World.placeLandmark(15, World.RADIUS * 1.5, World.TILE.SWAMP, $SM.get('world.map'));
}
Engine.log('upgraded save to v1.2');
version = 1.2;
};
if(version == 1.2) {
//StateManager added, so move data to new locations
$SM.remove('room.fire');
$SM.remove('room.temperature');
$SM.remove('room.buttons');
if($SM.get('room')){
$SM.set('features.location.room', true);
$SM.set('game.builder.level', $SM.get('room.builder'));
$SM.remove('room');
};
if($SM.get('outside')){
$SM.set('features.location.outside', true);
$SM.set('game.population', $SM.get('outside.population'));
$SM.set('game.buildings', $SM.get('outside.buildings'));
$SM.set('game.workers', $SM.get('outside.workers'));
$SM.set('game.outside.seenForest', $SM.get('outside.seenForest'));
$SM.remove('outside');
};
if($SM.get('world')){
$SM.set('features.location.world', true);
$SM.set('game.world.map', $SM.get('world.map'));
$SM.set('game.world.mask', $SM.get('world.mask'));
$SM.set('starved', $SM.get('character.starved', true));
$SM.set('dehydrated', $SM.get('character.dehydrated', true));
$SM.remove('world');
$SM.remove('starved');
$SM.remove('dehydrated');
};
if($SM.get('ship')){
$SM.set('features.location.spaceShip', true);
$SM.set('game.spaceShip.hull', $SM.get('ship.hull', true));
$SM.set('game.spaceShip.thrusters', $SM.get('ship.thrusters', true));
$SM.set('game.spaceShip.seenWarning', $SM.get('ship.seenWarning'));
$SM.set('game.spaceShip.seenShip', $SM.get('ship.seenShip'));
$SM.remove('ship');
};
if($SM.get('punches')){
$SM.set('character.punches', $SM.get('punches'));
$SM.remove('punches');
};
if($SM.get('perks')){
$SM.set('character.perks', $SM.get('perks'));
$SM.remove('perks');
};
if($SM.get('thieves')){
$SM.set('game.thieves', $SM.get('thieves'));
$SM.remove('thieves');
};
if($SM.get('stolen')){
$SM.set('game.stolen', $SM.get('stolen'));
$SM.remove('stolen');
};
if($SM.get('cityCleared')){
$SM.set('character.cityCleared', $SM.get('cityCleared'));
$SM.remove('cityCleared');
};
$SM.set('version', 1.3);
};
},
/******************************************************************
* Start of specific state functions
******************************************************************/
//PERKS
addPerk: function(name) {
$SM.set('character.perks["'+name+'"]', true);
Notifications.notify(null, Engine.Perks[name].notify);
},
hasPerk: function(name) {
return $SM.get('character.perks["'+name+'"]');
},
//INCOME
setIncome: function(source, options) {
var existing = $SM.get('income["'+source+'"]');
if(typeof existing != 'undefined') {
options.timeLeft = existing.timeLeft;
}
$SM.set('income["'+source+'"]', options);
},
getIncome: function(source) {
var existing = $SM.get('income["'+source+'"]');
if(typeof existing != 'undefined') {
return existing;
}
return {};
},
collectIncome: function() {
var changed = false;
if(typeof $SM.get('income') != 'undefined' && Engine.activeModule != Space) {
for(var source in $SM.get('income')) {
var income = $SM.get('income["'+source+'"]');
if(typeof income.timeLeft != 'number')
{
income.timeLeft = 0;
}
income.timeLeft--;
if(income.timeLeft <= 0) {
Engine.log('collection income from ' + source);
if(source == 'thieves') $SM.addStolen(income.stores);
$SM.addM('stores', income.stores, true);
changed = true;
if(typeof income.delay == 'number') {
income.timeLeft = income.delay;
}
}
}
}
if(changed){
$SM.fireUpdate('income', true);
};
Engine._incomeTimeout = setTimeout($SM.collectIncome, 1000);
},
//Thieves
addStolen: function(stores) {
for(var k in stores) {
var old = $SM.get('stores["'+k+'"]', true);
var short = old - stores[k];
//if they would steal more than actually owned
if(short < 0){
$SM.add('game.stolen["'+k+'"]', (stores[k] * -1) + short);
} else {
$SM.add('game.stolen["'+k+'"]', stores[k] * -1);
}
};
},
startThieves: function() {
$SM.set('game.thieves', 1);
$SM.setIncome('thieves', {
delay: 10,
stores: {
'wood': -10,
'fur': -5,
'meat': -5
}
});
},
//Misc
num: function(name, craftable) {
switch(craftable.type) {
case 'good':
case 'tool':
case 'weapon':
case 'upgrade':
return $SM.get('stores["'+name+'"]', true);
case 'building':
return $SM.get('game.buildings["'+name+'"]', true);
}
},
handleStateUpdates: function(e){
}
};
//alias
var $SM = StateManager;
+212 -88
View File
@@ -1,12 +1,13 @@
var World = {
RADIUS: 30,
VILLAGE_POS: [30, 30],
TILE: {
VILLAGE: 'A',
IRON_MINE: 'I',
COAL_MINE: 'C',
SULPHUR_MINE: 'S',
FOREST: 'T',
FOREST: ';',
FIELD: ',',
BARRENS: '.',
ROAD: '#',
@@ -18,7 +19,8 @@ var World = {
SHIP: 'W',
BOREHOLE: 'B',
BATTLEFIELD: 'F',
SWAMP: 'M'
SWAMP: 'M',
CACHE: 'U'
},
TILE_PROBS: {},
LANDMARKS: {},
@@ -31,8 +33,13 @@ var World = {
FIGHT_CHANCE: 0.20,
BASE_HEALTH: 10,
BASE_HIT_CHANCE: 0.8,
MEAT_HEAL: 10,
MEAT_HEAL: 8,
MEDS_HEAL: 20,
FIGHT_DELAY: 3, // At least three moves between fights
NORTH: [ 0, -1],
SOUTH: [ 0, 1],
WEST: [-1, 0],
EAST: [ 1, 0],
Weapons: {
'fists': {
@@ -117,16 +124,18 @@ 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 State.world == 'undefined') {
State.world = {
if(typeof $SM.get('features.location.world') == 'undefined') {
$SM.set('features.location.world', true);
$SM.setM('game.world', {
map: World.generateMap(),
mask: World.newMask()
};
});
}
// Create the World panel
@@ -142,6 +151,9 @@ var World = {
$('<div>').attr('id', 'healthCounter').appendTo(outer);
Engine.updateOuterSlider();
//subscribe to stateUpdates
$.Dispatch('stateUpdate').subscribe(World.handleStateUpdates);
},
clearDungeon: function() {
@@ -151,27 +163,68 @@ var World = {
},
drawRoad: function() {
var xDist = World.curPos[0] - World.RADIUS;
var yDist = World.curPos[1] - World.RADIUS;
var findClosestRoad = function(startPos) {
// We'll search in a spiral to find the closest road tile
// We spiral out along manhattan distance contour
// lines to ensure we draw the shortest road possible.
// No attempt is made to reduce the search space for
// tiles outside the map.
var searchX, searchY, dtmp,
x = 0,
y = 0,
dx = 1,
dy = -1;
for (var i = 0; i < Math.pow(World.getDistance(startPos, World.VILLAGE_POS) + 2, 2); i++) {
searchX = startPos[0] + x;
searchY = startPos[1] + y;
if (0 < searchX && searchX < World.RADIUS * 2 && 0 < searchY && searchY < World.RADIUS * 2) {
// check for road
var tile = World.state.map[searchX][searchY];
if (
tile === World.TILE.ROAD ||
(tile === World.TILE.OUTPOST && !(x === 0 && y === 0)) || // outposts are connected to roads
tile === World.TILE.VILLAGE // all roads lead home
) {
return [searchX, searchY];
}
}
if (x === 0 || y === 0) {
// Turn the corner
dtmp = dx;
dx = -dy;
dy = dtmp;
}
if (x === 0 && y <= 0) {
x++;
} else {
x += dx;
y += dy;
}
}
return World.VILLAGE_POS;
};
var closestRoad = findClosestRoad(World.curPos);
var xDist = World.curPos[0] - closestRoad[0];
var yDist = World.curPos[1] - closestRoad[1];
var xDir = Math.abs(xDist)/xDist;
var yDir = Math.abs(yDist)/yDist;
var xIntersect, yIntersect;
if(Math.abs(xDist) > Math.abs(yDist)) {
xIntersect = World.RADIUS;
yIntersect = World.RADIUS + yDist;
xIntersect = closestRoad[0];
yIntersect = closestRoad[1] + yDist;
} else {
xIntersect = World.RADIUS + xDist;
yIntersect = World.RADIUS;
xIntersect = closestRoad[0] + xDist;
yIntersect = closestRoad[1];
}
for(var x = 0; x < Math.abs(xDist); x++) {
if(World.isTerrain(World.state.map[World.RADIUS + (xDir*x)][yIntersect])) {
World.state.map[World.RADIUS + (xDir*x)][yIntersect] = World.TILE.ROAD;
if(World.isTerrain(World.state.map[closestRoad[0] + (xDir*x)][yIntersect])) {
World.state.map[closestRoad[0] + (xDir*x)][yIntersect] = World.TILE.ROAD;
}
}
for(var y = 0; y < Math.abs(yDist); y++) {
if(World.isTerrain(World.state.map[xIntersect][World.RADIUS + (yDir*y)])) {
World.state.map[xIntersect][World.RADIUS + (yDir*y)] = World.TILE.ROAD;
if(World.isTerrain(World.state.map[xIntersect][closestRoad[1] + (yDir*y)])) {
World.state.map[xIntersect][closestRoad[1] + (yDir*y)] = World.TILE.ROAD;
}
}
World.drawMap();
@@ -218,7 +271,7 @@ var World = {
// Update label
var t = 'pockets';
if(Engine.getStore('rucksack') > 0) {
if($SM.get('stores.rucksack', true) > 0) {
t = 'rucksack';
}
$('#backpackTitle').text(t);
@@ -253,57 +306,111 @@ var World = {
return div;
},
keyDown: function(event) {
var moved = true;
moveNorth: function() {
Engine.log('North');
if(World.curPos[1] > 0) World.move(World.NORTH);
},
moveSouth: function() {
Engine.log('South');
if(World.curPos[1] < World.RADIUS * 2) World.move(World.SOUTH);
},
moveWest: function() {
Engine.log('West');
if(World.curPos[0] > 0) World.move(World.WEST);
},
moveEast: function() {
Engine.log('East');
if(World.curPos[0] < World.RADIUS * 2) World.move(World.EAST);
},
move: function(direction) {
var oldTile = World.state.map[World.curPos[0]][World.curPos[1]];
World.curPos[0] += direction[0];
World.curPos[1] += direction[1];
World.narrateMove(oldTile, World.state.map[World.curPos[0]][World.curPos[1]]);
World.lightMap(World.curPos[0], World.curPos[1], World.state.mask);
World.drawMap();
World.doSpace();
if(World.checkDanger()) {
if(World.danger) {
Notifications.notify(World, 'dangerous to be this far from the village without proper protection');
} else {
Notifications.notify(World, 'safer here');
}
}
},
keyDown: function(event) {
switch(event.which) {
case 38: // Up
case 87:
Engine.log('up');
if(World.curPos[1] > 0) World.curPos[1]--;
World.moveNorth();
break;
case 40: // Down
case 83:
Engine.log('down');
if(World.curPos[1] < World.RADIUS * 2) World.curPos[1]++;
World.moveSouth();
break;
case 37: // Left
case 65:
Engine.log('left');
if(World.curPos[0] > 0) World.curPos[0]--;
World.moveWest();
break;
case 39: // Right
case 68:
Engine.log('right');
if(World.curPos[0] < World.RADIUS * 2) World.curPos[0]++;
World.moveEast();
break;
default:
moved = false;
break;
}
if(moved) {
World.narrateMove(oldTile, World.state.map[World.curPos[0]][World.curPos[1]]);
World.lightMap(World.curPos[0], World.curPos[1], World.state.mask);
World.drawMap();
World.doSpace();
if(World.checkDanger()) {
if(World.danger) {
Notifications.notify(World, 'dangerous to be this far from the village without proper protection')
} else {
Notifications.notify(World, 'safer here');
}
}
},
swipeLeft: function(e) {
World.moveWest();
},
swipeRight: function(e) {
World.moveEast();
},
swipeUp: function(e) {
World.moveNorth();
},
swipeDown: function(e) {
World.moveSouth();
},
click: function(event) {
var map = $('#map'),
// measure clicks relative to the centre of the current location
centreX = map.offset().left + map.width() * World.curPos[0] / (World.RADIUS * 2),
centreY = map.offset().top + map.height() * World.curPos[1] / (World.RADIUS * 2),
clickX = event.pageX - centreX,
clickY = event.pageY - centreY;
if (clickX > clickY && clickX < -clickY) {
World.moveNorth();
}
if (clickX < clickY && clickX > -clickY) {
World.moveSouth();
}
if (clickX < clickY && clickX < -clickY) {
World.moveWest();
}
if (clickX > clickY && clickX > -clickY) {
World.moveEast();
}
},
checkDanger: function() {
World.danger = typeof World.danger == 'undefined' ? false: World.danger;
if(!World.danger) {
if(!Engine.getStore('i armour') > 0 && World.getDistance() >= 8) {
if(!$SM.get('stores["i armour"]', true) > 0 && World.getDistance() >= 8) {
World.danger = true;
return true;
}
if(!Engine.getStore('s armour') > 0 && World.getDistance() >= 18) {
if(!$SM.get('stores["s armour"]', true) > 0 && World.getDistance() >= 18) {
World.danger = true;
return true;
}
@@ -312,7 +419,7 @@ var World = {
World.danger = false;
return true;
}
if(World.getDistance < 18 && Engine.getStore('i armour') > 0) {
if(World.getDistance < 18 && $SM.get('stores["i armour"]', true) > 0) {
World.danger = false;
return true;
}
@@ -325,7 +432,7 @@ var World = {
World.waterMove++;
// Food
var movesPerFood = World.MOVES_PER_FOOD;
movesPerFood *= Engine.hasPerk('slow metabolism') ? 2 : 1;
movesPerFood *= $SM.hasPerk('slow metabolism') ? 2 : 1;
if(World.foodMove >= movesPerFood) {
World.foodMove = 0;
var num = Path.outfit['cured meat'];
@@ -336,13 +443,13 @@ var World = {
// Starvation! Hooray!
num = 0;
if(!World.starvation) {
Notifications.notify(World, 'starvation sets in')
Notifications.notify(World, 'starvation sets in');
World.starvation = true;
} else {
State.starved = State.starved ? State.starved : 0;
State.starved++;
if(State.starved >= 10 && !Engine.hasPerk('slow metabolism')) {
Engine.addPerk('slow metabolism');
$SM.set('character.starved', $SM.get('character.starved', true));
$SM.add('character.starved', 1);
if($SM.get('character.starved') >= 10 && !$SM.hasPerk('slow metabolism')) {
$SM.addPerk('slow metabolism');
}
World.die();
return false;
@@ -355,7 +462,7 @@ var World = {
}
// Water
var movesPerWater = World.MOVES_PER_WATER;
movesPerWater *= Engine.hasPerk('desert rat') ? 2 : 1;
movesPerWater *= $SM.hasPerk('desert rat') ? 2 : 1;
if(World.waterMove >= movesPerWater) {
World.waterMove = 0;
var water = World.water;
@@ -368,10 +475,10 @@ var World = {
Notifications.notify(World, 'the thirst becomes unbearable');
World.thirst = true;
} else {
State.dehydrated = State.dehydrated ? State.dehydrated : 0;
State.dehydrated++;
if(State.dehydrated >= 10 && !Engine.hasPerk('desert rat')) {
Engine.addPerk('desert rat');
$SM.set('character.dehydrated', $SM.get('character.dehydrated', true));
$SM.add('character.dehydrated', 1);
if($SM.get('character.dehydrated') >= 10 && !$SM.hasPerk('desert rat')) {
$SM.addPerk('desert rat');
}
World.die();
return false;
@@ -386,7 +493,11 @@ var World = {
},
meatHeal: function() {
return World.MEAT_HEAL * (Engine.hasPerk('gastronome') ? 2 : 1);
return World.MEAT_HEAL * ($SM.hasPerk('gastronome') ? 2 : 1);
},
medsHeal: function() {
return World.MEDS_HEAL;
},
checkFight: function() {
@@ -394,7 +505,7 @@ var World = {
World.fightMove++;
if(World.fightMove > World.FIGHT_DELAY) {
var chance = World.FIGHT_CHANCE;
chance *= Engine.hasPerk('stealthy') ? 0.5 : 1;
chance *= $SM.hasPerk('stealthy') ? 0.5 : 1;
if(Math.random() < chance) {
World.fightMove = 0;
Events.triggerFight();
@@ -418,8 +529,10 @@ var World = {
}
},
getDistance: function() {
return Math.abs(World.curPos[0] - World.RADIUS) + Math.abs(World.curPos[1] - World.RADIUS);
getDistance: function(from, to) {
from = from || World.curPos;
to = to || World.VILLAGE_POS;
return Math.abs(from[0] - to[0]) + Math.abs(from[1] - to[1]);
},
getTerrain: function() {
@@ -476,7 +589,7 @@ var World = {
lightMap: function(x, y, mask) {
var r = World.LIGHT_RADIUS;
r *= Engine.hasPerk('scout') ? 2 : 1;
r *= $SM.hasPerk('scout') ? 2 : 1;
World.uncoverMap(x, y, r, mask);
return mask;
},
@@ -497,7 +610,7 @@ var World = {
applyMap: function() {
var x = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
var y = Math.floor(Math.random() * (World.RADIUS * 2) + 1);
World.uncoverMap(x, y, 5, State.world.mask);
World.uncoverMap(x, y, 5, $SM.get('game.world.mask'));
},
generateMap: function() {
@@ -509,7 +622,7 @@ var World = {
// Spiral out from there
map[World.RADIUS][World.RADIUS] = World.TILE.VILLAGE;
for(var r = 1; r <= World.RADIUS; r++) {
for(t = 0; t < r * 8; t++) {
for(var t = 0; t < r * 8; t++) {
var x, y;
if(t < 2 * r) {
x = World.RADIUS - r + t;
@@ -578,8 +691,6 @@ var World = {
chooseTile: function(x, y, map) {
var log = x == World.RADIUS + 1 && y == World.RADIUS + 1;
var adjacent = [
y > 0 ? map[x][y-1] : null,
y < World.RADIUS * 2 ? map[x][y+1] : null,
@@ -641,6 +752,8 @@ var World = {
var map = $('#map');
if(map.length == 0) {
map = new $('<div>').attr('id', 'map').appendTo('#worldOuter');
// register click handler
map.click(World.click);
}
var mapString = "";
for(var j = 0; j <= World.RADIUS * 2; j++) {
@@ -697,6 +810,7 @@ var World = {
$('#outerSlider').animate({opacity: '0'}, 600, 'linear', function() {
$('#outerSlider').css('left', '0px');
$('#locationSlider').css('left', '0px');
$('#storesContainer').css({'top': '0px', 'right': '0px'});
Engine.activeModule = Room;
$('div.headerButton').removeClass('selected');
Room.tab.addClass('selected');
@@ -712,20 +826,20 @@ var World = {
goHome: function() {
// Home safe! Commit the changes.
State.world = World.state;
if(World.state.sulphurmine && Outside.numBuilding('sulphur mine') == 0) {
Outside.addBuilding('sulphur mine', 1);
$SM.setM('game.world', World.state);
if(World.state.sulphurmine && $SM.get('game.buildings["sulphur mine"]', true) == 0) {
$SM.add('game.buildings["sulphur mine"]', 1);
Engine.event('progress', 'sulphur mine');
}
if(World.state.ironmine && Outside.numBuilding('iron mine') == 0) {
Outside.addBuilding('iron mine', 1);
if(World.state.ironmine && $SM.get('game.buildings["iron mine"]', true) == 0) {
$SM.add('game.buildings["iron mine"]', 1);
Engine.event('progress', 'iron mine');
}
if(World.state.coalmine && Outside.numBuilding('coal mine') == 0) {
Outside.addBuilding('coal mine', 1);
if(World.state.coalmine && $SM.get('game.buildings["coal mine"]', true) == 0) {
$SM.add('game.buildings["coal mine"]', 1);
Engine.event('progress', 'coal mine');
}
if(World.state.ship && !State.ship) {
if(World.state.ship && !$SM.get('features.location.spaceShip')) {
Ship.init();
Engine.event('progress', 'ship');
}
@@ -738,7 +852,7 @@ var World = {
}
for(var k in Path.outfit) {
Engine.addStore(k, Path.outfit[k]);
$SM.add('stores["'+k+'"]', Path.outfit[k]);
if(World.leaveItAtHome(k)) {
Path.outfit[k] = 0;
}
@@ -750,34 +864,34 @@ var World = {
},
leaveItAtHome: function(thing) {
return thing != 'cured meat' && thing != 'bullets' && thing != 'energy cell' && thing != 'charm'
return thing != 'cured meat' && thing != 'bullets' && thing != 'energy cell' && thing != 'charm' && thing != 'medicine'
&& typeof World.Weapons[thing] == 'undefined' && typeof Room.Craftables[thing] == 'undefined';
},
getMaxHealth: function() {
if(Engine.getStore('s armour') > 0) {
if($SM.get('stores["s armour"]', true) > 0) {
return World.BASE_HEALTH + 35;
} else if(Engine.getStore('i armour') > 0) {
} else if($SM.get('stores["i armour"]', true) > 0) {
return World.BASE_HEALTH + 15;
} else if(Engine.getStore('l armour') > 0) {
} else if($SM.get('stores["l armour"]', true) > 0) {
return World.BASE_HEALTH + 5;
}
return World.BASE_HEALTH;
},
getHitChance: function() {
if(Engine.hasPerk('precise')) {
if($SM.hasPerk('precise')) {
return World.BASE_HIT_CHANCE + 0.1;
}
return World.BASE_HIT_CHANCE;
},
getMaxWater: function() {
if(Engine.getStore('water tank') > 0) {
if($SM.get('stores["water tank"]', true) > 0) {
return World.BASE_WATER + 50;
} else if(Engine.getStore('cask') > 0) {
} else if($SM.get('stores.cask', true) > 0) {
return World.BASE_WATER + 20;
} else if(Engine.getStore('waterskin') > 0) {
} else if($SM.get('stores.waterskin', true) > 0) {
return World.BASE_WATER + 10;
}
return World.BASE_WATER;
@@ -794,7 +908,7 @@ var World = {
Notifications.notify(null, 'water replenished');
World.setWater(World.getMaxWater());
// Save progress at outposts
State.world = World.state;
$SM.setM('game.world', World.state);
// Mark this outpost as used
World.usedOutposts[World.curPos[0] + ',' + World.curPos[1]] = true;
},
@@ -802,7 +916,9 @@ var World = {
onArrival: function() {
Engine.keyLock = false;
// Explore in a temporary world-state. We'll commit the changes if you return home safe.
World.state = $.extend(true, {}, State.world);
World.state = $.extend(true, {}, $SM.get('game.world'));
// Some weirdness in jQuery's extend method is causing the map to not be deep copied...
World.state.map = $.extend(true, {}, World.state.map);
World.setWater(World.getMaxWater());
World.setHp(World.getMaxHealth());
World.foodMove = 0;
@@ -810,7 +926,7 @@ var World = {
World.starvation = false;
World.thirst = false;
World.usedOutposts = {};
World.curPos = [World.RADIUS, World.RADIUS];
World.curPos = World.copyPos(World.VILLAGE_POS);
World.drawMap();
World.setTitle();
World.dead = false;
@@ -821,5 +937,13 @@ var World = {
setTitle: function() {
document.title = 'A Barren World';
},
copyPos: function(pos) {
return [pos[0], pos[1]];
},
handleStateUpdates: function(e){
}
};
};