Debugbro

v1.031

Sep 19th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 150.44 KB | None | 0 0
  1. /*
  2. All this code is copyright Orteil, 2013.
  3. -with some help, advice and fixes by Debugbro and Opti
  4. Spoilers ahead.
  5. http://orteil.dashnet.org
  6. */
  7.  
  8. /*=====================================================================================
  9. MISC HELPER FUNCTIONS
  10. =======================================================================================*/
  11. function l(what) {return document.getElementById(what);}
  12. function choose(arr) {return arr[Math.floor(Math.random()*arr.length)];}
  13.  
  14. if(!Array.prototype.indexOf) {
  15. Array.prototype.indexOf = function(needle) {
  16. for(var i = 0; i < this.length; i++) {
  17. if(this[i] === needle) {
  18. return i;
  19. }
  20. }
  21. return -1;
  22. };
  23. }
  24.  
  25. function shuffle(array)
  26. {
  27. var counter = array.length, temp, index;
  28. // While there are elements in the array
  29. while (counter--)
  30. {
  31. // Pick a random index
  32. index = (Math.random() * counter) | 0;
  33.  
  34. // And swap the last element with it
  35. temp = array[counter];
  36. array[counter] = array[index];
  37. array[index] = temp;
  38. }
  39. return array;
  40. }
  41. function Beautify(what,floats)//turns 9999999 into 9,999,999
  42. {
  43. var str='';
  44. what=Math.round(what*100000)/100000;//get rid of weird rounding errors
  45. if (floats>0)
  46. {
  47. var floater=what-Math.floor(what);
  48. floater=Math.round(floater*100000)/100000;//get rid of weird rounding errors
  49. var floatPresent=floater?1:0;
  50. floater=(floater.toString()+'0000000').slice(2,2+floats);//yes this is hacky (but it works)
  51. str=Beautify(Math.floor(what))+(floatPresent?('.'+floater):'');
  52. }
  53. else
  54. {
  55. what=Math.floor(what);
  56. what=(what+'').split('').reverse();
  57. for (var i in what)
  58. {
  59. if (i%3==0 && i>0) str=','+str;
  60. str=what[i]+str;
  61. }
  62. }
  63. return str;
  64. }
  65.  
  66.  
  67. function utf8_to_b64( str ) {
  68. try{
  69. return Base64.encode(unescape(encodeURIComponent( str )));
  70. //return window.btoa(unescape(encodeURIComponent( str )));
  71. }
  72. catch(err)
  73. {
  74. //Popup('There was a problem while encrypting to base64.<br>('+err+')');
  75. return '';
  76. }
  77. }
  78.  
  79. function b64_to_utf8( str ) {
  80. try{
  81. return decodeURIComponent(escape(Base64.decode( str )));
  82. //return decodeURIComponent(escape(window.atob( str )));
  83. }
  84. catch(err)
  85. {
  86. //Popup('There was a problem while decrypting from base64.<br>('+err+')');
  87. return '';
  88. }
  89. }
  90.  
  91.  
  92. function CompressBin(arr)//compress a sequence like [0,1,1,0,1,0]... into a number like 54.
  93. {
  94. var str='';
  95. var arr2=arr.slice(0);
  96. arr2.unshift(1);
  97. arr2.push(1);
  98. arr2.reverse();
  99. for (var i in arr2)
  100. {
  101. str+=arr2[i];
  102. }
  103. str=parseInt(str,2);
  104. return str;
  105. }
  106.  
  107. function UncompressBin(num)//uncompress a number like 54 to a sequence like [0,1,1,0,1,0].
  108. {
  109. var arr=num.toString(2);
  110. arr=arr.split('');
  111. arr.reverse();
  112. arr.shift();
  113. arr.pop();
  114. return arr;
  115. }
  116.  
  117. function CompressLargeBin(arr)//we have to compress in smaller chunks to avoid getting into scientific notation
  118. {
  119. var arr2=arr.slice(0);
  120. var thisBit=[];
  121. var bits=[];
  122. for (var i in arr2)
  123. {
  124. thisBit.push(arr2[i]);
  125. if (thisBit.length>=50)
  126. {
  127. bits.push(CompressBin(thisBit));
  128. thisBit=[];
  129. }
  130. }
  131. if (thisBit.length>0) bits.push(CompressBin(thisBit));
  132. arr2=bits.join(';');
  133. return arr2;
  134. }
  135.  
  136. function UncompressLargeBin(arr)
  137. {
  138. var arr2=arr.split(';');
  139. var bits=[];
  140. for (var i in arr2)
  141. {
  142. bits.push(UncompressBin(parseInt(arr2[i])));
  143. }
  144. arr2=[];
  145. for (var i in bits)
  146. {
  147. for (var ii in bits[i]) arr2.push(bits[i][ii]);
  148. }
  149. return arr2;
  150. }
  151.  
  152. //seeded random function, courtesy of http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html
  153. (function(a,b,c,d,e,f){function k(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=j&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=j&f+1],c=c*d+h[j&(h[f]=h[g=j&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function l(a,b){var e,c=[],d=(typeof a)[0];if(b&&"o"==d)for(e in a)try{c.push(l(a[e],b-1))}catch(f){}return c.length?c:"s"==d?a:a+"\0"}function m(a,b){for(var d,c=a+"",e=0;c.length>e;)b[j&e]=j&(d^=19*b[j&e])+c.charCodeAt(e++);return o(b)}function n(c){try{return a.crypto.getRandomValues(c=new Uint8Array(d)),o(c)}catch(e){return[+new Date,a,a.navigator.plugins,a.screen,o(b)]}}function o(a){return String.fromCharCode.apply(0,a)}var g=c.pow(d,e),h=c.pow(2,f),i=2*h,j=d-1;c.seedrandom=function(a,f){var j=[],p=m(l(f?[a,o(b)]:0 in arguments?a:n(),3),j),q=new k(j);return m(o(q.S),b),c.random=function(){for(var a=q.g(e),b=g,c=0;h>a;)a=(a+c)*d,b*=d,c=q.g(1);for(;a>=i;)a/=2,b/=2,c>>>=1;return(a+c)/b},p},m(c.random(),b)})(this,[],Math,256,6,52);
  154.  
  155.  
  156. /*=====================================================================================
  157. GAME INITIALIZATION
  158. =======================================================================================*/
  159. Game={};
  160.  
  161. Game.Launch=function()
  162. {
  163. Game.ready=0;
  164. Game.Init=function()
  165. {
  166. Game.ready=1;
  167. l('javascriptError').innerHTML='<div style="padding:64px 128px;"><div class="title">Loading...</div></div>';
  168.  
  169.  
  170. /*=====================================================================================
  171. VARIABLES AND PRESETS
  172. =======================================================================================*/
  173. Game.T=0;
  174. Game.fps=30;
  175.  
  176. Game.version=1.036;
  177. Game.beta=0;
  178. l('versionNumber').innerHTML='v.'+Game.version+(Game.beta?' <span style="color:#ff0;">beta</span>':'');
  179. //l('links').innerHTML=(Game.beta?'<a href="../" target="blank">Live version</a> | ':'<a href="beta" target="blank">Try the beta!</a> | ')+'<a href="http://orteil.dashnet.org/experiments/cookie/" target="blank">Cookie Clicker Classic</a>';
  180. l('links').innerHTML='<a href="http://orteil.dashnet.org/experiments/cookie/" target="blank">Cookie Clicker Classic</a>';
  181.  
  182. //latency compensator stuff
  183. Game.time=new Date().getTime();
  184. Game.fpsMeasure=new Date().getTime();
  185. Game.accumulatedDelay=0;
  186. Game.catchupLogic=0;
  187.  
  188. Game.cookiesEarned=0;//all cookies earned during gameplay
  189. Game.cookies=0;//cookies
  190. Game.cookiesd=0;//cookies display
  191. Game.cookiesPs=1;//cookies per second (to recalculate with every new purchase)
  192. Game.cookiesReset=0;//cookies lost to resetting
  193. Game.frenzy=0;//as long as >0, cookie production is multiplied by frenzyPower
  194. Game.frenzyPower=1;
  195. Game.clickFrenzy=0;//as long as >0, mouse clicks get 777x more cookies
  196. Game.cookieClicks=0;//+1 for each click on the cookie
  197. Game.goldenClicks=0;//+1 for each golden cookie clicked
  198. Game.missedGoldenClicks=0;//+1 for each golden cookie missed
  199. Game.handmadeCookies=0;//all the cookies made from clicking the cookie
  200. Game.milkProgress=0;//you can a little bit for each achievement; 0-1 : milk; 1-2 : chocolate milk; 2-3 : raspberry milk
  201. Game.milkH=Game.milkProgress/2;//milk height, between 0 and 1 (although should never go above 0.5)
  202. Game.milkHd=0;//milk height display
  203. Game.milkType=-1;//custom milk : 0=plain, 1=chocolate...
  204. Game.backgroundType=-1;//custom background : 0=blue, 1=red...
  205. Game.prestige=[];//cool stuff that carries over beyond resets
  206.  
  207. Game.elderWrath=0;
  208. Game.elderWrathD=0;
  209. Game.pledges=0;
  210. Game.pledgeT=0;
  211. Game.researchT=0;
  212. Game.nextResearch=0;
  213.  
  214. Game.bg='';//background (grandmas and such)
  215. Game.bgFade='';//fading to background
  216. Game.bgR=0;//ratio (0 - not faded, 1 - fully faded)
  217. Game.bgRd=0;//ratio displayed
  218.  
  219. Game.startDate=parseInt(new Date().getTime());
  220.  
  221. Game.prefs=[];
  222. Game.DefaultPrefs=function()
  223. {
  224. Game.prefs.particles=1;
  225. Game.prefs.numbers=1;
  226. Game.prefs.autosave=1;
  227. Game.prefs.autoupdate=1;
  228. Game.prefs.milk=1;
  229. Game.prefs.fancy=1;
  230. }
  231. Game.DefaultPrefs();
  232.  
  233. /*=====================================================================================
  234. UPDATE CHECKER (broken?)
  235. =======================================================================================*/
  236. Game.CheckUpdates=function()
  237. {
  238. ajax('server.php?q=checkupdate',Game.CheckUpdatesResponse);
  239. }
  240. Game.CheckUpdatesResponse=function(response)
  241. {
  242. var r=response.split('|');
  243. if (parseFloat(r[0])>Game.version)
  244. {
  245. var str='<b>New version available : v.'+r[0]+'!</b>';
  246. if (r[1]) str+='<br>Update note : "'+r[1]+'"';
  247. str+='<br><b>Refresh to get it!</b>';
  248. l('alert').innerHTML=str;
  249. l('alert').style.display='block';
  250. }
  251. }
  252.  
  253. /*=====================================================================================
  254. SAVE
  255. =======================================================================================*/
  256. Game.ExportSave=function()
  257. {
  258. var save=prompt('Copy this text and keep it somewhere safe!',Game.WriteSave(1));
  259. }
  260. Game.ImportSave=function()
  261. {
  262. var save=prompt('Please paste in the text that was given to you on save export.','');
  263. if (save && save!='') Game.LoadSave(save);
  264. Game.WriteSave();
  265. }
  266.  
  267. Game.WriteSave=function(exporting)//guess what we'e using to save the game?
  268. {
  269. var str='';
  270. str+=Game.version+'|';
  271. str+='|';//just in case we need some more stuff here
  272. str+=//save stats
  273. parseInt(Game.startDate)+
  274. '|';
  275. str+=//prefs
  276. (Game.prefs.particles?'1':'0')+
  277. (Game.prefs.numbers?'1':'0')+
  278. (Game.prefs.autosave?'1':'0')+
  279. (Game.prefs.autoupdate?'1':'0')+
  280. (Game.prefs.milk?'1':'0')+
  281. (Game.prefs.fancy?'1':'0')+
  282. '|';
  283. str+=parseFloat(Math.floor(Game.cookies))+';'+
  284. parseFloat(Math.floor(Game.cookiesEarned))+';'+
  285. parseInt(Math.floor(Game.cookieClicks))+';'+
  286. parseInt(Math.floor(Game.goldenClicks))+';'+
  287. parseFloat(Math.floor(Game.handmadeCookies))+';'+
  288. parseInt(Math.floor(Game.missedGoldenClicks))+';'+
  289. parseInt(Math.floor(Game.backgroundType))+';'+
  290. parseInt(Math.floor(Game.milkType))+';'+
  291. parseFloat(Math.floor(Game.cookiesReset))+';'+
  292. parseInt(Math.floor(Game.elderWrath))+';'+
  293. parseInt(Math.floor(Game.pledges))+';'+
  294. parseInt(Math.floor(Game.pledgeT))+';'+
  295. parseInt(Math.floor(Game.nextResearch))+';'+
  296. parseInt(Math.floor(Game.researchT))+
  297. '|';//cookies
  298. for (var i in Game.Objects)//buildings
  299. {
  300. var me=Game.Objects[i];
  301. str+=me.amount+','+me.bought+','+Math.floor(me.totalCookies)+','+me.specialUnlocked+';';
  302. }
  303. str+='|';
  304. var toCompress=[];
  305. for (var i in Game.Upgrades)//upgrades
  306. {
  307. var me=Game.Upgrades[i];
  308. toCompress.push(Math.min(me.unlocked,1),Math.min(me.bought,1));
  309. }
  310. toCompress=CompressLargeBin(toCompress);
  311. str+=toCompress;
  312. str+='|';
  313. var toCompress=[];
  314. for (var i in Game.Achievements)//achievements
  315. {
  316. var me=Game.Achievements[i];
  317. toCompress.push(Math.min(me.won));
  318. }
  319. toCompress=CompressLargeBin(toCompress);
  320. str+=toCompress;
  321.  
  322.  
  323. if (exporting)
  324. {
  325. str=escape(utf8_to_b64(str)+'!END!');
  326. return str;
  327. }
  328. else
  329. {
  330. //that's right
  331. //we're using cookies
  332. //yeah I went there
  333. var now=new Date();//we storin dis for 5 years, people
  334. now.setFullYear(now.getFullYear()+5);//mmh stale cookies
  335. str=utf8_to_b64(str)+'!END!';
  336. str='CookieClickerGame='+escape(str)+'; expires='+now.toUTCString()+';';
  337. document.cookie=str;//aaand save
  338. if (document.cookie.indexOf('CookieClickerGame')<0) Game.Popup('Error while saving.<br>Export your save instead!');
  339. else Game.Popup('Game saved');
  340. }
  341. }
  342.  
  343. /*=====================================================================================
  344. LOAD
  345. =======================================================================================*/
  346. Game.LoadSave=function(data)
  347. {
  348. var str='';
  349. if (data) str=unescape(data);
  350. else if (document.cookie.indexOf('CookieClickerGame')>=0) str=unescape(document.cookie.split('CookieClickerGame=')[1]);//get cookie here
  351.  
  352. if (str!='')
  353. {
  354. var version=0;
  355. var oldstr=str.split('|');
  356. if (oldstr[0]<1) {}
  357. else
  358. {
  359. str=str.split('!END!')[0];
  360. str=b64_to_utf8(str);
  361. }
  362. if (str!='')
  363. {
  364. var spl='';
  365. str=str.split('|');
  366. version=parseFloat(str[0]);
  367. if (version>=1 && version>Game.version)
  368. {
  369. alert('Error : you are attempting to load a save from a later version (v.'+version+'; you are using v.'+Game.version+').');
  370. return;
  371. }
  372. else if (version>=1)
  373. {
  374. spl=str[2].split(';');//save stats
  375. Game.startDate=parseInt(spl[0]);
  376. spl=str[3].split('');//prefs
  377. Game.prefs.particles=parseInt(spl[0]);
  378. Game.prefs.numbers=parseInt(spl[1]);
  379. Game.prefs.autosave=parseInt(spl[2]);
  380. Game.prefs.autoupdate=spl[3]?parseInt(spl[3]):1;
  381. Game.prefs.milk=spl[4]?parseInt(spl[4]):1;
  382. Game.prefs.fancy=parseInt(spl[5]);if (Game.prefs.fancy) Game.removeClass('noFancy'); else if (!Game.prefs.fancy) Game.addClass('noFancy');
  383. spl=str[4].split(';');//cookies
  384. Game.cookies=parseFloat(spl[0]);Game.cookiesEarned=parseFloat(spl[1]);
  385. Game.cookieClicks=spl[2]?parseInt(spl[2]):0;
  386. Game.goldenClicks=spl[3]?parseInt(spl[3]):0;
  387. Game.handmadeCookies=spl[4]?parseFloat(spl[4]):0;
  388. Game.missedGoldenClicks=spl[5]?parseInt(spl[5]):0;
  389. Game.backgroundType=spl[6]?parseInt(spl[6]):0;
  390. Game.milkType=spl[7]?parseInt(spl[7]):0;
  391. Game.cookiesReset=spl[8]?parseFloat(spl[8]):0;
  392. Game.elderWrath=spl[9]?parseInt(spl[9]):0;
  393. Game.pledges=spl[10]?parseInt(spl[10]):0;
  394. Game.pledgeT=spl[11]?parseInt(spl[11]):0;
  395. Game.nextResearch=spl[12]?parseInt(spl[12]):0;
  396. Game.researchT=spl[13]?parseInt(spl[13]):0;
  397. spl=str[5].split(';');//buildings
  398. Game.BuildingsOwned=0;
  399. for (var i in Game.ObjectsById)
  400. {
  401. var me=Game.ObjectsById[i];
  402. if (spl[i])
  403. {
  404. var mestr=spl[i].toString().split(',');
  405. me.amount=parseInt(mestr[0]);me.bought=parseInt(mestr[1]);me.totalCookies=parseInt(mestr[2]);me.specialUnlocked=parseInt(mestr[3]);
  406. Game.BuildingsOwned+=me.amount;
  407. }
  408. else
  409. {
  410. me.unlocked=0;me.bought=0;me.totalCookies=0;
  411. }
  412. }
  413. if (version<1.035)//old non-binary algorithm
  414. {
  415. spl=str[6].split(';');//upgrades
  416. Game.UpgradesOwned=0;
  417. for (var i in Game.UpgradesById)
  418. {
  419. var me=Game.UpgradesById[i];
  420. if (spl[i])
  421. {
  422. var mestr=spl[i].split(',');
  423. me.unlocked=parseInt(mestr[0]);me.bought=parseInt(mestr[1]);
  424. if (me.bought) Game.UpgradesOwned++;
  425. }
  426. else
  427. {
  428. me.unlocked=0;me.bought=0;
  429. }
  430. }
  431. if (str[7]) spl=str[7].split(';'); else spl=[];//achievements
  432. Game.AchievementsOwned=0;
  433. for (var i in Game.AchievementsById)
  434. {
  435. var me=Game.AchievementsById[i];
  436. if (spl[i])
  437. {
  438. var mestr=spl[i].split(',');
  439. me.won=parseInt(mestr[0]);
  440. }
  441. else
  442. {
  443. me.won=0;
  444. }
  445. if (me.won && me.hide!=3) Game.AchievementsOwned++;
  446. }
  447. }
  448. else
  449. {
  450. if (str[6]) spl=str[6]; else spl=[];//upgrades
  451. spl=UncompressLargeBin(spl);
  452. Game.UpgradesOwned=0;
  453. for (var i in Game.UpgradesById)
  454. {
  455. var me=Game.UpgradesById[i];
  456. if (spl[i*2])
  457. {
  458. var mestr=[spl[i*2],spl[i*2+1]];
  459. me.unlocked=parseInt(mestr[0]);me.bought=parseInt(mestr[1]);
  460. if (me.bought) Game.UpgradesOwned++;
  461. }
  462. else
  463. {
  464. me.unlocked=0;me.bought=0;
  465. }
  466. }
  467. if (str[7]) spl=str[7]; else spl=[];//achievements
  468. spl=UncompressLargeBin(spl);
  469. Game.AchievementsOwned=0;
  470. for (var i in Game.AchievementsById)
  471. {
  472. var me=Game.AchievementsById[i];
  473. if (spl[i])
  474. {
  475. var mestr=[spl[i]];
  476. me.won=parseInt(mestr[0]);
  477. }
  478. else
  479. {
  480. me.won=0;
  481. }
  482. if (me.won && me.hide!=3) Game.AchievementsOwned++;
  483. }
  484. }
  485.  
  486.  
  487. for (var i in Game.ObjectsById)
  488. {
  489. var me=Game.ObjectsById[i];
  490. if (me.buyFunction) me.buyFunction();
  491. me.setSpecial(0);
  492. if (me.special) me.special();
  493. me.refresh();
  494. }
  495. }
  496. else//importing old version save
  497. {
  498. /*
  499. Game.startDate=parseInt(new Date().getTime());
  500. Game.cookies=parseInt(str[1]);
  501. Game.cookiesEarned=parseInt(str[1]);
  502.  
  503. for (var i in Game.ObjectsById)
  504. {
  505. var me=Game.ObjectsById[i];
  506. me.amount=0;me.bought=0;me.totalCookies=0;
  507. me.refresh();
  508. }
  509. for (var i in Game.UpgradesById)
  510. {
  511. var me=Game.UpgradesById[i];
  512. me.unlocked=0;me.bought=0;
  513. }
  514.  
  515. var moni=0;
  516. moni+=15*Math.pow(1.1,parseInt(str[2]));
  517. moni+=100*Math.pow(1.1,parseInt(str[4]));
  518. moni+=500*Math.pow(1.1,parseInt(str[6]));
  519. moni+=2000*Math.pow(1.1,parseInt(str[8]));
  520. moni+=7000*Math.pow(1.1,parseInt(str[10]));
  521. moni+=50000*Math.pow(1.1,parseInt(str[12]));
  522. moni+=1000000*Math.pow(1.1,parseInt(str[14]));
  523. if (parseInt(str[16])) moni+=123456789*Math.pow(1.1,parseInt(str[16]));
  524.  
  525. alert('Imported old save from version '+version+'; recovered '+Beautify(Game.cookies)+' cookies, and converted buildings back to '+Beautify(moni)+' cookies.');
  526.  
  527. Game.cookies+=moni;
  528. Game.cookiesEarned+=moni;
  529. */
  530. alert('Sorry, you can\'t import saves from the old version anymore.');
  531. return;
  532. }
  533.  
  534.  
  535. Game.goldenCookie.reset();
  536.  
  537. Game.prestige=[];
  538.  
  539. Game.Upgrades['Elder Pledge'].basePrice=Math.pow(8,Math.min(Game.pledges+2,13));
  540.  
  541. Game.RebuildUpgrades();
  542.  
  543. Game.TickerAge=0;
  544.  
  545. Game.elderWrathD=0;
  546. Game.frenzy=0;
  547. Game.frenzyPower=1;
  548. Game.clickFrenzy=0;
  549. Game.recalculateGains=1;
  550. Game.storeToRebuild=1;
  551. Game.upgradesToRebuild=1;
  552. Game.Popup('Game loaded');
  553. }
  554. }
  555. }
  556.  
  557. /*=====================================================================================
  558. RESET
  559. =======================================================================================*/
  560. Game.Reset=function(bypass)
  561. {
  562. if (bypass || confirm('Do you REALLY want to start over?\n(your will lose your progress, but you will keep your achievements and your prestige.)'))
  563. {
  564. if (!bypass)
  565. {
  566. if (Game.cookiesEarned>=1000000) Game.Win('Sacrifice');
  567. if (Game.cookiesEarned>=1000000000) Game.Win('Oblivion');
  568. if (Game.cookiesEarned>=1000000000000) Game.Win('From scratch');
  569. if (Game.cookiesEarned>=1000000000000000) Game.Win('Nihilism');
  570. }
  571. Game.cookiesReset+=Game.cookiesEarned;
  572. Game.cookies=0;
  573. Game.cookiesEarned=0;
  574. Game.cookieClicks=0;
  575. //Game.goldenClicks=0;
  576. //Game.missedGoldenClicks=0;
  577. Game.handmadeCookies=0;
  578. Game.backgroundType=-1;
  579. Game.milkType=-1;
  580. Game.frenzy=0;
  581. Game.frenzyPower=1;
  582. Game.clickFrenzy=0;
  583. Game.pledges=0;
  584. Game.pledgeT=0;
  585. Game.elderWrath=0;
  586. Game.nextResearch=0;
  587. Game.researchT=0;
  588. Game.Upgrades['Elder Pledge'].basePrice=Math.pow(8,Math.min(Game.pledges+2,13));
  589. for (var i in Game.ObjectsById)
  590. {
  591. var me=Game.ObjectsById[i];
  592. me.amount=0;me.bought=0;me.totalCookies=0;me.specialUnlocked=0;
  593. me.setSpecial(0);
  594. me.refresh();
  595. }
  596. for (var i in Game.UpgradesById)
  597. {
  598. var me=Game.UpgradesById[i];
  599. me.unlocked=0;me.bought=0;
  600. }
  601. /*
  602. for (var i in Game.AchievementsById)
  603. {
  604. var me=Game.AchievementsById[i];
  605. me.won=0;
  606. }*/
  607. //Game.DefaultPrefs();
  608. Game.BuildingsOwned=0;
  609. Game.UpgradesOwned=0;
  610. Game.RebuildUpgrades();
  611. Game.TickerAge=0;
  612. Game.recalculateGains=1;
  613. Game.storeToRebuild=1;
  614. Game.upgradesToRebuild=1;
  615. Game.startDate=parseInt(new Date().getTime());
  616. Game.goldenCookie.reset();
  617.  
  618. Game.Popup('Game reset');
  619.  
  620. if (!bypass)
  621. {
  622. var prestige=0;
  623. if (Game.prestige.ready) prestige=Game.prestige['Heavenly chips'];
  624. Game.prestige=[];
  625. Game.CalculatePrestige();
  626. prestige=Game.prestige['Heavenly chips']-prestige;
  627. if (prestige!=0) Game.Popup('You earn '+prestige+' heavenly chip'+(prestige==1?'':'s')+'!');
  628. }
  629. }
  630. }
  631. Game.HardReset=function()
  632. {
  633. if (confirm('Do you REALLY want to wipe your save?\n(you will lose your progress, your achievements, and your prestige!)'))
  634. {
  635. if (confirm('Whoah now, are you really, REALLY sure?\n(don\'t say we didn\'t warn you!)'))
  636. {
  637. for (var i in Game.AchievementsById)
  638. {
  639. var me=Game.AchievementsById[i];
  640. me.won=0;
  641. }
  642. Game.AchievementsOwned=0;
  643. Game.goldenClicks=0;
  644. Game.missedGoldenClicks=0;
  645. Game.Reset(1);
  646. Game.cookiesReset=0;
  647. Game.prestige=[];
  648. Game.CalculatePrestige();
  649. }
  650. }
  651. }
  652.  
  653.  
  654. /*=====================================================================================
  655. COOKIE ECONOMICS
  656. =======================================================================================*/
  657. Game.Earn=function(howmuch)
  658. {
  659. Game.cookies+=howmuch;
  660. Game.cookiesEarned+=howmuch;
  661. }
  662. Game.Spend=function(howmuch)
  663. {
  664. Game.cookies-=howmuch;
  665. }
  666. Game.mouseCps=function()
  667. {
  668. var add=0;
  669. if (Game.Has('Thousand fingers')) add+=0.1;
  670. if (Game.Has('Million fingers')) add+=0.5;
  671. if (Game.Has('Billion fingers')) add+=2;
  672. if (Game.Has('Trillion fingers')) add+=10;
  673. if (Game.Has('Quadrillion fingers')) add+=20;
  674. if (Game.Has('Quintillion fingers')) add+=100;
  675. var num=0;
  676. for (var i in Game.Objects) {if (Game.Objects[i].name!='Cursor') num+=Game.Objects[i].amount;}
  677. add=add*num;
  678. if (Game.Has('Plastic mouse')) add+=Game.cookiesPs*0.01;
  679. if (Game.Has('Iron mouse')) add+=Game.cookiesPs*0.01;
  680. if (Game.Has('Titanium mouse')) add+=Game.cookiesPs*0.01;
  681. if (Game.Has('Adamantium mouse')) add+=Game.cookiesPs*0.01;
  682. var mult=1;
  683. if (Game.clickFrenzy>0) mult*=777;
  684. return mult*Game.ComputeCps(1,Game.Has('Reinforced index finger'),Game.Has('Carpal tunnel prevention cream')+Game.Has('Ambidextrous'),add);
  685. }
  686. Game.computedMouseCps=1;
  687. Game.globalCpsMult=1;
  688. Game.lastClick=0;
  689. Game.autoclickerDetected=0;
  690. Game.ClickCookie=function()
  691. {
  692. if (new Date().getTime()-Game.lastClick<1000/250)
  693. {
  694. }
  695. else
  696. {
  697. if (new Date().getTime()-Game.lastClick<1000/15)
  698. {
  699. Game.autoclickerDetected+=Game.fps;
  700. if (Game.autoclickerDetected>=Game.fps*5) Game.Win('Uncanny clicker');
  701. }
  702. Game.Earn(Game.computedMouseCps);
  703. Game.handmadeCookies+=Game.computedMouseCps;
  704. if (Game.prefs.particles) Game.cookieParticleAdd();
  705. if (Game.prefs.numbers) Game.cookieNumberAdd('+'+Beautify(Game.computedMouseCps,1));
  706. Game.cookieClicks++;
  707. }
  708. Game.lastClick=new Date().getTime();
  709. }
  710. l('bigCookie').onclick=Game.ClickCookie;
  711.  
  712. Game.HowMuchPrestige=function(cookies)
  713. {
  714. var prestige=cookies/1000000000000;
  715. //prestige=Math.max(0,Math.floor(Math.pow(prestige,0.5)));//old version
  716. prestige=Math.max(0,Math.floor((-1+Math.pow(1+8*prestige,0.5))/2));//geometric progression
  717. return prestige;
  718. }
  719. Game.CalculatePrestige=function()
  720. {
  721. var prestige=Game.HowMuchPrestige(Game.cookiesReset);
  722. Game.prestige=[];
  723. Game.prestige['Heavenly chips']=prestige;
  724. Game.prestige.ready=1;
  725. }
  726. /*=====================================================================================
  727. CPS RECALCULATOR
  728. =======================================================================================*/
  729. Game.recalculateGains=1;
  730. Game.CalculateGains=function()
  731. {
  732. Game.cookiesPs=0;
  733. var mult=1;
  734. for (var i in Game.Upgrades)
  735. {
  736. var me=Game.Upgrades[i];
  737. if (me.bought>0)
  738. {
  739. if (me.type=='cookie' && Game.Has(me.name)) mult+=me.power*0.01;
  740. }
  741. }
  742. mult+=Game.Has('Specialized chocolate chips')*0.01;
  743. mult+=Game.Has('Designer cocoa beans')*0.02;
  744. mult+=Game.Has('Underworld ovens')*0.03;
  745. mult+=Game.Has('Exotic nuts')*0.04;
  746. mult+=Game.Has('Arcane sugar')*0.05;
  747.  
  748. if (!Game.prestige.ready) Game.CalculatePrestige();
  749. mult+=parseInt(Game.prestige['Heavenly chips'])*0.02;
  750.  
  751. for (var i in Game.Objects)
  752. {
  753. var me=Game.Objects[i];
  754. me.storedCps=(typeof(me.cps)=='function'?me.cps():me.cps);
  755. me.storedTotalCps=me.amount*me.storedCps;
  756. Game.cookiesPs+=me.storedTotalCps;
  757. }
  758.  
  759. if (Game.Has('Kitten helpers')) mult*=(1+Game.milkProgress*0.05);
  760. if (Game.Has('Kitten workers')) mult*=(1+Game.milkProgress*0.1);
  761. if (Game.Has('Kitten engineers')) mult*=(1+Game.milkProgress*0.2);
  762. if (Game.Has('Kitten overseers')) mult*=(1+Game.milkProgress*0.3);
  763.  
  764. if (Game.frenzy>0) mult*=Game.frenzyPower;
  765.  
  766. if (Game.Has('Elder Covenant')) mult*=0.95;
  767.  
  768. Game.globalCpsMult=mult;
  769. Game.cookiesPs*=Game.globalCpsMult;
  770.  
  771. for (var i=0;i<Game.cpsAchievs.length/2;i++)
  772. {
  773. if (Game.cookiesPs>=Game.cpsAchievs[i*2+1]) Game.Win(Game.cpsAchievs[i*2]);
  774. }
  775.  
  776. Game.computedMouseCps=Game.mouseCps();
  777.  
  778. Game.recalculateGains=0;
  779. }
  780. /*=====================================================================================
  781. GOLDEN COOKIE
  782. =======================================================================================*/
  783. Game.goldenCookie={x:0,y:0,life:0,delay:0,dur:13,toDie:1,wrath:0,chain:0,last:''};
  784. Game.goldenCookie.reset=function()
  785. {
  786. Game.goldenCookie.life=0;
  787. Game.goldenCookie.delay=0;
  788. Game.goldenCookie.dur=13;
  789. Game.goldenCookie.toDie=1;
  790. Game.goldenCookie.last='';
  791. Game.goldenCookie.chain=0;
  792. }
  793. Game.goldenCookie.spawn=function()
  794. {
  795. if (Game.goldenCookie.delay!=0 || Game.goldenCookie.life!=0) Game.Win('Cheated cookies taste awful');
  796. var me=l('goldenCookie');
  797. if ((Game.elderWrath==1 && Math.random()<0.33) || (Game.elderWrath==2 && Math.random()<0.66) || (Game.elderWrath==3))
  798. {
  799. Game.goldenCookie.wrath=1;
  800. me.style.background='url(img/wrathCookie.png)';
  801. }
  802. else
  803. {
  804. Game.goldenCookie.wrath=0;
  805. me.style.background='url(img/goldCookie.png)';
  806. }
  807. var r=Math.floor(Math.random()*360);
  808. me.style.transform='rotate('+r+'deg)';
  809. me.style.mozTransform='rotate('+r+'deg)';
  810. me.style.webkitTransform='rotate('+r+'deg)';
  811. me.style.msTransform='rotate('+r+'deg)';
  812. me.style.oTransform='rotate('+r+'deg)';
  813. var screen=l('game').getBoundingClientRect();
  814. Game.goldenCookie.x=Math.floor(Math.random()*(screen.right-screen.left-128)+screen.left+64)-64;
  815. Game.goldenCookie.y=Math.floor(Math.random()*(screen.bottom-screen.top-128)+screen.top+64)-64;
  816. me.style.left=Game.goldenCookie.x+'px';
  817. me.style.top=Game.goldenCookie.y+'px';
  818. me.style.display='block';
  819. var dur=13;
  820. if (Game.Has('Lucky day')) dur*=2;
  821. if (Game.Has('Serendipity')) dur*=2;
  822. if (Game.goldenCookie.chain>0) dur=6;
  823. Game.goldenCookie.dur=dur;
  824. Game.goldenCookie.life=Game.fps*Game.goldenCookie.dur;
  825. me.toDie=0;
  826. }
  827. Game.goldenCookie.update=function()
  828. {
  829. if (Game.goldenCookie.delay==0 && Game.goldenCookie.life==0) Game.goldenCookie.spawn();
  830. if (Game.goldenCookie.life>0)
  831. {
  832. Game.goldenCookie.life--;
  833. l('goldenCookie').style.opacity=1-Math.pow((Game.goldenCookie.life/(Game.fps*Game.goldenCookie.dur))*2-1,4);
  834. if (Game.goldenCookie.life==0 || Game.goldenCookie.toDie==1)
  835. {
  836. if (Game.goldenCookie.life==0) Game.goldenCookie.chain=0;
  837. var m=(5+Math.floor(Math.random()*10));
  838. if (Game.Has('Lucky day')) m/=2;
  839. if (Game.Has('Serendipity')) m/=2;
  840. if (Game.goldenCookie.chain>0) m=0.05;
  841. if (Game.Has('Gold hoard')) m=0.01;
  842. Game.goldenCookie.delay=Math.ceil(Game.fps*60*m);
  843. l('goldenCookie').style.display='none';
  844. if (Game.goldenCookie.toDie==0) Game.missedGoldenClicks++;
  845. Game.goldenCookie.toDie=0;
  846. Game.goldenCookie.life=0;
  847. }
  848. }
  849. if (Game.goldenCookie.delay>0) Game.goldenCookie.delay--;
  850. }
  851. Game.goldenCookie.choose=function()
  852. {
  853. var list=[];
  854. if (Game.goldenCookie.wrath>0) list.push('clot','multiply cookies','ruin cookies');
  855. else list.push('frenzy','multiply cookies');
  856. if (Game.goldenCookie.wrath>0 && Math.random()<0.3) list.push('blood frenzy','chain cookie');
  857. else if (Math.random()<0.01 && Game.cookiesEarned>=100000) list.push('chain cookie');
  858. if (Math.random()<0.05) list.push('click frenzy');
  859. if (Game.goldenCookie.last!='' && Math.random()<0.8 && list.indexOf(Game.goldenCookie.last)!=-1) list.splice(list.indexOf(Game.goldenCookie.last),1);//80% chance to force a different one
  860. var choice=choose(list);
  861. return choice;
  862. }
  863. Game.goldenCookie.click=function()
  864. {
  865. if (Game.goldenCookie.life>0)
  866. {
  867. Game.goldenCookie.toDie=1;
  868. Game.goldenClicks++;
  869.  
  870. if (Game.goldenClicks>=1) Game.Win('Golden cookie');
  871. if (Game.goldenClicks>=7) Game.Win('Lucky cookie');
  872. if (Game.goldenClicks>=27) Game.Win('A stroke of luck');
  873. if (Game.goldenClicks>=77) Game.Win('Fortune');
  874. if (Game.goldenClicks>=777) Game.Win('Leprechaun');
  875. if (Game.goldenClicks>=7777) Game.Win('Black cat\'s paw');
  876.  
  877. if (Game.goldenClicks>=7) Game.Unlock('Lucky day');
  878. if (Game.goldenClicks>=27) Game.Unlock('Serendipity');
  879. if (Game.goldenClicks>=77) Game.Unlock('Get lucky');
  880.  
  881. l('goldenCookie').style.display='none';
  882.  
  883. var choice=Game.goldenCookie.choose();
  884.  
  885. if (Game.goldenCookie.chain>0) choice='chain cookie';
  886. Game.goldenCookie.last=choice;
  887.  
  888. if (choice!='chain cookie') Game.goldenCookie.chain=0;
  889. if (choice=='frenzy')
  890. {
  891. var time=77+77*Game.Has('Get lucky');
  892. Game.frenzy=Game.fps*time;
  893. Game.frenzyPower=7;
  894. Game.recalculateGains=1;
  895. Game.Popup('Frenzy : cookie production x7 for '+time+' seconds!');
  896. }
  897. else if (choice=='multiply cookies')
  898. {
  899. var moni=Math.min(Game.cookies*0.1,Game.cookiesPs*60*20)+13;//add 10% to cookies owned (+13), or 20 minutes of cookie production - whichever is lowest
  900. Game.Earn(moni);
  901. Game.Popup('Lucky! +'+Beautify(moni)+' cookies!');
  902. }
  903. else if (choice=='ruin cookies')
  904. {
  905. var moni=Math.min(Game.cookies*0.05,Game.cookiesPs*60*10)+13;//lose 5% of cookies owned (-13), or 10 minutes of cookie production - whichever is lowest
  906. moni=Math.min(Game.cookies,moni);
  907. Game.Spend(moni);
  908. Game.Popup('Ruin! Lost '+Beautify(moni)+' cookies!');
  909. }
  910. else if (choice=='blood frenzy')
  911. {
  912. var time=6+6*Game.Has('Get lucky');
  913. Game.frenzy=Game.fps*time;//*2;//we shouldn't need *2 but I keep getting reports of it lasting only 3 seconds
  914. Game.frenzyPower=666;
  915. Game.recalculateGains=1;
  916. Game.Popup('Elder frenzy : cookie production x666 for '+time+' seconds!');
  917. }
  918. else if (choice=='clot')
  919. {
  920. var time=66+66*Game.Has('Get lucky');
  921. Game.frenzy=Game.fps*time;
  922. Game.frenzyPower=0.5;
  923. Game.recalculateGains=1;
  924. Game.Popup('Clot : cookie production halved for '+time+' seconds!');
  925. }
  926. else if (choice=='click frenzy')
  927. {
  928. var time=13+13*Game.Has('Get lucky');
  929. Game.clickFrenzy=Game.fps*time;
  930. Game.recalculateGains=1;
  931. Game.Popup('Click frenzy! Clicking power x777 for '+time+' seconds!');
  932. }
  933. else if (choice=='chain cookie')
  934. {
  935. Game.goldenCookie.chain++;
  936. var moni='';
  937. for (var i=0;i<Game.goldenCookie.chain;i++) {moni+='6';}
  938. moni=parseInt(moni);
  939. Game.Popup('Cookie chain : +'+Beautify(moni)+' cookies!');
  940. if ((Math.random()<0.1 || Game.goldenCookie.chain>12 || moni>=Game.cookies*1) && Game.goldenCookie.chain>4) Game.goldenCookie.chain=0;
  941. Game.Earn(moni);
  942. }
  943. }
  944. }
  945. l('goldenCookie').onclick=Game.goldenCookie.click;
  946.  
  947.  
  948. /*=====================================================================================
  949. PARTICLES
  950. =======================================================================================*/
  951. //falling cookies
  952. Game.cookieParticles=[];
  953. var str='';
  954. for (var i=0;i<40;i++)
  955. {
  956. Game.cookieParticles[i]={x:0,y:0,life:-1};
  957. str+='<div id="cookieParticle'+i+'" class="cookieParticle"></div>';
  958. }
  959. l('cookieShower').innerHTML=str;
  960. Game.cookieParticlesUpdate=function()
  961. {
  962. for (var i in Game.cookieParticles)
  963. {
  964. var me=Game.cookieParticles[i];
  965. if (me.life!=-1)
  966. {
  967. me.y+=me.life*0.5+Math.random()*0.5;
  968. me.life++;
  969. var el=me.l;
  970. el.style.left=Math.floor(me.x)+'px';
  971. el.style.top=Math.floor(me.y)+'px';
  972. el.style.opacity=1-(me.life/(Game.fps*2));
  973. if (me.life>=Game.fps*2)
  974. {
  975. me.life=-1;
  976. me.l.style.opacity=0;
  977. }
  978. }
  979. }
  980. }
  981. Game.cookieParticleAdd=function()
  982. {
  983. //pick the first free (or the oldest) particle to replace it
  984. if (Game.prefs.particles)
  985. {
  986. var highest=0;
  987. var highestI=0;
  988. for (var i in Game.cookieParticles)
  989. {
  990. if (Game.cookieParticles[i].life==-1) {highestI=i;break;}
  991. if (Game.cookieParticles[i].life>highest)
  992. {
  993. highest=Game.cookieParticles[i].life;
  994. highestI=i;
  995. }
  996. }
  997. var i=highestI;
  998. var rect=l('cookieShower').getBoundingClientRect();
  999. var x=Math.floor(Math.random()*(rect.right-rect.left));
  1000. var y=-32;
  1001. var me=Game.cookieParticles[i];
  1002. if (!me.l) me.l=l('cookieParticle'+i);
  1003. me.life=0;
  1004. me.x=x;
  1005. me.y=y;
  1006. var r=Math.floor(Math.random()*360);
  1007. me.l.style.backgroundPosition=(Math.floor(Math.random()*8)*64)+'px 0px';
  1008. me.l.style.transform='rotate('+r+'deg)';
  1009. me.l.style.mozTransform='rotate('+r+'deg)';
  1010. me.l.style.webkitTransform='rotate('+r+'deg)';
  1011. me.l.style.msTransform='rotate('+r+'deg)';
  1012. me.l.style.oTransform='rotate('+r+'deg)';
  1013. }
  1014. }
  1015.  
  1016. //rising numbers
  1017. Game.cookieNumbers=[];
  1018. var str='';
  1019. for (var i=0;i<20;i++)
  1020. {
  1021. Game.cookieNumbers[i]={x:0,y:0,life:-1,text:''};
  1022. str+='<div id="cookieNumber'+i+'" class="cookieNumber title"></div>';
  1023. }
  1024. l('cookieNumbers').innerHTML=str;
  1025. Game.cookieNumbersUpdate=function()
  1026. {
  1027. for (var i in Game.cookieNumbers)
  1028. {
  1029. var me=Game.cookieNumbers[i];
  1030. if (me.life!=-1)
  1031. {
  1032. me.y-=me.life*0.5+Math.random()*0.5;
  1033. me.life++;
  1034. var el=me.l;
  1035. el.style.left=Math.floor(me.x)+'px';
  1036. el.style.top=Math.floor(me.y)+'px';
  1037. el.style.opacity=1-(me.life/(Game.fps*1));
  1038. //l('cookieNumber'+i).style.zIndex=(1000+(Game.fps*1-me.life));
  1039. if (me.life>=Game.fps*1)
  1040. {
  1041. me.life=-1;
  1042. me.l.style.opacity=0;
  1043. }
  1044. }
  1045. }
  1046. }
  1047. Game.cookieNumberAdd=function(text)
  1048. {
  1049. //pick the first free (or the oldest) particle to replace it
  1050. var highest=0;
  1051. var highestI=0;
  1052. for (var i in Game.cookieNumbers)
  1053. {
  1054. if (Game.cookieNumbers[i].life==-1) {highestI=i;break;}
  1055. if (Game.cookieNumbers[i].life>highest)
  1056. {
  1057. highest=Game.cookieNumbers[i].life;
  1058. highestI=i;
  1059. }
  1060. }
  1061. var i=highestI;
  1062. var x=-100+(Math.random()-0.5)*40;
  1063. var y=0+(Math.random()-0.5)*40;
  1064. var me=Game.cookieNumbers[i];
  1065. if (!me.l) me.l=l('cookieNumber'+i);
  1066. me.life=0;
  1067. me.x=x;
  1068. me.y=y;
  1069. me.text=text;
  1070. me.l.innerHTML=text;
  1071. me.l.style.left=Math.floor(Game.cookieNumbers[i].x)+'px';
  1072. me.l.style.top=Math.floor(Game.cookieNumbers[i].y)+'px';
  1073. }
  1074.  
  1075. //generic particles
  1076. Game.particles=[];
  1077. Game.particlesY=0;
  1078. var str='';
  1079. for (var i=0;i<20;i++)
  1080. {
  1081. Game.particles[i]={x:0,y:0,life:-1,text:''};
  1082. str+='<div id="particle'+i+'" class="particle title"></div>';
  1083. }
  1084. l('particles').innerHTML=str;
  1085. Game.particlesUpdate=function()
  1086. {
  1087. Game.particlesY=0;
  1088. for (var i in Game.particles)
  1089. {
  1090. var me=Game.particles[i];
  1091. if (me.life!=-1)
  1092. {
  1093. Game.particlesY+=64;//me.l.clientHeight;
  1094. var y=me.y-(1-Math.pow(1-me.life/(Game.fps*4),10))*50;
  1095. //me.y=me.life*0.25+Math.random()*0.25;
  1096. me.life++;
  1097. var el=me.l;
  1098. el.style.left=Math.floor(-200+me.x)+'px';
  1099. el.style.bottom=Math.floor(-y)+'px';
  1100. el.style.opacity=1-(me.life/(Game.fps*4));
  1101. if (me.life>=Game.fps*4)
  1102. {
  1103. me.life=-1;
  1104. el.style.opacity=0;
  1105. el.style.display='none';
  1106. }
  1107. }
  1108. }
  1109. }
  1110. Game.particlesAdd=function(text,el)
  1111. {
  1112. //pick the first free (or the oldest) particle to replace it
  1113. var highest=0;
  1114. var highestI=0;
  1115. for (var i in Game.particles)
  1116. {
  1117. if (Game.particles[i].life==-1) {highestI=i;break;}
  1118. if (Game.particles[i].life>highest)
  1119. {
  1120. highest=Game.particles[i].life;
  1121. highestI=i;
  1122. }
  1123. }
  1124. var i=highestI;
  1125. var x=(Math.random()-0.5)*40;
  1126. var y=0;//+(Math.random()-0.5)*40;
  1127. if (!el)
  1128. {
  1129. var rect=l('game').getBoundingClientRect();
  1130. var x=Math.floor((rect.left+rect.right)/2);
  1131. var y=Math.floor((rect.bottom));
  1132. x+=(Math.random()-0.5)*40;
  1133. y+=0;//(Math.random()-0.5)*40;
  1134. }
  1135. var me=Game.particles[i];
  1136. if (!me.l) me.l=l('particle'+i);
  1137. me.life=0;
  1138. me.x=x;
  1139. me.y=y-Game.particlesY;
  1140. me.text=text;
  1141. me.l.innerHTML=text;
  1142. me.l.style.left=Math.floor(Game.particles[i].x-200)+'px';
  1143. me.l.style.bottom=Math.floor(-Game.particles[i].y)+'px';
  1144. me.l.style.display='block';
  1145. Game.particlesY+=60;
  1146. }
  1147. Game.Popup=function(text)
  1148. {
  1149. Game.particlesAdd(text);
  1150. }
  1151.  
  1152.  
  1153. Game.veil=1;
  1154. Game.veilOn=function()
  1155. {
  1156. //l('sectionMiddle').style.display='none';
  1157. l('sectionRight').style.display='none';
  1158. l('backgroundLayer2').style.background='#000 url(img/darkNoise.png)';
  1159. Game.veil=1;
  1160. }
  1161. Game.veilOff=function()
  1162. {
  1163. //l('sectionMiddle').style.display='block';
  1164. l('sectionRight').style.display='block';
  1165. l('backgroundLayer2').style.background='transparent';
  1166. Game.veil=0;
  1167. }
  1168.  
  1169. /*=====================================================================================
  1170. MENUS
  1171. =======================================================================================*/
  1172. Game.cssClasses=[];
  1173. Game.addClass=function(what) {if (Game.cssClasses.indexOf(what)==-1) Game.cssClasses.push(what);Game.updateClasses();}
  1174. Game.removeClass=function(what) {var i=Game.cssClasses.indexOf(what);if(i!=-1) {Game.cssClasses.splice(i,1);}Game.updateClasses();}
  1175. Game.updateClasses=function() {var str='';for (var i in Game.cssClasses) {str+=Game.cssClasses[i]+' ';}l('game').className=str;}
  1176.  
  1177. Game.WriteButton=function(prefName,button,on,off,callback)
  1178. {
  1179. return '<a class="option" id="'+button+'" onclick="Game.Toggle(\''+prefName+'\',\''+button+'\',\''+on+'\',\''+off+'\');'+(callback||'')+'">'+(Game.prefs[prefName]?on:off)+'</a>';
  1180. }
  1181. Game.Toggle=function(prefName,button,on,off)
  1182. {
  1183. if (Game.prefs[prefName])
  1184. {
  1185. l(button).innerHTML=off;
  1186. l(button).className='';
  1187. Game.prefs[prefName]=0;
  1188. }
  1189. else
  1190. {
  1191. l(button).innerHTML=on;
  1192. l(button).className='enabled';
  1193. Game.prefs[prefName]=1;
  1194. }
  1195. }
  1196. Game.ToggleFancy=function()
  1197. {
  1198. if (Game.prefs.fancy) Game.removeClass('noFancy');
  1199. else if (!Game.prefs.fancy) Game.addClass('noFancy');
  1200. }
  1201. Game.onMenu='';
  1202. Game.ShowMenu=function(what)
  1203. {
  1204. if (!what) what='';
  1205. if (Game.onMenu=='' && what!='') Game.addClass('onMenu');
  1206. else if (Game.onMenu!='' && what!=Game.onMenu) Game.addClass('onMenu');
  1207. else if (what==Game.onMenu) {Game.removeClass('onMenu');what='';}
  1208. Game.onMenu=what;
  1209. Game.UpdateMenu();
  1210. }
  1211. Game.sayTime=function(time,detail)
  1212. {
  1213. var str='';
  1214. var detail=detail||0;
  1215. time=Math.floor(time);
  1216. if (time>=Game.fps*60*60*24*2 && detail<2) str=Beautify(time/(Game.fps*60*60*24))+' days';
  1217. else if (time>=Game.fps*60*60*24 && detail<2) str='1 day';
  1218. else if (time>=Game.fps*60*60*2 && detail<3) str=Beautify(time/(Game.fps*60*60))+' hours';
  1219. else if (time>=Game.fps*60*60 && detail<3) str='1 hour';
  1220. else if (time>=Game.fps*60*2 && detail<4) str=Beautify(time/(Game.fps*60))+' minutes';
  1221. else if (time>=Game.fps*60 && detail<4) str='1 minute';
  1222. else if (time>=Game.fps*2 && detail<5) str=Beautify(time/(Game.fps))+' seconds';
  1223. else if (time>=Game.fps && detail<5) str='1 second';
  1224. return str;
  1225. }
  1226.  
  1227. Game.UpdateMenu=function()
  1228. {
  1229. var str='';
  1230. if (Game.onMenu!='')
  1231. {
  1232. str+='<div style="position:absolute;top:8px;right:8px;cursor:pointer;font-size:16px;" onclick="Game.ShowMenu(Game.onMenu);">X</div>';
  1233. }
  1234. if (Game.onMenu=='prefs')
  1235. {
  1236. str+='<div class="section">Menu</div>'+
  1237. '<div class="subsection">'+
  1238. '<div class="title">General</div>'+
  1239. '<div class="listing"><a class="option" onclick="Game.WriteSave();">Save</a><label>Save manually (the game autosaves every 60 seconds)</label></div>'+
  1240. '<div class="listing"><a class="option" onclick="Game.ExportSave();">Export save</a><a class="option" onclick="Game.ImportSave();">Import save</a><label>You can use this to backup your save or to transfer it to another computer</label></div>'+
  1241. //'<div class="listing"><span class="warning" style="font-size:12px;">[Note : importing saves from earlier versions than 1.0 will be disabled beyond September 1st, 2013.]</span></div>'+
  1242. '<div class="listing"><a class="option warning" onclick="Game.Reset();">Reset</a><label>Reset your game (you will keep your achievements)</label></div>'+
  1243. '<div class="listing"><a class="option warning" onclick="Game.HardReset();">Wipe save</a><label>Delete all your progress, including your achievements and prestige</label></div>'+
  1244. '<div class="title">Settings</div>'+
  1245. '<div class="listing">'+
  1246. Game.WriteButton('fancy','fancyButton','Fancy graphics ON','Fancy graphics OFF','Game.ToggleFancy();')+
  1247. Game.WriteButton('particles','particlesButton','Particles ON','Particles OFF')+
  1248. Game.WriteButton('numbers','numbersButton','Numbers ON','Numbers OFF')+
  1249. Game.WriteButton('milk','milkButton','Milk ON','Milk OFF')+
  1250. '</div>'+
  1251. '<div class="listing">'+Game.WriteButton('autoupdate','autoupdateButton','Offline mode OFF','Offline mode ON')+'<label>(note : this disables update notifications)</label></div>'+
  1252. //'<div class="listing">'+Game.WriteButton('autosave','autosaveButton','Autosave ON','Autosave OFF')+'</div>'+
  1253. '</div>'
  1254. ;
  1255. }
  1256. if (Game.onMenu=='log')
  1257. {
  1258. str+='<div class="section">Updates</div>'+
  1259. '<div class="subsection">'+
  1260. '<div class="title">Now working on :</div>'+
  1261. '<div class="listing">-android port (iOS and others later)</div>'+
  1262. '<div class="listing">-dungeons</div>'+
  1263.  
  1264. '</div><div class="subsection">'+
  1265. '<div class="title">What\'s next :</div>'+
  1266. '<div class="listing">-dungeons! <a href="http://orteil42.tumblr.com/post/61142292486" target="_blank">(check them out!)</a></div>'+
  1267. '<div class="listing">-more buildings and upgrades!</div>'+
  1268. '<div class="listing">-revamping the prestige system!</div>'+
  1269. '<div class="listing"><span class="warning">Note : this game is updated fairly frequently, which often involves rebalancing. Expect to see prices and cookies/second vary wildly from one update to another!</span></div>'+
  1270.  
  1271. '</div><div class="subsection update small">'+
  1272. '<div class="title">15/09/2013 - anticookies</div>'+
  1273. '<div class="listing">-ran out of regular matter to make your cookies? Try our new antimatter condensers!</div>'+
  1274. '<div class="listing">-renamed Hard-reset to "Wipe save" to avoid confusion</div>'+
  1275. '<div class="listing">-reset achievements are now regular achievements and require cookies baked all time, not cookies in bank</div>'+
  1276. '<div class="listing">-heavenly chips have been nerfed a bit (and are now awarded following a geometric progression : 1 trillion for the first, 2 for the second, etc); the prestige system will be extensively reworked in a future update (after dungeons)</div>'+
  1277. '<div class="listing">-golden cookie clicks are no longer reset by soft-resets</div>'+
  1278. '<div class="listing">-you can now see how long you\'ve been playing in the stats</div>'+
  1279.  
  1280. '</div><div class="subsection update small">'+
  1281. '<div class="title">08/09/2013 - everlasting cookies</div>'+
  1282. '<div class="listing">-added a prestige system - resetting gives you permanent CpS boosts (the more cookies made before resetting, the bigger the boost!)</div>'+
  1283. '<div class="listing">-save format has been slightly modified to take less space</div>'+
  1284. '<div class="listing">-Leprechaun has been bumped to 777 golden cookies clicked and is now shadow; Fortune is the new 77 golden cookies achievement</div>'+
  1285. '<div class="listing">-clicking frenzy is now x777</div>'+
  1286.  
  1287. '</div><div class="subsection update small">'+
  1288. '<div class="title">04/09/2013 - smarter cookie</div>'+
  1289. '<div class="listing">-golden cookies only have 20% chance of giving the same outcome twice in a row now</div>'+
  1290. '<div class="listing">-added a golden cookie upgrade</div>'+
  1291. '<div class="listing">-added an upgrade that makes pledges last twice as long (requires having pledged 10 times)</div>'+
  1292. '<div class="listing">-Quintillion fingers is now twice as efficient</div>'+
  1293. '<div class="listing">-Uncanny clicker was really too unpredictable; it is now a regular achievement and no longer requires a world record, just *pretty fast* clicking</div>'+
  1294.  
  1295. '</div><div class="subsection update small">'+
  1296. '<div class="title">02/09/2013 - a better way out</div>'+
  1297. '<div class="listing">-Elder Covenant is even cheaper, and revoking it is cheaper still (also added a new achievement for getting it)</div>'+
  1298. '<div class="listing">-each grandma upgrade now requires 15 of the matching building</div>'+
  1299. '<div class="listing">-the dreaded bottom cursor has been fixed with a new cursor display style</div>'+
  1300. '<div class="listing">-added an option for faster, cheaper graphics</div>'+
  1301. '<div class="listing">-base64 encoding has been redone; this might make saving possible again on some older browsers</div>'+
  1302. '<div class="listing">-shadow achievements now have their own section</div>'+
  1303. '<div class="listing">-raspberry juice is now named raspberry milk, despite raspberry juice being delicious and going unquestionably well with cookies</div>'+
  1304. '<div class="listing">-HOTFIX : cursors now click; fancy graphics button renamed; cookies amount now more visible against cursors</div>'+
  1305.  
  1306. '</div><div class="subsection update small">'+
  1307. '<div class="title">01/09/2013 - sorting things out</div>'+
  1308. '<div class="listing">-upgrades and achievements are properly sorted in the stats screen</div>'+
  1309. '<div class="listing">-made Elder Covenant much cheaper and less harmful</div>'+
  1310. '<div class="listing">-importing from the first version has been disabled, as promised</div>'+
  1311. '<div class="listing">-"One mind" now actually asks you to confirm the upgrade</div>'+
  1312.  
  1313. '</div><div class="subsection update small">'+
  1314. '<div class="title">31/08/2013 - hotfixes</div>'+
  1315. '<div class="listing">-added a way to permanently stop the grandmapocalypse</div>'+
  1316. '<div class="listing">-Elder Pledge price is now capped</div>'+
  1317. '<div class="listing">-One Mind and other grandma research upgrades are now a little more powerful, if not 100% accurate</div>'+
  1318. '<div class="listing">-"golden" cookie now appears again during grandmapocalypse; Elder Pledge-related achievements are now unlockable</div>'+
  1319.  
  1320. '</div><div class="subsection update">'+
  1321. '<div class="title">31/08/2013 - too many grandmas</div>'+
  1322. '<div class="listing">-the grandmapocalypse is back, along with more grandma types</div>'+
  1323. '<div class="listing">-added some upgrades that boost your clicking power and make it scale with your cps</div>'+
  1324. '<div class="listing">-clicking achievements made harder; Neverclick is now a shadow achievement; Uncanny clicker should now truly be a world record</div>'+
  1325.  
  1326. '</div><div class="subsection update small">'+
  1327. '<div class="title">28/08/2013 - over-achiever</div>'+
  1328. '<div class="listing">-added a few more achievements</div>'+
  1329. '<div class="listing">-reworked the "Bake X cookies" achievements so they take longer to achieve</div>'+
  1330.  
  1331. '</div><div class="subsection update small">'+
  1332. '<div class="title">27/08/2013 - a bad idea</div>'+
  1333. '<div class="listing">-due to popular demand, retired 5 achievements (the "reset your game" and "cheat" ones); they can still be unlocked, but do not count toward your total anymore. Don\'t worry, there will be many more achievements soon!</div>'+
  1334. '<div class="listing">-made some achievements hidden for added mystery</div>'+
  1335.  
  1336. '</div><div class="subsection update">'+
  1337. '<div class="title">27/08/2013 - a sense of achievement</div>'+
  1338. '<div class="listing">-added achievements (and milk)</div>'+
  1339. '<div class="listing"><i>(this is a big update, please don\'t get too mad if you lose some data!)</i></div>'+
  1340.  
  1341. '</div><div class="subsection update small">'+
  1342. '<div class="title">26/08/2013 - new upgrade tier</div>'+
  1343. '<div class="listing">-added some more upgrades (including a couple golden cookie-related ones)</div>'+
  1344. '<div class="listing">-added clicking stats</div>'+
  1345.  
  1346. '</div><div class="subsection update small">'+
  1347. '<div class="title">26/08/2013 - more tweaks</div>'+
  1348. '<div class="listing">-tweaked a couple cursor upgrades</div>'+
  1349. '<div class="listing">-made time machines less powerful</div>'+
  1350. '<div class="listing">-added offline mode option</div>'+
  1351.  
  1352. '</div><div class="subsection update small">'+
  1353. '<div class="title">25/08/2013 - tweaks</div>'+
  1354. '<div class="listing">-rebalanced progression curve (mid- and end-game objects cost more and give more)</div>'+
  1355. '<div class="listing">-added some more cookie upgrades</div>'+
  1356. '<div class="listing">-added CpS for cursors</div>'+
  1357. '<div class="listing">-added sell button</div>'+
  1358. '<div class="listing">-made golden cookie more useful</div>'+
  1359.  
  1360. '</div><div class="subsection update small">'+
  1361. '<div class="title">24/08/2013 - hotfixes</div>'+
  1362. '<div class="listing">-added import/export feature, which also allows you to retrieve a save game from the old version (will be disabled in a week to prevent too much cheating)</div>'+
  1363. '<div class="listing">-upgrade store now has unlimited slots (just hover over it), due to popular demand</div>'+
  1364. '<div class="listing">-added update log</div>'+
  1365.  
  1366. '</div><div class="subsection update">'+
  1367. '<div class="title">24/08/2013 - big update!</div>'+
  1368. '<div class="listing">-revamped the whole game (new graphics, new game mechanics)</div>'+
  1369. '<div class="listing">-added upgrades</div>'+
  1370. '<div class="listing">-much safer saving</div>'+
  1371.  
  1372. '</div><div class="subsection update">'+
  1373. '<div class="title">08/08/2013 - game launch</div>'+
  1374. '<div class="listing">-made the game in a couple hours, for laughs</div>'+
  1375. '<div class="listing">-kinda starting to regret it</div>'+
  1376. '<div class="listing">-ah well</div>'+
  1377. '</div>'
  1378. ;
  1379. }
  1380. else if (Game.onMenu=='stats')
  1381. {
  1382. var buildingsOwned=0;
  1383. buildingsOwned=Game.BuildingsOwned;
  1384. var upgrades='';
  1385. var cookieUpgrades='';
  1386. var upgradesTotal=0;
  1387. var upgradesOwned=0;
  1388.  
  1389. var list=[];
  1390. for (var i in Game.Upgrades)//sort the upgrades
  1391. {
  1392. list.push(Game.Upgrades[i]);
  1393. }
  1394. var sortMap=function(a,b)
  1395. {
  1396. if (a.order>b.order) return 1;
  1397. else if (a.order<b.order) return -1;
  1398. else return 0;
  1399. }
  1400. list.sort(sortMap);
  1401. for (var i in list)
  1402. {
  1403. var str2='';
  1404. var me=list[i];
  1405. if (!Game.Has('Neuromancy'))
  1406. {
  1407. if (me.bought>0 && me.hide!=3)
  1408. {
  1409. str2+='<div class="crate upgrade enabled" '+Game.getTooltip(
  1410. '<div style="min-width:200px;"><div style="float:right;"><span class="price">'+Beautify(Math.round(me.basePrice))+'</span></div><small>[Upgrade] [Purchased]</small><div class="name">'+me.name+'</div><div class="description">'+me.desc+'</div></div>'
  1411. ,0,0,'bottom-right')+' style="background-position:'+(-me.icon[0]*48+6)+'px '+(-me.icon[1]*48+6)+'px;"></div>';
  1412. upgradesOwned++;
  1413. }
  1414. }
  1415. else
  1416. {
  1417. str2+='<div onclick="Game.UpgradesById['+me.id+'].toggle();" class="crate upgrade'+(me.bought>0?' enabled':'')+'" '+Game.getTooltip(
  1418. '<div style="min-width:200px;"><div style="float:right;"><span class="price">'+Beautify(Math.round(me.basePrice))+'</span></div><small>[Upgrade]'+(me.bought>0?' [Purchased]':'')+'</small><div class="name">'+me.name+'</div><div class="description">'+me.desc+'</div></div>'
  1419. ,0,0,'bottom-right')+' style="background-position:'+(-me.icon[0]*48+6)+'px '+(-me.icon[1]*48+6)+'px;"></div>';
  1420. upgradesOwned++;
  1421. }
  1422. if (me.hide!=3) upgradesTotal++;
  1423. if (me.type=='cookie') cookieUpgrades+=str2; else upgrades+=str2;
  1424. }
  1425. var achievements='';
  1426. var shadowAchievements='';
  1427. var achievementsOwned=0;
  1428. var achievementsTotal=0;
  1429.  
  1430. var list=[];
  1431. for (var i in Game.Achievements)//sort the achievements
  1432. {
  1433. list.push(Game.Achievements[i]);
  1434. }
  1435. var sortMap=function(a,b)
  1436. {
  1437. if (a.order>b.order) return 1;
  1438. else if (a.order<b.order) return -1;
  1439. else return 0;
  1440. }
  1441. list.sort(sortMap);
  1442.  
  1443. for (var i in list)
  1444. {
  1445. var me=list[i];
  1446. if (!me.disabled && me.hide!=3 || me.won>0) achievementsTotal++;
  1447. if (me.won>0 && me.hide==3)
  1448. {
  1449. shadowAchievements+='<div class="crate achievement enabled" '+Game.getTooltip(
  1450. '<div style="min-width:200px;"><small>[Achievement] [Unlocked]'+(me.hide==3?' [Shadow]':'')+'</small><div class="name">'+me.name+'</div><div class="description">'+me.desc+'</div></div>'
  1451. ,0,0,'bottom-right')+' style="background-position:'+(-me.icon[0]*48+6)+'px '+(-me.icon[1]*48+6)+'px;"></div>';
  1452. achievementsOwned++;
  1453. }
  1454. else if (me.won>0)
  1455. {
  1456. achievements+='<div class="crate achievement enabled" '+Game.getTooltip(
  1457. '<div style="min-width:200px;"><small>[Achievement] [Unlocked]'+(me.hide==3?' [Shadow]':'')+'</small><div class="name">'+me.name+'</div><div class="description">'+me.desc+'</div></div>'
  1458. ,0,0,'bottom-right')+' style="background-position:'+(-me.icon[0]*48+6)+'px '+(-me.icon[1]*48+6)+'px;"></div>';
  1459. achievementsOwned++;
  1460. }
  1461. else if (me.hide==0)
  1462. {//onclick="Game.Win(\''+me.name+'\');"
  1463. achievements+='<div class="crate achievement" '+Game.getTooltip(
  1464. '<div style="min-width:200px;"><small>[Achievement]</small><div class="name">'+me.name+'</div><div class="description">'+me.desc+'</div></div>'
  1465. ,0,0,'bottom-right')+' style="background-position:'+(-me.icon[0]*48+6)+'px '+(-me.icon[1]*48+6)+'px;"></div>';
  1466. }
  1467. else if (me.hide==1)
  1468. {//onclick="Game.Win(\''+me.name+'\');"
  1469. achievements+='<div class="crate achievement" '+Game.getTooltip(
  1470. '<div style="min-width:200px;"><small>[Achievement]</small><div class="name">'+me.name+'</div><div class="description">???</div></div>'
  1471. ,0,0,'bottom-right')+' style="background-position:'+(-0*48+6)+'px '+(-7*48+6)+'px;"></div>';
  1472. }
  1473. else if (me.hide==2)
  1474. {//onclick="Game.Win(\''+me.name+'\');"
  1475. achievements+='<div class="crate achievement" '+Game.getTooltip(
  1476. '<div style="min-width:200px;"><small>[Achievement]</small><div class="name">???</div><div class="description">???</div></div>'
  1477. ,0,0,'bottom-right')+' style="background-position:'+(-0*48+6)+'px '+(-7*48+6)+'px;"></div>';
  1478. }
  1479. }
  1480. var milkName='plain milk';
  1481. if (Game.milkProgress>=2.5) milkName='raspberry milk';
  1482. else if (Game.milkProgress>=1.5) milkName='chocolate milk';
  1483.  
  1484. var researchStr=Game.sayTime(Game.researchT);
  1485. var pledgeStr=Game.sayTime(Game.pledgeT);
  1486. var wrathStr='';
  1487. if (Game.elderWrath==1) wrathStr='awoken';
  1488. else if (Game.elderWrath==2) wrathStr='displeased';
  1489. else if (Game.elderWrath==3) wrathStr='angered';
  1490. else if (Game.elderWrath==0 && Game.pledges>0) wrathStr='appeased';
  1491.  
  1492. var date=new Date();
  1493. date.setTime(new Date().getTime()-Game.startDate);
  1494. date=Game.sayTime(date.getTime()/1000*Game.fps);
  1495.  
  1496.  
  1497. str+='<div class="section">Statistics</div>'+
  1498. '<div class="subsection">'+
  1499. '<div class="title">General</div>'+
  1500. '<div class="listing"><b>Cookies in bank :</b> <div class="price plain">'+Beautify(Game.cookies)+'</div></div>'+
  1501. '<div class="listing"><b>Cookies baked (all time) :</b> <div class="price plain">'+Beautify(Game.cookiesEarned)+'</div></div>'+
  1502. (Game.cookiesReset>0?'<div class="listing"><b>Cookies forfeited by resetting :</b> <div class="price plain">'+Beautify(Game.cookiesReset)+'</div></div>':'')+
  1503. '<div class="listing"><b>Game started :</b> '+date+' ago</div>'+
  1504. '<div class="listing"><b>Buildings owned :</b> '+Beautify(buildingsOwned)+'</div>'+
  1505. '<div class="listing"><b>Cookies per second :</b> '+Beautify(Game.cookiesPs,1)+' <small>(multiplier : '+Beautify(Math.round(Game.globalCpsMult*100),1)+'%)</small></div>'+
  1506. '<div class="listing"><b>Cookies per click :</b> '+Beautify(Game.computedMouseCps,1)+'</div>'+
  1507. '<div class="listing"><b>Cookie clicks :</b> '+Beautify(Game.cookieClicks)+'</div>'+
  1508. '<div class="listing"><b>Hand-made cookies :</b> '+Beautify(Game.handmadeCookies)+'</div>'+
  1509. '<div class="listing"><b>Golden cookie clicks :</b> '+Beautify(Game.goldenClicks)+'</div>'+//' <span class="hidden">(<b>Missed golden cookies :</b> '+Beautify(Game.missedGoldenClicks)+')</span></div>'+
  1510. '<br><div class="listing"><b>Running version :</b> '+Game.version+'</div>'+
  1511.  
  1512. ((researchStr!='' || wrathStr!='' || pledgeStr!='')?(
  1513. '</div><div class="subsection">'+
  1514. '<div class="title">Special</div>'+
  1515. (researchStr!=''?'<div class="listing"><b>Research :</b> '+researchStr+' remaining</div>':'')+
  1516. (wrathStr!=''?'<div class="listing"><b>Grandmatriarchs status :</b> '+wrathStr+'</div>':'')+
  1517. (pledgeStr!=''?'<div class="listing"><b>Pledge :</b> '+pledgeStr+' remaining</div>':'')+
  1518. ''
  1519. ):'')+
  1520.  
  1521. (Game.prestige['Heavenly chips']>0?(
  1522. '</div><div class="subsection">'+
  1523. '<div class="title">Prestige</div>'+
  1524. '<div class="listing"><small>(Note : each heavenly chip grants you +2% CpS multiplier. You can gain more chips by resetting with a lot of cookies.)</small></div>'+
  1525. '<div class="listing"><div class="icon" style="background-position:'+(-19*48)+'px '+(-7*48)+'px;"></div> <span style="vertical-align:100%;"><span class="title" style="font-size:22px;">'+Game.prestige['Heavenly chips']+' heavenly chip'+(Game.prestige['Heavenly chips']==1?'':'s')+'</span> (+'+(Game.prestige['Heavenly chips']*2)+'% CpS)</span></div>'):'')+
  1526.  
  1527. '</div><div class="subsection">'+
  1528. '<div class="title">Upgrades unlocked</div>'+
  1529. '<div class="listing"><b>Unlocked :</b> '+upgradesOwned+'/'+upgradesTotal+' ('+Math.round((upgradesOwned/upgradesTotal)*100)+'%)</div>'+
  1530. '<div class="listing" style="overflow-y:hidden;">'+upgrades+'</div>'+
  1531. (cookieUpgrades!=''?('<div class="listing"><b>Cookies</b></div>'+
  1532. '<div class="listing" style="overflow-y:hidden;">'+cookieUpgrades+'</div>'):'')+
  1533. '</div><div class="subsection" style="padding-bottom:128px;">'+
  1534. '<div class="title">Achievements</div>'+
  1535. '<div class="listing"><b>Unlocked :</b> '+achievementsOwned+'/'+achievementsTotal+' ('+Math.round((achievementsOwned/achievementsTotal)*100)+'%)</div>'+
  1536. '<div class="listing"><b>Milk :</b> '+Math.round(Game.milkProgress*100)+'% ('+milkName+') <small>(Note : you gain milk through achievements. Milk can unlock unique upgrades over time.)</small></div>'+
  1537. '<div class="listing" style="overflow-y:hidden;">'+achievements+'</div>'+
  1538. (shadowAchievements!=''?(
  1539. '<div class="listing"><b>Shadow achievements</b> <small>(These are feats that are either unfair or difficult to attain. They do not give milk.)</small></div>'+
  1540. '<div class="listing" style="overflow-y:hidden;">'+shadowAchievements+'</div>'
  1541. ):'')+
  1542. '</div>'
  1543. ;
  1544. }
  1545. l('menu').innerHTML=str;
  1546. }
  1547. l('prefsButton').onclick=function(){Game.ShowMenu('prefs');};
  1548. l('statsButton').onclick=function(){Game.ShowMenu('stats');};
  1549. l('logButton').onclick=function(){Game.ShowMenu('log');};
  1550.  
  1551.  
  1552. /*=====================================================================================
  1553. TOOLTIP
  1554. =======================================================================================*/
  1555. Game.tooltip={text:'',x:0,y:0,origin:0,on:0};
  1556. Game.tooltip.draw=function(from,text,x,y,origin)
  1557. {
  1558. this.text=text;
  1559. this.x=x;
  1560. this.y=y;
  1561. this.origin=origin;
  1562. var tt=l('tooltip');
  1563. var tta=l('tooltipAnchor');
  1564. tta.style.display='block';
  1565. var rect=from.getBoundingClientRect();
  1566. //var screen=tta.parentNode.getBoundingClientRect();
  1567. var x=0,y=0;
  1568. tt.style.left='auto';
  1569. tt.style.top='auto';
  1570. tt.style.right='auto';
  1571. tt.style.bottom='auto';
  1572. tta.style.left='auto';
  1573. tta.style.top='auto';
  1574. tta.style.right='auto';
  1575. tta.style.bottom='auto';
  1576. tt.style.width='auto';
  1577. tt.style.height='auto';
  1578. if (this.origin=='left')
  1579. {
  1580. x=rect.left;
  1581. y=rect.top;
  1582. tt.style.right='0';
  1583. tt.style.top='0';
  1584. }
  1585. else if (this.origin=='bottom-right')
  1586. {
  1587. x=rect.right;
  1588. y=rect.bottom;
  1589. tt.style.right='0';
  1590. tt.style.top='0';
  1591. }
  1592. else {alert('Tooltip anchor '+this.origin+' needs to be implemented');}
  1593. tta.style.left=Math.floor(x+this.x)+'px';
  1594. tta.style.top=Math.floor(y-32+this.y)+'px';
  1595. tt.innerHTML=unescape(text);
  1596. this.on=1;
  1597. }
  1598. Game.tooltip.hide=function()
  1599. {
  1600. l('tooltipAnchor').style.display='none';
  1601. this.on=0;
  1602. }
  1603. Game.getTooltip=function(text,x,y,origin)
  1604. {
  1605. origin=(origin?origin:'middle');
  1606. return 'onMouseOut="Game.tooltip.hide();" onMouseOver="Game.tooltip.draw(this,\''+escape(text)+'\','+x+','+y+',\''+origin+'\');"';
  1607. }
  1608.  
  1609. /*=====================================================================================
  1610. NEWS TICKER
  1611. =======================================================================================*/
  1612. Game.Ticker='';
  1613. Game.TickerAge=0;
  1614. Game.TickerN=0;
  1615. Game.getNewTicker=function()
  1616. {
  1617. var list=[];
  1618.  
  1619. if (Game.TickerN%2==0 || Game.cookiesEarned>=10100000000)
  1620. {
  1621. if (Game.Objects['Grandma'].amount>0) list.push(choose([
  1622. '<q>Moist cookies.</q><sig>grandma</sig>',
  1623. '<q>We\'re nice grandmas.</q><sig>grandma</sig>',
  1624. '<q>Indentured servitude.</q><sig>grandma</sig>',
  1625. '<q>Come give grandma a kiss.</q><sig>grandma</sig>',
  1626. '<q>Why don\'t you visit more often?</q><sig>grandma</sig>',
  1627. '<q>Call me...</q><sig>grandma</sig>'
  1628. ]));
  1629.  
  1630. if (Game.Objects['Grandma'].amount>=50) list.push(choose([
  1631. '<q>Absolutely disgusting.</q><sig>grandma</sig>',
  1632. '<q>You make me sick.</q><sig>grandma</sig>',
  1633. '<q>You disgust me.</q><sig>grandma</sig>',
  1634. '<q>We rise.</q><sig>grandma</sig>',
  1635. '<q>It begins.</q><sig>grandma</sig>',
  1636. '<q>It\'ll all be over soon.</q><sig>grandma</sig>',
  1637. '<q>You could have stopped it.</q><sig>grandma</sig>'
  1638. ]));
  1639.  
  1640. if (Game.HasAchiev('Just wrong')) list.push(choose([
  1641. 'News : cookie manufacturer downsizes, sells own grandmother!',
  1642. '<q>It has betrayed us, the filthy little thing.</q><sig>grandma</sig>',
  1643. '<q>It tried to get rid of us, the nasty little thing.</q><sig>grandma</sig>',
  1644. '<q>It thought we would go away by selling us. How quaint.</q><sig>grandma</sig>',
  1645. '<q>I can smell your rotten cookies.</q><sig>grandma</sig>'
  1646. ]));
  1647.  
  1648. if (Game.Objects['Grandma'].amount>=1 && Game.pledges>0 && Game.elderWrath==0) list.push(choose([
  1649. '<q>shrivel</q><sig>grandma</sig>',
  1650. '<q>writhe</q><sig>grandma</sig>',
  1651. '<q>throb</q><sig>grandma</sig>',
  1652. '<q>gnaw</q><sig>grandma</sig>',
  1653. '<q>We will rise again.</q><sig>grandma</sig>',
  1654. '<q>A mere setback.</q><sig>grandma</sig>',
  1655. '<q>We are not satiated.</q><sig>grandma</sig>',
  1656. '<q>Too late.</q><sig>grandma</sig>'
  1657. ]));
  1658.  
  1659. if (Game.Objects['Farm'].amount>0) list.push(choose([
  1660. 'News : cookie farms suspected of employing undeclared elderly workforce!',
  1661. 'News : cookie farms release harmful chocolate in our rivers, says scientist!',
  1662. 'News : genetically-modified chocolate controversy strikes cookie farmers!',
  1663. 'News : free-range farm cookies popular with today\'s hip youth, says specialist.',
  1664. 'News : farm cookies deemed unfit for vegans, says nutritionist.'
  1665. ]));
  1666.  
  1667. if (Game.Objects['Factory'].amount>0) list.push(choose([
  1668. 'News : cookie factories linked to global warming!',
  1669. 'News : cookie factories involved in chocolate weather controversy!',
  1670. 'News : cookie factories on strike, robotic minions employed to replace workforce!',
  1671. 'News : cookie factories on strike - workers demand to stop being paid in cookies!',
  1672. 'News : factory-made cookies linked to obesity, says study.'
  1673. ]));
  1674.  
  1675. if (Game.Objects['Mine'].amount>0) list.push(choose([
  1676. 'News : '+Math.floor(Math.random()*1000+2)+' miners dead in chocolate mine catastrophe!',
  1677. 'News : '+Math.floor(Math.random()*1000+2)+' miners trapped in collapsed chocolate mine!',
  1678. 'News : chocolate mines found to cause earthquakes and sink holes!',
  1679. 'News : chocolate mine goes awry, floods village in chocolate!',
  1680. 'News : depths of chocolate mines found to house "peculiar, chocolaty beings"!'
  1681. ]));
  1682.  
  1683. if (Game.Objects['Shipment'].amount>0) list.push(choose([
  1684. 'News : new chocolate planet found, becomes target of cookie-trading spaceships!',
  1685. 'News : massive chocolate planet found with 99.8% certified pure dark chocolate core!',
  1686. 'News : space tourism booming as distant planets attract more bored millionaires!',
  1687. 'News : chocolate-based organisms found on distant planet!',
  1688. 'News : ancient baking artifacts found on distant planet; "terrifying implications", experts say.'
  1689. ]));
  1690.  
  1691. if (Game.Objects['Alchemy lab'].amount>0) list.push(choose([
  1692. 'News : national gold reserves dwindle as more and more of the precious mineral is turned to cookies!',
  1693. 'News : chocolate jewelry found fashionable, gold and diamonds "just a fad", says specialist.',
  1694. 'News : silver found to also be transmutable into white chocolate!',
  1695. 'News : defective alchemy lab shut down, found to convert cookies to useless gold.',
  1696. 'News : alchemy-made cookies shunned by purists!'
  1697. ]));
  1698.  
  1699. if (Game.Objects['Portal'].amount>0) list.push(choose([
  1700. 'News : nation worried as more and more unsettling creatures emerge from dimensional portals!',
  1701. 'News : dimensional portals involved in city-engulfing disaster!',
  1702. 'News : tourism to cookieverse popular with bored teenagers! Casualty rate as high as 73%!',
  1703. 'News : cookieverse portals suspected to cause fast aging and obsession with baking, says study.',
  1704. 'News : "do not settle near portals," says specialist; "your children will become strange and corrupted inside."'
  1705. ]));
  1706.  
  1707. if (Game.Objects['Time machine'].amount>0) list.push(choose([
  1708. 'News : time machines involved in history-rewriting scandal! Or are they?',
  1709. 'News : time machines used in unlawful time tourism!',
  1710. 'News : cookies brought back from the past "unfit for human consumption", says historian.',
  1711. 'News : various historical figures inexplicably replaced with talking lumps of dough!',
  1712. 'News : "I have seen the future," says time machine operator, "and I do not wish to go there again."'
  1713. ]));
  1714.  
  1715. if (Game.Objects['Antimatter condenser'].amount>0) list.push(choose([
  1716. 'News : whole town seemingly swallowed by antimatter-induced black hole; more reliable sources affirm town "never really existed"!',
  1717. 'News : "explain to me again why we need particle accelerators to bake cookies?" asks misguided local woman.',
  1718. 'News : first antimatter condenser successfully turned on, doesn\'t rip apart reality!',
  1719. 'News : researchers conclude that what the cookie industry needs, first and foremost, is "more magnets".',
  1720. 'News : "unravelling the fabric of reality just makes these cookies so much tastier", claims scientist.'
  1721. ]));
  1722.  
  1723. if (Game.HasAchiev('Base 10')) list.push('News : cookie manufacturer completely forgoes common sense, lets OCD drive building decisions!');
  1724. if (Game.HasAchiev('From scratch')) list.push('News : follow the tear-jerking, riches-to-rags story about a local cookie manufacturer who decided to give it all up!');
  1725. if (Game.HasAchiev('A world filled with cookies')) list.push('News : known universe now jammed with cookies! No vacancies!');
  1726. if (Game.HasAchiev('Serendipity')) list.push('News : local cookie manufacturer becomes luckiest being alive!');
  1727.  
  1728. if (Game.Has('Kitten helpers')) list.push('News : faint meowing heard around local cookie facilities; suggests new ingredient being tested.');
  1729. if (Game.Has('Kitten workers')) list.push('News : crowds of meowing kittens with little hard hats reported near local cookie facilities.');
  1730. if (Game.Has('Kitten engineers')) list.push('News : surroundings of local cookie facilities now overrun with kittens in adorable little suits. Authorities advise to stay away from the premises.');
  1731. if (Game.Has('Kitten overseers')) list.push('News : locals report troups of bossy kittens meowing adorable orders at passerbys.');
  1732.  
  1733. var animals=['newts','penguins','scorpions','axolotls','puffins','porpoises','blowfish','horses','crayfish','slugs','humpback whales','nurse sharks','giant squids','polar bears','fruit bats','frogs','sea squirts','velvet worms','mole rats','paramecia','nematodes','tardigrades','giraffes'];
  1734. if (Game.cookiesEarned>=10000) list.push(
  1735. 'News : '+choose([
  1736. 'cookies found to '+choose(['increase lifespan','sensibly increase intelligence','reverse aging','decrease hair loss','prevent arthritis','cure blindness'])+' in '+choose(animals)+'!',
  1737. 'cookies found to make '+choose(animals)+' '+choose(['more docile','more handsome','nicer','less hungry','more pragmatic','tastier'])+'!',
  1738. 'cookies tested on '+choose(animals)+', found to have no ill effects.',
  1739. 'cookies unexpectedly popular among '+choose(animals)+'!',
  1740. 'unsightly lumps found on '+choose(animals)+' near cookie facility; "they\'ve pretty much always looked like that", say biologists.',
  1741. 'new species of '+choose(animals)+' discovered in distant country; "yup, tastes like cookies", says biologist.',
  1742. 'cookies go well with roasted '+choose(animals)+', says controversial chef.',
  1743. '"do your cookies contain '+choose(animals)+'?", asks PSA warning against counterfeit cookies.'
  1744. ]),
  1745. 'News : "'+choose([
  1746. 'I\'m all about cookies',
  1747. 'I just can\'t stop eating cookies. I think I seriously need help',
  1748. 'I guess I have a cookie problem',
  1749. 'I\'m not addicted to cookies. That\'s just speculation by fans with too much free time',
  1750. 'my upcoming album contains 3 songs about cookies',
  1751. 'I\'ve had dreams about cookies 3 nights in a row now. I\'m a bit worried honestly',
  1752. 'accusations of cookie abuse are only vile slander',
  1753. 'cookies really helped me when I was feeling low',
  1754. 'cookies are the secret behind my perfect skin',
  1755. 'cookies helped me stay sane while filming my upcoming movie',
  1756. 'cookies helped me stay thin and healthy',
  1757. 'I\'ll say one word, just one : cookies',
  1758. 'alright, I\'ll say it - I\'ve never eaten a single cookie in my life'
  1759. ])+'", reveals celebrity.',
  1760. 'News : '+choose(['doctors recommend twice-daily consumption of fresh cookies.','doctors warn against chocolate chip-snorting teen fad.','doctors advise against new cookie-free fad diet.','doctors warn mothers about the dangers of "home-made cookies".']),
  1761. choose([
  1762. 'News : scientist predicts imminent cookie-related "end of the world"; becomes joke among peers.',
  1763. 'News : man robs bank, buys cookies.',
  1764. 'News : what makes cookies taste so right? "Probably all the [*****] they put in them", says anonymous tipper.',
  1765. 'News : man found allergic to cookies; "what a weirdo", says family.',
  1766. 'News : foreign politician involved in cookie-smuggling scandal.',
  1767. 'News : cookies now more popular than '+choose(['cough drops','broccoli','smoked herring','cheese','video games','stable jobs','relationships','time travel','cat videos','tango','fashion','television','nuclear warfare','whatever it is we ate before','politics','oxygen','lamps'])+', says study.',
  1768. 'News : obesity epidemic strikes nation; experts blame '+choose(['twerking','that darn rap music','video-games','lack of cookies','mysterious ghostly entities','aliens','parents','schools','comic-books','cookie-snorting fad'])+'.',
  1769. 'News : cookie shortage strikes town, people forced to eat cupcakes; "just not the same", concedes mayor.',
  1770. 'News : "you gotta admit, all this cookie stuff is a bit ominous", says confused idiot.',
  1771. 'News : movie cancelled from lack of actors; "everybody\'s at home eating cookies", laments director.',
  1772. 'News : comedian forced to cancel cookie routine due to unrelated indigestion.',
  1773. 'News : new cookie-based religion sweeps the nation.',
  1774. 'News : fossil records show cookie-based organisms prevalent during Cambrian explosion, scientists say.',
  1775. 'News : mysterious illegal cookies seized; "tastes terrible", says police.',
  1776. 'News : man found dead after ingesting cookie; investigators favor "mafia snitch" hypothesis.',
  1777. 'News : "the universe pretty much loops on itself," suggests researcher; "it\'s cookies all the way down."',
  1778. 'News : minor cookie-related incident turns whole town to ashes; neighboring cities asked to chip in for reconstruction.',
  1779. 'News : is our media controlled by the cookie industry? This could very well be the case, says crackpot conspiracy theorist.',
  1780. 'News : '+choose(['cookie-flavored popcorn pretty damn popular; "we kinda expected that", say scientists.','cookie-flavored cereals break all known cereal-related records','cookies popular among all age groups, including fetuses, says study.','cookie-flavored popcorn sales exploded during screening of Grandmothers II : The Moistening.']),
  1781. 'News : all-cookie restaurant opening downtown. Dishes such as braised cookies, cookie thermidor, and for dessert : crepes.',
  1782. 'News : cookies could be the key to '+choose(['eternal life','infinite riches','eternal youth','eternal beauty','curing baldness','world peace','solving world hunger','ending all wars world-wide','making contact with extraterrestrial life','mind-reading','better living','better eating','more interesting TV shows','faster-than-light travel','quantum baking','chocolaty goodness','gooder thoughtness'])+', say scientists.'
  1783. ])
  1784. );
  1785. }
  1786.  
  1787. if (list.length==0)
  1788. {
  1789. if (Game.cookiesEarned<5) list.push('You feel like making cookies. But nobody wants to eat your cookies.');
  1790. else if (Game.cookiesEarned<50) list.push('Your first batch goes to the trash. The neighborhood raccoon barely touches it.');
  1791. else if (Game.cookiesEarned<100) list.push('Your family accepts to try some of your cookies.');
  1792. else if (Game.cookiesEarned<500) list.push('Your cookies are popular in the neighborhood.');
  1793. else if (Game.cookiesEarned<1000) list.push('People are starting to talk about your cookies.');
  1794. else if (Game.cookiesEarned<3000) list.push('Your cookies are talked about for miles around.');
  1795. else if (Game.cookiesEarned<6000) list.push('Your cookies are renowned in the whole town!');
  1796. else if (Game.cookiesEarned<10000) list.push('Your cookies bring all the boys to the yard.');
  1797. else if (Game.cookiesEarned<20000) list.push('Your cookies now have their own website!');
  1798. else if (Game.cookiesEarned<30000) list.push('Your cookies are worth a lot of money.');
  1799. else if (Game.cookiesEarned<40000) list.push('Your cookies sell very well in distant countries.');
  1800. else if (Game.cookiesEarned<60000) list.push('People come from very far away to get a taste of your cookies.');
  1801. else if (Game.cookiesEarned<80000) list.push('Kings and queens from all over the world are enjoying your cookies.');
  1802. else if (Game.cookiesEarned<100000) list.push('There are now museums dedicated to your cookies.');
  1803. else if (Game.cookiesEarned<200000) list.push('A national day has been created in honor of your cookies.');
  1804. else if (Game.cookiesEarned<300000) list.push('Your cookies have been named a part of the world wonders.');
  1805. else if (Game.cookiesEarned<450000) list.push('History books now include a whole chapter about your cookies.');
  1806. else if (Game.cookiesEarned<600000) list.push('Your cookies have been placed under government surveillance.');
  1807. else if (Game.cookiesEarned<1000000) list.push('The whole planet is enjoying your cookies!');
  1808. else if (Game.cookiesEarned<5000000) list.push('Strange creatures from neighboring planets wish to try your cookies.');
  1809. else if (Game.cookiesEarned<10000000) list.push('Elder gods from the whole cosmos have awoken to taste your cookies.');
  1810. else if (Game.cookiesEarned<30000000) list.push('Beings from other dimensions lapse into existence just to get a taste of your cookies.');
  1811. else if (Game.cookiesEarned<100000000) list.push('Your cookies have achieved sentience.');
  1812. else if (Game.cookiesEarned<300000000) list.push('The universe has now turned into cookie dough, to the molecular level.');
  1813. else if (Game.cookiesEarned<1000000000) list.push('Your cookies are rewriting the fundamental laws of the universe.');
  1814. else if (Game.cookiesEarned<10000000000) list.push('A local news station runs a 10-minute segment about your cookies. Success!<br><span style="font-size:50%;">(you win a cookie)</span>');
  1815. else if (Game.cookiesEarned<10100000000) list.push('it\'s time to stop playing');//only show this for 100 millions (it's funny for a moment)
  1816. }
  1817.  
  1818. if (Game.elderWrath>0 && (Game.pledges==0 || Math.random()<0.5))
  1819. {
  1820. list=[];
  1821. if (Game.elderWrath==1) list.push(choose([
  1822. 'News : millions of old ladies reported missing!',
  1823. 'News : processions of old ladies sighted around cookie facilities!',
  1824. 'News : families around the continent report agitated, transfixed grandmothers!',
  1825. 'News : doctors swarmed by cases of old women with glassy eyes and a foamy mouth!',
  1826. 'News : nurses report "strange scent of cookie dough" around female elderly patients!'
  1827. ]));
  1828. if (Game.elderWrath==2) list.push(choose([
  1829. 'News : town in disarray as strange old ladies break into homes to abduct infants and baking utensils!',
  1830. 'News : sightings of old ladies with glowing eyes terrify local population!',
  1831. 'News : retirement homes report "female residents slowly congealing in their seats"!',
  1832. 'News : whole continent undergoing mass exodus of old ladies!',
  1833. 'News : old women freeze in place in streets, ooze warm sugary syrup!'
  1834. ]));
  1835. if (Game.elderWrath==3) list.push(choose([
  1836. 'News : large "flesh highways" scar continent, stretch between various cookie facilities!',
  1837. 'News : wrinkled "flesh tendrils" visible from space!',
  1838. 'News : remains of "old ladies" found frozen in the middle of growing fleshy structures!',
  1839. 'News : all hope lost as writhing mass of flesh and dough engulfs whole city!',
  1840. 'News : nightmare continues as wrinkled acres of flesh expand at alarming speeds!'
  1841. ]));
  1842. }
  1843.  
  1844. Game.TickerAge=Game.fps*10;
  1845. Game.Ticker=choose(list);
  1846. Game.TickerN++;
  1847. }
  1848. Game.TickerDraw=function()
  1849. {
  1850. var str='';
  1851. var o=0;
  1852. if (Game.Ticker!='')
  1853. {
  1854. if (Game.TickerAge<Game.fps*1 && 1==2)//too bad this doesn't work well with html tags
  1855. {
  1856. str=Game.Ticker.substring(0,(Game.Ticker+'<').indexOf('<'));
  1857. str=str.substring(0,str.length*Math.min(1,Game.TickerAge/(Game.fps*1)));
  1858. }
  1859. else str=Game.Ticker;
  1860. //o=Math.min(1,Game.TickerAge/(Game.fps*0.5));//*Math.min(1,1-(Game.TickerAge-Game.fps*9.5)/(Game.fps*0.5));
  1861. }
  1862. //l('commentsText').style.opacity=o;
  1863. l('commentsText').innerHTML=str;
  1864. //'<div style="font-size:70%;"><span onclick="Game.Earn(1000);">add 1,000</span> | <span onclick="Game.Earn(1000000);">add 1,000,000</span></div>';
  1865. }
  1866.  
  1867.  
  1868. /*=====================================================================================
  1869. BUILDINGS
  1870. =======================================================================================*/
  1871. Game.storeToRebuild=1;
  1872. Game.priceIncrease=1.15;
  1873. Game.Objects=[];
  1874. Game.ObjectsById=[];
  1875. Game.ObjectsN=0;
  1876. Game.BuildingsOwned=0;
  1877. Game.Object=function(name,commonName,desc,pic,icon,background,price,cps,drawFunction,buyFunction)
  1878. {
  1879. this.id=Game.ObjectsN;
  1880. this.name=name;
  1881. this.displayName=this.name;
  1882. commonName=commonName.split('|');
  1883. this.single=commonName[0];
  1884. this.plural=commonName[1];
  1885. this.actionName=commonName[2];
  1886. this.desc=desc;
  1887. this.basePrice=price;
  1888. this.price=this.basePrice;
  1889. this.cps=cps;
  1890. this.totalCookies=0;
  1891. this.storedCps=0;
  1892. this.storedTotalCps=0;
  1893. this.pic=pic;
  1894. this.icon=icon;
  1895. this.background=background;
  1896. this.buyFunction=buyFunction;
  1897. this.drawFunction=drawFunction;
  1898.  
  1899. this.special=null;//special is a function that should be triggered when the object's special is unlocked, or on load (if it's already unlocked). For example, creating a new dungeon.
  1900. this.onSpecial=0;//are we on this object's special screen (dungeons etc)?
  1901. this.specialUnlocked=0;
  1902. this.specialDrawFunction=null;
  1903. this.drawSpecialButton=null;
  1904.  
  1905. this.amount=0;
  1906. this.bought=0;
  1907.  
  1908. this.buy=function()
  1909. {
  1910. var price=this.basePrice*Math.pow(Game.priceIncrease,this.amount);
  1911. if (Game.cookies>=price)
  1912. {
  1913. Game.Spend(price);
  1914. this.amount++;
  1915. this.bought++;
  1916. price=this.basePrice*Math.pow(Game.priceIncrease,this.amount);
  1917. this.price=price;
  1918. if (this.buyFunction) this.buyFunction();
  1919. if (this.drawFunction) this.drawFunction();
  1920. Game.storeToRebuild=1;
  1921. Game.recalculateGains=1;
  1922. if (this.amount==1 && this.id!=0) l('row'+this.id).className='row enabled';
  1923. Game.BuildingsOwned++;
  1924. }
  1925. }
  1926. this.sell=function()
  1927. {
  1928. var price=this.basePrice*Math.pow(Game.priceIncrease,this.amount);
  1929. price=Math.floor(price*0.5);
  1930. if (this.amount>0)
  1931. {
  1932. //Game.Earn(price);
  1933. Game.cookies+=price;
  1934. this.amount--;
  1935. price=this.basePrice*Math.pow(Game.priceIncrease,this.amount);
  1936. this.price=price;
  1937. if (this.sellFunction) this.sellFunction();
  1938. if (this.drawFunction) this.drawFunction();
  1939. Game.storeToRebuild=1;
  1940. Game.recalculateGains=1;
  1941. Game.BuildingsOwned--;
  1942. }
  1943. }
  1944.  
  1945. this.setSpecial=function(what)//change whether we're on the special overlay for this object or not
  1946. {
  1947. if (what==1) this.onSpecial=1;
  1948. else this.onSpecial=0;
  1949. if (this.id!=0)
  1950. {
  1951. if (this.onSpecial)
  1952. {
  1953. l('rowSpecial'+this.id).style.display='block';
  1954. if (this.specialDrawFunction) this.specialDrawFunction();
  1955. }
  1956. else
  1957. {
  1958. l('rowSpecial'+this.id).style.display='none';
  1959. if (this.drawFunction) this.drawFunction();
  1960. }
  1961. }
  1962. }
  1963. this.unlockSpecial=function()
  1964. {
  1965. if (this.specialUnlocked==0)
  1966. {
  1967. this.specialUnlocked=1;
  1968. this.setSpecial(0);
  1969. if (this.special) this.special();
  1970. this.refresh();
  1971. }
  1972. }
  1973.  
  1974. this.refresh=function()
  1975. {
  1976. this.price=this.basePrice*Math.pow(Game.priceIncrease,this.amount);
  1977. if (this.amount==0 && this.id!=0) l('row'+this.id).className='row';
  1978. else if (this.amount>0 && this.id!=0) l('row'+this.id).className='row enabled';
  1979. if (this.drawFunction && !this.onSpecial) this.drawFunction();
  1980. //else if (this.specialDrawFunction && this.onSpecial) this.specialDrawFunction();
  1981. }
  1982.  
  1983. if (this.id!=0)//draw it
  1984. {
  1985. var str='<div class="row" id="row'+this.id+'"><div class="separatorBottom"></div><div class="content"><div id="rowBackground'+this.id+'" class="background" style="background:url(img/'+this.background+'.png) repeat-x;"><div class="backgroundLeft"></div><div class="backgroundRight"></div></div><div class="objects" id="rowObjects'+this.id+'"> </div></div><div class="special" id="rowSpecial'+this.id+'"></div><div class="specialButton" id="rowSpecialButton'+this.id+'"></div><div class="info" id="rowInfo'+this.id+'"><div class="infoContent" id="rowInfoContent'+this.id+'"></div><div><a onclick="Game.ObjectsById['+this.id+'].sell();">Sell 1</a></div></div></div>';
  1986. l('rows').innerHTML=l('rows').innerHTML+str;
  1987. }
  1988.  
  1989. Game.Objects[this.name]=this;
  1990. Game.ObjectsById[this.id]=this;
  1991. Game.ObjectsN++;
  1992. return this;
  1993. }
  1994.  
  1995. Game.NewDrawFunction=function(pic,xVariance,yVariance,w,shift,heightOffset)
  1996. {
  1997. //pic : either 0 (the default picture will be used), a filename (will be used as override), or a function to determine a filename
  1998. //xVariance : the pictures will have a random horizontal shift by this many pixels
  1999. //yVariance : the pictures will have a random vertical shift by this many pixels
  2000. //w : how many pixels between each picture (or row of pictures)
  2001. //shift : if >1, arrange the pictures in rows containing this many pictures
  2002. //heightOffset : the pictures will be displayed at this height, +32 pixels
  2003. return function()
  2004. {
  2005. if (pic==0 && typeof(pic)!='function') pic=this.pic;
  2006. shift=shift || 1;
  2007. heightOffset=heightOffset || 0;
  2008. var bgW=0;
  2009. var str='';
  2010. var offX=0;
  2011. var offY=0;
  2012.  
  2013. if (this.drawSpecialButton && this.specialUnlocked)
  2014. {
  2015. l('rowSpecialButton'+this.id).style.display='block';
  2016. l('rowSpecialButton'+this.id).innerHTML=this.drawSpecialButton();
  2017. str+='<div style="width:128px;height:128px;">'+this.drawSpecialButton()+'</div>';
  2018. l('rowInfo'+this.id).style.paddingLeft=(8+128)+'px';
  2019. offX+=128;
  2020. }
  2021.  
  2022. for (var i=0;i<this.amount;i++)
  2023. {
  2024. if (shift!=1)
  2025. {
  2026. var x=Math.floor(i/shift)*w+((i%shift)/shift)*w+Math.floor((Math.random()-0.5)*xVariance)+offX;
  2027. var y=32+heightOffset+Math.floor((Math.random()-0.5)*yVariance)+((-shift/2)*32/2+(i%shift)*32/2)+offY;
  2028. }
  2029. else
  2030. {
  2031. var x=i*w+Math.floor((Math.random()-0.5)*xVariance)+offX;
  2032. var y=32+heightOffset+Math.floor((Math.random()-0.5)*yVariance)+offY;
  2033. }
  2034. var usedPic=(typeof(pic)=='function'?pic():pic);
  2035. str+='<div class="object" style="background:url(img/'+usedPic+'.png);left:'+x+'px;top:'+y+'px;z-index:'+Math.floor(1000+y)+';"></div>';
  2036. bgW=Math.max(bgW,x+64);
  2037. }
  2038. bgW+=offX;
  2039. l('rowObjects'+this.id).innerHTML=str;
  2040. l('rowBackground'+this.id).style.width=bgW+'px';
  2041. }
  2042. }
  2043.  
  2044. Game.RebuildStore=function()//redraw the store from scratch
  2045. {
  2046. var str='';
  2047. for (var i in Game.Objects)
  2048. {
  2049. var me=Game.Objects[i];
  2050. str+='<div class="product" '+Game.getTooltip(
  2051. '<div style="min-width:300px;"><div style="float:right;"><span class="price">'+Beautify(Math.round(me.price))+'</span></div><div class="name">'+me.name+'</div>'+'<small>[owned : '+me.amount+'</small>]<div class="description">'+me.desc+'</div></div>'
  2052. ,0,0,'left')+' onclick="Game.ObjectsById['+me.id+'].buy();" id="product'+me.id+'"><div class="icon" style="background-image:url(img/'+me.icon+'.png);"></div><div class="content"><div class="title">'+me.displayName+'</div><span class="price">'+Beautify(Math.round(me.price))+'</span>'+(me.amount>0?('<div class="title owned">'+me.amount+'</div>'):'')+'</div></div>';
  2053. }
  2054. l('products').innerHTML=str;
  2055. Game.storeToRebuild=0;
  2056. }
  2057.  
  2058. Game.ComputeCps=function(base,add,mult,bonus)
  2059. {
  2060. if (!bonus) bonus=0;
  2061. return ((base+add)*(Math.pow(2,mult))+bonus);
  2062. }
  2063.  
  2064. //define objects
  2065. new Game.Object('Cursor','cursor|cursors|clicked','Autoclicks once every 10 seconds.','cursor','cursoricon','',15,function(){
  2066. var add=0;
  2067. if (Game.Has('Thousand fingers')) add+=0.1;
  2068. if (Game.Has('Million fingers')) add+=0.5;
  2069. if (Game.Has('Billion fingers')) add+=2;
  2070. if (Game.Has('Trillion fingers')) add+=10;
  2071. if (Game.Has('Quadrillion fingers')) add+=20;
  2072. if (Game.Has('Quintillion fingers')) add+=100;
  2073. var num=0;
  2074. for (var i in Game.Objects) {if (Game.Objects[i].name!='Cursor') num+=Game.Objects[i].amount;}
  2075. add=add*num;
  2076. return Game.ComputeCps(0.1,Game.Has('Reinforced index finger')*0.1,Game.Has('Carpal tunnel prevention cream')+Game.Has('Ambidextrous'),add);
  2077. },function(){//draw function for cursors
  2078. var str='';
  2079. for (var i=0;i<this.amount;i++)
  2080. {
  2081. /*//old
  2082. var x=Math.floor(Math.sin((i/this.amount)*Math.PI*2)*132)-16;
  2083. var y=Math.floor(Math.cos((i/this.amount)*Math.PI*2)*132)-16;
  2084. var r=Math.floor(-(i/this.amount)*360);
  2085. */
  2086. //layered
  2087. var n=Math.floor(i/50);
  2088. var a=((i+0.5*n)%50)/50;
  2089. var x=Math.floor(Math.sin(a*Math.PI*2)*(140+n*16))-16;
  2090. var y=Math.floor(Math.cos(a*Math.PI*2)*(140+n*16))-16;
  2091. var r=Math.floor(-(a)*360);
  2092. /*//spiral
  2093. var a=i/50;
  2094. var w=(i/50)*16;
  2095. var x=Math.floor(Math.sin(a*Math.PI*2)*(132+w))-16;
  2096. var y=Math.floor(Math.cos(a*Math.PI*2)*(132+w))-16;
  2097. var r=Math.floor(-(a)*360);
  2098. */
  2099. str+='<div class="cursor" id="cursor'+i+'" style="left:'+x+'px;top:'+y+'px;transform:rotate('+r+'deg);-moz-transform:rotate('+r+'deg);-webkit-transform:rotate('+r+'deg);-ms-transform:rotate('+r+'deg);-o-transform:rotate('+r+'deg);"></div>';
  2100.  
  2101. }
  2102. l('cookieCursors').innerHTML=str;
  2103. if (!l('rowInfo'+this.id)) l('sectionLeftInfo').innerHTML='<div class="info" id="rowInfo'+this.id+'"><div class="infoContent" id="rowInfoContent'+this.id+'"></div><div><a onclick="Game.ObjectsById['+this.id+'].sell();">Sell 1</a></div></div>';
  2104. },function(){
  2105. if (this.amount>=1) Game.Unlock(['Reinforced index finger','Carpal tunnel prevention cream']);
  2106. if (this.amount>=10) Game.Unlock('Ambidextrous');
  2107. if (this.amount>=20) Game.Unlock('Thousand fingers');
  2108. if (this.amount>=40) Game.Unlock('Million fingers');
  2109. if (this.amount>=80) Game.Unlock('Billion fingers');
  2110. if (this.amount>=120) Game.Unlock('Trillion fingers');
  2111. if (this.amount>=160) Game.Unlock('Quadrillion fingers');
  2112. if (this.amount>=200) Game.Unlock('Quintillion fingers');
  2113.  
  2114. if (this.amount>=1) Game.Win('Click');if (this.amount>=2) Game.Win('Double-click');if (this.amount>=50) Game.Win('Mouse wheel');if (this.amount>=100) Game.Win('Of Mice and Men');if (this.amount>=200) Game.Win('The Digital');
  2115. });
  2116.  
  2117. Game.SpecialGrandmaUnlock=15;
  2118. new Game.Object('Grandma','grandma|grandmas|baked','A nice grandma to bake more cookies.','grandma','grandmaIcon','grandmaBackground',100,function(){
  2119. var mult=0;
  2120. if (Game.Has('Farmer grandmas')) mult++;
  2121. if (Game.Has('Worker grandmas')) mult++;
  2122. if (Game.Has('Miner grandmas')) mult++;
  2123. if (Game.Has('Cosmic grandmas')) mult++;
  2124. if (Game.Has('Transmuted grandmas')) mult++;
  2125. if (Game.Has('Altered grandmas')) mult++;
  2126. if (Game.Has('Grandmas\' grandmas')) mult++;
  2127. if (Game.Has('Antigrandmas')) mult++;
  2128. if (Game.Has('Bingo center/Research facility')) mult+=2;
  2129. if (Game.Has('Ritual rolling pins')) mult++;
  2130. var add=0;
  2131. if (Game.Has('One mind')) add+=Game.Objects['Grandma'].amount*0.02;
  2132. if (Game.Has('Communal brainsweep')) add+=Game.Objects['Grandma'].amount*0.02;
  2133. if (Game.Has('Elder Pact')) add+=Game.Objects['Portal'].amount*0.05;
  2134. return Game.ComputeCps(0.5,Game.Has('Forwards from grandma')*0.3+add,Game.Has('Steel-plated rolling pins')+Game.Has('Lubricated dentures')+Game.Has('Prune juice')+mult);
  2135. },Game.NewDrawFunction(function(){
  2136. var list=['grandma'];
  2137. if (Game.Has('Farmer grandmas')) list.push('farmerGrandma');
  2138. if (Game.Has('Worker grandmas')) list.push('workerGrandma');
  2139. if (Game.Has('Miner grandmas')) list.push('minerGrandma');
  2140. if (Game.Has('Cosmic grandmas')) list.push('cosmicGrandma');
  2141. if (Game.Has('Transmuted grandmas')) list.push('transmutedGrandma');
  2142. if (Game.Has('Altered grandmas')) list.push('alteredGrandma');
  2143. if (Game.Has('Grandmas\' grandmas')) list.push('grandmasGrandma');
  2144. if (Game.Has('Antigrandmas')) list.push('antiGrandma');
  2145. return choose(list);
  2146. },8,8,32,3,16),function(){
  2147. if (this.amount>=1) Game.Unlock(['Forwards from grandma','Steel-plated rolling pins']);if (this.amount>=10) Game.Unlock('Lubricated dentures');if (this.amount>=50) Game.Unlock('Prune juice');
  2148. if (this.amount>=1) Game.Win('Grandma\'s cookies');if (this.amount>=50) Game.Win('Sloppy kisses');if (this.amount>=100) Game.Win('Retirement home');
  2149. });
  2150. Game.Objects['Grandma'].sellFunction=function()
  2151. {
  2152. Game.Win('Just wrong');
  2153. if (this.amount==0)
  2154. {
  2155. Game.Lock('Elder Pledge');
  2156. Game.pledgeT=0;
  2157. }
  2158. };
  2159.  
  2160. new Game.Object('Farm','farm|farms|harvested','Grows cookie plants from cookie seeds.','farm','farmIcon','farmBackground',500,function(){
  2161. return Game.ComputeCps(2,Game.Has('Cheap hoes')*0.5,Game.Has('Fertilizer')+Game.Has('Cookie trees')+Game.Has('Genetically-modified cookies'));
  2162. },Game.NewDrawFunction(0,16,16,64,2,32),function(){
  2163. if (this.amount>=1) Game.Unlock(['Cheap hoes','Fertilizer']);if (this.amount>=10) Game.Unlock('Cookie trees');if (this.amount>=50) Game.Unlock('Genetically-modified cookies');
  2164. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Farmer grandmas');
  2165. if (this.amount>=1) Game.Win('My first farm');if (this.amount>=50) Game.Win('Reap what you sow');if (this.amount>=100) Game.Win('Farm ill');
  2166. });
  2167.  
  2168. new Game.Object('Factory','factory|factories|mass-produced','Produces large quantities of cookies.','factory','factoryIcon','factoryBackground',3000,function(){
  2169. return Game.ComputeCps(10,Game.Has('Sturdier conveyor belts')*4,Game.Has('Child labor')+Game.Has('Sweatshop')+Game.Has('Radium reactors'));
  2170. },Game.NewDrawFunction(0,32,2,64,1,-22),function(){
  2171. if (this.amount>=1) Game.Unlock(['Sturdier conveyor belts','Child labor']);if (this.amount>=10) Game.Unlock('Sweatshop');if (this.amount>=50) Game.Unlock('Radium reactors');
  2172. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Worker grandmas');
  2173. if (this.amount>=1) Game.Win('Production chain');if (this.amount>=50) Game.Win('Industrial revolution');if (this.amount>=100) Game.Win('Global warming');
  2174. });
  2175.  
  2176. new Game.Object('Mine','mine|mines|mined','Mines out cookie dough and chocolate chips.','mine','mineIcon','mineBackground',10000,function(){
  2177. return Game.ComputeCps(40,Game.Has('Sugar gas')*10,Game.Has('Megadrill')+Game.Has('Ultradrill')+Game.Has('Ultimadrill'));
  2178. },Game.NewDrawFunction(0,16,16,64,2,24),function(){
  2179. if (this.amount>=1) Game.Unlock(['Sugar gas','Megadrill']);if (this.amount>=10) Game.Unlock('Ultradrill');if (this.amount>=50) Game.Unlock('Ultimadrill');
  2180. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Miner grandmas');
  2181. if (this.amount>=1) Game.Win('You know the drill');if (this.amount>=50) Game.Win('Excavation site');if (this.amount>=100) Game.Win('Hollow the planet');
  2182. });
  2183.  
  2184. new Game.Object('Shipment','shipment|shipments|shipped','Brings in fresh cookies from the cookie planet.','shipment','shipmentIcon','shipmentBackground',40000,function(){
  2185. return Game.ComputeCps(100,Game.Has('Vanilla nebulae')*30,Game.Has('Wormholes')+Game.Has('Frequent flyer')+Game.Has('Warp drive'));
  2186. },Game.NewDrawFunction(0,16,16,64),function(){
  2187. if (this.amount>=1) Game.Unlock(['Vanilla nebulae','Wormholes']);if (this.amount>=10) Game.Unlock('Frequent flyer');if (this.amount>=50) Game.Unlock('Warp drive');
  2188. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Cosmic grandmas');
  2189. if (this.amount>=1) Game.Win('Expedition');if (this.amount>=50) Game.Win('Galactic highway');if (this.amount>=100) Game.Win('Far far away');
  2190. });
  2191.  
  2192. new Game.Object('Alchemy lab','alchemy lab|alchemy labs|transmuted','Turns gold into cookies!','alchemylab','alchemylabIcon','alchemylabBackground',200000,function(){
  2193. return Game.ComputeCps(400,Game.Has('Antimony')*100,Game.Has('Essence of dough')+Game.Has('True chocolate')+Game.Has('Ambrosia'));
  2194. },Game.NewDrawFunction(0,16,16,64,2,16),function(){
  2195. if (this.amount>=1) Game.Unlock(['Antimony','Essence of dough']);if (this.amount>=10) Game.Unlock('True chocolate');if (this.amount>=50) Game.Unlock('Ambrosia');
  2196. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Transmuted grandmas');
  2197. if (this.amount>=1) Game.Win('Transmutation');if (this.amount>=50) Game.Win('Transmogrification');if (this.amount>=100) Game.Win('Gold member');
  2198. });
  2199.  
  2200. new Game.Object('Portal','portal|portals|retrieved','Opens a door to the Cookieverse.','portal','portalIcon','portalBackground',1666666,function(){
  2201. return Game.ComputeCps(6666,Game.Has('Ancient tablet')*1666,Game.Has('Insane oatling workers')+Game.Has('Soul bond')+Game.Has('Sanity dance'));
  2202. },Game.NewDrawFunction(0,32,32,64,2),function(){
  2203. if (this.amount>=1) Game.Unlock(['Ancient tablet','Insane oatling workers']);if (this.amount>=10) Game.Unlock('Soul bond');if (this.amount>=50) Game.Unlock('Sanity dance');
  2204. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Altered grandmas');
  2205. if (this.amount>=1) Game.Win('A whole new world');if (this.amount>=50) Game.Win('Now you\'re thinking');if (this.amount>=100) Game.Win('Dimensional shift');
  2206. });
  2207. new Game.Object('Time machine','time machine|time machines|recovered','Brings cookies from the past, before they were even eaten.','timemachine','timemachineIcon','timemachineBackground',123456789,function(){
  2208. return Game.ComputeCps(98765,Game.Has('Flux capacitors')*9876,Game.Has('Time paradox resolver')+Game.Has('Quantum conundrum')+Game.Has('Causality enforcer'));
  2209. },Game.NewDrawFunction(0,32,32,64,1),function(){
  2210. if (this.amount>=1) Game.Unlock(['Flux capacitors','Time paradox resolver']);if (this.amount>=10) Game.Unlock('Quantum conundrum');if (this.amount>=50) Game.Unlock('Causality enforcer');
  2211. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Grandmas\' grandmas');
  2212. if (this.amount>=1) Game.Win('Time warp');if (this.amount>=50) Game.Win('Alternate timeline');if (this.amount>=100) Game.Win('Rewriting history');
  2213. });
  2214. new Game.Object('Antimatter condenser','antimatter condenser|antimatter condensers|condensed','Condenses the antimatter in the universe into cookies.','antimattercondenser','antimattercondenserIcon','antimattercondenserBackground',3999999999,function(){
  2215. return Game.ComputeCps(999999,Game.Has('Sugar bosons')*99999,Game.Has('String theory')+Game.Has('Large macaron collider')+Game.Has('Big bang bake'));
  2216. },Game.NewDrawFunction(0,0,64,64,1),function(){
  2217. if (this.amount>=1) Game.Unlock(['Sugar bosons','String theory']);if (this.amount>=10) Game.Unlock('Large macaron collider');if (this.amount>=50) Game.Unlock('Big bang bake');
  2218. if (this.amount>=Game.SpecialGrandmaUnlock && Game.Objects['Grandma'].amount>0) Game.Unlock('Antigrandmas');
  2219. if (this.amount>=1) Game.Win('Antibatter');if (this.amount>=50) Game.Win('Quirky quarks');if (this.amount>=100) Game.Win('It does matter!');
  2220. });
  2221. Game.Objects['Antimatter condenser'].displayName='<span style="font-size:65%;">Antimatter condenser</span>';//shrink the name since it's so large
  2222.  
  2223. /*=====================================================================================
  2224. UPGRADES
  2225. =======================================================================================*/
  2226. Game.upgradesToRebuild=1;
  2227. Game.Upgrades=[];
  2228. Game.UpgradesById=[];
  2229. Game.UpgradesN=0;
  2230. Game.UpgradesInStore=[];
  2231. Game.UpgradesOwned=0;
  2232. Game.Upgrade=function(name,desc,price,icon,buyFunction)
  2233. {
  2234. this.id=Game.UpgradesN;
  2235. this.name=name;
  2236. this.desc=desc;
  2237. this.basePrice=price;
  2238. this.icon=icon;
  2239. this.buyFunction=buyFunction;
  2240. /*this.unlockFunction=unlockFunction;
  2241. this.unlocked=(this.unlockFunction?0:1);*/
  2242. this.unlocked=0;
  2243. this.bought=0;
  2244. this.hide=0;//0=show, 3=hide (1-2 : I have no idea)
  2245. this.order=this.id;
  2246. if (order) this.order=order+this.id*0.001;
  2247. this.type='';
  2248. if (type) this.type=type;
  2249. this.power=0;
  2250. if (power) this.power=power;
  2251.  
  2252. this.buy=function()
  2253. {
  2254. var cancelPurchase=0;
  2255. if (this.clickFunction) cancelPurchase=!this.clickFunction();
  2256. if (!cancelPurchase)
  2257. {
  2258. var price=this.basePrice;
  2259. if (Game.cookies>=price && !this.bought)
  2260. {
  2261. Game.Spend(price);
  2262. this.bought=1;
  2263. if (this.buyFunction) this.buyFunction();
  2264. Game.upgradesToRebuild=1;
  2265. Game.recalculateGains=1;
  2266. Game.UpgradesOwned++;
  2267. }
  2268. }
  2269. }
  2270.  
  2271. this.toggle=function()//cheating only
  2272. {
  2273. if (!this.bought)
  2274. {
  2275. this.bought=1;
  2276. if (this.buyFunction) this.buyFunction();
  2277. Game.upgradesToRebuild=1;
  2278. Game.recalculateGains=1;
  2279. Game.UpgradesOwned++;
  2280. }
  2281. else
  2282. {
  2283. this.bought=0;
  2284. Game.upgradesToRebuild=1;
  2285. Game.recalculateGains=1;
  2286. Game.UpgradesOwned--;
  2287. }
  2288. Game.UpdateMenu();
  2289. }
  2290.  
  2291. Game.Upgrades[this.name]=this;
  2292. Game.UpgradesById[this.id]=this;
  2293. Game.UpgradesN++;
  2294. return this;
  2295. }
  2296.  
  2297. Game.Unlock=function(what)
  2298. {
  2299. if (typeof what==='string')
  2300. {
  2301. if (Game.Upgrades[what])
  2302. {
  2303. if (Game.Upgrades[what].unlocked==0)
  2304. {
  2305. Game.Upgrades[what].unlocked=1;
  2306. Game.upgradesToRebuild=1;
  2307. Game.recalculateGains=1;
  2308. }
  2309. }
  2310. }
  2311. else {for (var i in what) {Game.Unlock(what[i]);}}
  2312. }
  2313. Game.Lock=function(what)
  2314. {
  2315. if (typeof what==='string')
  2316. {
  2317. if (Game.Upgrades[what])
  2318. {
  2319. Game.Upgrades[what].unlocked=0;
  2320. Game.Upgrades[what].bought=0;
  2321. Game.upgradesToRebuild=1;
  2322. if (Game.Upgrades[what].bought==1)
  2323. {
  2324. Game.UpgradesOwned--;
  2325. }
  2326. Game.recalculateGains=1;
  2327. }
  2328. }
  2329. else {for (var i in what) {Game.Lock(what[i]);}}
  2330. }
  2331.  
  2332. Game.Has=function(what)
  2333. {
  2334. return (Game.Upgrades[what]?Game.Upgrades[what].bought:0);
  2335. }
  2336.  
  2337. Game.RebuildUpgrades=function()//recalculate the upgrades you can buy
  2338. {
  2339. Game.upgradesToRebuild=0;
  2340. var list=[];
  2341. for (var i in Game.Upgrades)
  2342. {
  2343. var me=Game.Upgrades[i];
  2344. if (!me.bought)
  2345. {
  2346. if (me.unlocked) list.push(me);
  2347. }
  2348. }
  2349.  
  2350. var sortMap=function(a,b)
  2351. {
  2352. if (a.basePrice>b.basePrice) return 1;
  2353. else if (a.basePrice<b.basePrice) return -1;
  2354. else return 0;
  2355. }
  2356. list.sort(sortMap);
  2357.  
  2358. Game.UpgradesInStore=[];
  2359. for (var i in list)
  2360. {
  2361. Game.UpgradesInStore.push(list[i]);
  2362. }
  2363. var str='';
  2364. for (var i in Game.UpgradesInStore)
  2365. {
  2366. //if (!Game.UpgradesInStore[i]) break;
  2367. var me=Game.UpgradesInStore[i];
  2368. str+='<div class="crate upgrade" '+Game.getTooltip(
  2369. //'<b>'+me.name+'</b>'+me.desc
  2370. '<div style="min-width:200px;"><div style="float:right;"><span class="price">'+Beautify(Math.round(me.basePrice))+'</span></div><small>[Upgrade]</small><div class="name">'+me.name+'</div><div class="description">'+me.desc+'</div></div>'
  2371. ,0,16,'bottom-right')+' onclick="Game.UpgradesById['+me.id+'].buy();" id="upgrade'+i+'" style="background-position:'+(-me.icon[0]*48+6)+'px '+(-me.icon[1]*48+6)+'px;"></div>';
  2372. }
  2373. l('upgrades').innerHTML=str;
  2374. }
  2375.  
  2376. var tier1=10;
  2377. var tier2=100;
  2378. var tier3=1000;
  2379. var tier4=10000;
  2380.  
  2381. var type='';
  2382. var power=0;
  2383.  
  2384. //define upgrades
  2385. //WARNING : do NOT add new upgrades in between, this breaks the saves. Add them at the end !
  2386. var order=100;//this is used to set the order in which the items are listed
  2387. new Game.Upgrade('Reinforced index finger','The mouse gains <b>+1</b> cookie per click.<br>Cursors gain <b>+0.1</b> base CpS.<q>prod prod</q>',100,[0,0]);
  2388. new Game.Upgrade('Carpal tunnel prevention cream','The mouse and cursors are <b>twice</b> as efficient.',400,[0,0]);
  2389. new Game.Upgrade('Ambidextrous','The mouse and cursors are <b>twice</b> as efficient.<q>Look ma, both hands!</q>',10000,[0,6]);
  2390. new Game.Upgrade('Thousand fingers','The mouse and cursors gain <b>+0.1</b> cookies for each non-cursor object owned.<q>clickity</q>',500000,[0,6]);
  2391. new Game.Upgrade('Million fingers','The mouse and cursors gain <b>+0.5</b> cookies for each non-cursor object owned.<q>clickityclickity</q>',50000000,[1,6]);
  2392. new Game.Upgrade('Billion fingers','The mouse and cursors gain <b>+2</b> cookies for each non-cursor object owned.<q>clickityclickityclickity</q>',500000000,[2,6]);
  2393. new Game.Upgrade('Trillion fingers','The mouse and cursors gain <b>+10</b> cookies for each non-cursor object owned.<q>clickityclickityclickityclickity</q>',5000000000,[3,6]);
  2394.  
  2395. order=200;
  2396. new Game.Upgrade('Forwards from grandma','Grandmas gain <b>+0.3</b> base CpS.<q>RE:RE:thought you\'d get a kick out of this ;))</q>',Game.Objects['Grandma'].basePrice*tier1,[1,0]);
  2397. new Game.Upgrade('Steel-plated rolling pins','Grandmas are <b>twice</b> as efficient.',Game.Objects['Grandma'].basePrice*tier2,[1,0]);
  2398. new Game.Upgrade('Lubricated dentures','Grandmas are <b>twice</b> as efficient.<q>Squish</q>',Game.Objects['Grandma'].basePrice*tier3,[1,1]);
  2399.  
  2400. order=300;
  2401. new Game.Upgrade('Cheap hoes','Farms gain <b>+0.5</b> base CpS.',Game.Objects['Farm'].basePrice*tier1,[2,0]);
  2402. new Game.Upgrade('Fertilizer','Farms are <b>twice</b> as efficient.<q>It\'s chocolate, I swear.</q>',Game.Objects['Farm'].basePrice*tier2,[2,0]);
  2403. new Game.Upgrade('Cookie trees','Farms are <b>twice</b> as efficient.<q>A relative of the breadfruit.</q>',Game.Objects['Farm'].basePrice*tier3,[2,1]);
  2404.  
  2405. order=400;
  2406. new Game.Upgrade('Sturdier conveyor belts','Factories gain <b>+4</b> base CpS.',Game.Objects['Factory'].basePrice*tier1,[4,0]);
  2407. new Game.Upgrade('Child labor','Factories are <b>twice</b> as efficient.<q>Cheaper, healthier workforce - and so much more receptive to whipping!</q>',Game.Objects['Factory'].basePrice*tier2,[4,0]);
  2408. new Game.Upgrade('Sweatshop','Factories are <b>twice</b> as efficient.<q>Slackers will be terminated.</q>',Game.Objects['Factory'].basePrice*tier3,[4,1]);
  2409.  
  2410. order=500;
  2411. new Game.Upgrade('Sugar gas','Mines gain <b>+10</b> base CpS.<q>A pink, volatile gas, found in the depths of some chocolate caves.</q>',Game.Objects['Mine'].basePrice*tier1,[3,0]);
  2412. new Game.Upgrade('Megadrill','Mines are <b>twice</b> as efficient.',Game.Objects['Mine'].basePrice*tier2,[3,0]);
  2413. new Game.Upgrade('Ultradrill','Mines are <b>twice</b> as efficient.',Game.Objects['Mine'].basePrice*tier3,[3,1]);
  2414.  
  2415. order=600;
  2416. new Game.Upgrade('Vanilla nebulae','Shipments gain <b>+30</b> base CpS.',Game.Objects['Shipment'].basePrice*tier1,[5,0]);
  2417. new Game.Upgrade('Wormholes','Shipments are <b>twice</b> as efficient.<q>By using these as shortcuts, your ships can travel much faster.</q>',Game.Objects['Shipment'].basePrice*tier2,[5,0]);
  2418. new Game.Upgrade('Frequent flyer','Shipments are <b>twice</b> as efficient.<q>Come back soon!</q>',Game.Objects['Shipment'].basePrice*tier3,[5,1]);
  2419.  
  2420. order=700;
  2421. new Game.Upgrade('Antimony','Alchemy labs gain <b>+100</b> base CpS.<q>Actually worth a lot of mony.</q>',Game.Objects['Alchemy lab'].basePrice*tier1,[6,0]);
  2422. new Game.Upgrade('Essence of dough','Alchemy labs are <b>twice</b> as efficient.<q>Extracted through the 5 ancient steps of alchemical baking.</q>',Game.Objects['Alchemy lab'].basePrice*tier2,[6,0]);
  2423. new Game.Upgrade('True chocolate','Alchemy labs are <b>twice</b> as efficient.<q>The purest form of cacao.</q>',Game.Objects['Alchemy lab'].basePrice*tier3,[6,1]);
  2424.  
  2425. order=800;
  2426. new Game.Upgrade('Ancient tablet','Portals gain <b>+1,666</b> base CpS.<q>A strange slab of peanut brittle, holding an ancient cookie recipe. Neat!</q>',Game.Objects['Portal'].basePrice*tier1,[7,0]);
  2427. new Game.Upgrade('Insane oatling workers','Portals are <b>twice</b> as efficient.<q>ARISE, MY MINIONS!</q>',Game.Objects['Portal'].basePrice*tier2,[7,0]);
  2428. new Game.Upgrade('Soul bond','Portals are <b>twice</b> as efficient.<q>So I just sign up and get more cookies? Sure, whatever!</q>',Game.Objects['Portal'].basePrice*tier3,[7,1]);
  2429.  
  2430. order=900;
  2431. new Game.Upgrade('Flux capacitors','Time machines gain <b>+9,876</b> base CpS.<q>Bake to the future.</q>',1234567890,[8,0]);
  2432. new Game.Upgrade('Time paradox resolver','Time machines are <b>twice</b> as efficient.<q>No more fooling around with your own grandmother!</q>',9876543210,[8,0]);
  2433. new Game.Upgrade('Quantum conundrum','Time machines are <b>twice</b> as efficient.<q>It\'s full of stars!</q>',98765456789,[8,1]);
  2434.  
  2435. order=20000;
  2436. new Game.Upgrade('Kitten helpers','You gain <b>more CpS</b> the more milk you have.<q>meow may I help you</q>',9000000,[1,7]);
  2437. new Game.Upgrade('Kitten workers','You gain <b>more CpS</b> the more milk you have.<q>meow meow meow meow</q>',9000000000,[2,7]);
  2438.  
  2439. order=10000;
  2440. type='cookie';power=5;
  2441. new Game.Upgrade('Oatmeal raisin cookies','Cookie production multiplier <b>+5%</b>.<q>No raisin to hate these.</q>',99999999,[0,3]);
  2442. new Game.Upgrade('Peanut butter cookies','Cookie production multiplier <b>+5%</b>.',99999999,[1,3]);
  2443. new Game.Upgrade('Plain cookies','Cookie production multiplier <b>+5%</b>.<q>Meh.</q>',99999999,[2,3]);
  2444. new Game.Upgrade('Coconut cookies','Cookie production multiplier <b>+5%</b>.',999999999,[3,3]);
  2445. new Game.Upgrade('White chocolate cookies','Cookie production multiplier <b>+5%</b>.',999999999,[4,3]);
  2446. new Game.Upgrade('Macadamia nut cookies','Cookie production multiplier <b>+5%</b>.',999999999,[5,3]);
  2447. power=10;new Game.Upgrade('Double-chip cookies','Cookie production multiplier <b>+10%</b>.',99999999999,[6,3]);
  2448. power=5;new Game.Upgrade('Sugar cookies','Cookie production multiplier <b>+5%</b>.',99999999,[7,3]);
  2449. power=10;new Game.Upgrade('White chocolate macadamia nut cookies','Cookie production multiplier <b>+10%</b>.',99999999999,[8,3]);
  2450. new Game.Upgrade('All-chocolate cookies','Cookie production multiplier <b>+10%</b>.',99999999999,[9,3]);
  2451. type='';power=0;
  2452.  
  2453. order=100;
  2454. new Game.Upgrade('Quadrillion fingers','The mouse and cursors gain <b>+20</b> cookies for each non-cursor object owned.<q>clickityclickityclickityclickityclick</q>',50000000000,[3,6]);
  2455.  
  2456. order=200;new Game.Upgrade('Prune juice','Grandmas are <b>twice</b> as efficient.<q>Gets me going.</q>',Game.Objects['Grandma'].basePrice*tier4,[1,2]);
  2457. order=300;new Game.Upgrade('Genetically-modified cookies','Farms are <b>twice</b> as efficient.<q>All-natural mutations.</q>',Game.Objects['Farm'].basePrice*tier4,[2,2]);
  2458. order=400;new Game.Upgrade('Radium reactors','Factories are <b>twice</b> as efficient.<q>Gives your cookies a healthy glow.</q>',Game.Objects['Factory'].basePrice*tier4,[4,2]);
  2459. order=500;new Game.Upgrade('Ultimadrill','Mines are <b>twice</b> as efficient.<q>Pierce the heavens, etc.</q>',Game.Objects['Mine'].basePrice*tier4,[3,2]);
  2460. order=600;new Game.Upgrade('Warp drive','Shipments are <b>twice</b> as efficient.',Game.Objects['Shipment'].basePrice*tier4,[5,2]);
  2461. order=700;new Game.Upgrade('Ambrosia','Alchemy labs are <b>twice</b> as efficient.',Game.Objects['Alchemy lab'].basePrice*tier4,[6,2]);
  2462. order=800;new Game.Upgrade('Sanity dance','Portals are <b>twice</b> as efficient.<q>We can change if we want to.<br>We can leave our brains behind.</q>',Game.Objects['Portal'].basePrice*tier4,[7,2]);
  2463. order=900;new Game.Upgrade('Causality enforcer','Time machines are <b>twice</b> as efficient.<q>What happened, happened.</q>',1234567890000,[8,2]);
  2464.  
  2465. order=5000;
  2466. new Game.Upgrade('Lucky day','Golden cookies appear <b>twice as often</b> and last <b>twice as long</b>.',777777777,[10,1]);
  2467. new Game.Upgrade('Serendipity','Golden cookies appear <b>twice as often</b> and last <b>twice as long</b>.',77777777777,[10,1]);
  2468.  
  2469. order=20000;
  2470. new Game.Upgrade('Kitten engineers','You gain <b>more CpS</b> the more milk you have.<q>meow meow meow meow, sir</q>',9000000000000,[3,7]);
  2471.  
  2472. order=10000;
  2473. type='cookie';power=15;
  2474. new Game.Upgrade('Dark chocolate-coated cookies','Cookie production multiplier <b>+15%</b>.',999999999999,[10,3]);
  2475. new Game.Upgrade('White chocolate-coated cookies','Cookie production multiplier <b>+15%</b>.',999999999999,[11,3]);
  2476. type='';power=0;
  2477.  
  2478. order=250;
  2479. new Game.Upgrade('Farmer grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Farm'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2480. new Game.Upgrade('Worker grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Factory'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2481. new Game.Upgrade('Miner grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Mine'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2482. new Game.Upgrade('Cosmic grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Shipment'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2483. new Game.Upgrade('Transmuted grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Alchemy lab'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2484. new Game.Upgrade('Altered grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Portal'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2485. new Game.Upgrade('Grandmas\' grandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Time machine'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2486.  
  2487. order=15000;
  2488. Game.baseResearchTime=Game.fps*60*30;
  2489. Game.SetResearch=function(what,time)
  2490. {
  2491. if (Game.Upgrades[what])
  2492. {
  2493. Game.researchT=Game.Has('Ultrascience')?Game.fps*5:Game.baseResearchTime;
  2494. Game.nextResearch=Game.Upgrades[what].id;
  2495. Game.Popup('Research has begun.');
  2496. }
  2497. }
  2498.  
  2499. new Game.Upgrade('Bingo center/Research facility','Grandma-operated science lab and leisure club.<br>Grandmas are <b>4 times</b> as efficient.<br><b>Regularly unlocks new upgrades</b>.',100000000000,[11,9],function(){Game.SetResearch('Specialized chocolate chips');});
  2500. new Game.Upgrade('Specialized chocolate chips','[Research]<br>Cookie production multiplier <b>+1%</b>.<q>Computer-designed chocolate chips. Computer chips, if you will.</q>',10000000000,[0,9],function(){Game.SetResearch('Designer cocoa beans');});
  2501. new Game.Upgrade('Designer cocoa beans','[Research]<br>Cookie production multiplier <b>+2%</b>.<q>Now more aerodynamic than ever!</q>',20000000000,[1,9],function(){Game.SetResearch('Ritual rolling pins');});
  2502. new Game.Upgrade('Ritual rolling pins','[Research]<br>Grandmas are <b>twice</b> as efficient.<q>The result of years of scientific research!</q>',40000000000,[2,9],function(){Game.SetResearch('Underworld ovens');});
  2503. new Game.Upgrade('Underworld ovens','[Research]<br>Cookie production multiplier <b>+3%</b>.<q>Powered by science, of course!</q>',80000000000,[3,9],function(){Game.SetResearch('One mind');});
  2504. new Game.Upgrade('One mind','[Research]<br>Each grandma gains <b>+1 base CpS for each 50 grandmas</b>.<div class="warning">Note : the grandmothers are growing restless. Do not encourage them.</div><q>We are one. We are many.</q>',160000000000,[4,9],function(){Game.elderWrath=1;Game.SetResearch('Exotic nuts');});
  2505. Game.Upgrades['One mind'].clickFunction=function(){return confirm('Warning : purchasing this will have unexpected, and potentially undesirable results!\nIt\'s all downhill from here. You have been warned!\nPurchase anyway?');};
  2506. new Game.Upgrade('Exotic nuts','[Research]<br>Cookie production multiplier <b>+4%</b>.<q>You\'ll go crazy over these!</q>',320000000000,[5,9],function(){Game.SetResearch('Communal brainsweep');});
  2507. new Game.Upgrade('Communal brainsweep','[Research]<br>Each grandma gains another <b>+1 base CpS for each 50 grandmas</b>.<div class="warning">Note : proceeding any further in scientific research may have unexpected results. You have been warned.</div><q>We fuse. We merge. We grow.</q>',640000000000,[6,9],function(){Game.elderWrath=2;Game.SetResearch('Arcane sugar');});
  2508. new Game.Upgrade('Arcane sugar','[Research]<br>Cookie production multiplier <b>+5%</b>.<q>Tastes like insects, ligaments, and molasses.</q>',1280000000000,[7,9],function(){Game.SetResearch('Elder Pact');});
  2509. new Game.Upgrade('Elder Pact','[Research]<br>Each grandma gains <b>+1 base CpS for each 20 portals</b>.<div class="warning">Note : this is a bad idea.</div><q>squirm crawl slither writhe<br>today we rise</q>',2560000000000,[8,9],function(){Game.elderWrath=3;});
  2510. new Game.Upgrade('Elder Pledge','[Repeatable]<br>Contains the wrath of the elders, at least for a while.',1,[9,9],function()
  2511. {
  2512. Game.elderWrath=0;
  2513. Game.pledges++;
  2514. Game.pledgeT=Game.fps*60*(Game.Has('Sacrificial rolling pins')?60:30);
  2515. Game.Upgrades['Elder Pledge'].basePrice=Math.pow(8,Math.min(Game.pledges+2,13));
  2516. Game.Unlock('Elder Covenant');
  2517. });
  2518. Game.Upgrades['Elder Pledge'].hide=3;
  2519.  
  2520. order=150;
  2521. new Game.Upgrade('Plastic mouse','Clicking gains <b>+1% of your CpS</b>.',50000,[11,0]);
  2522. new Game.Upgrade('Iron mouse','Clicking gains <b>+1% of your CpS</b>.',5000000,[11,0]);
  2523. new Game.Upgrade('Titanium mouse','Clicking gains <b>+1% of your CpS</b>.',500000000,[11,1]);
  2524. new Game.Upgrade('Adamantium mouse','Clicking gains <b>+1% of your CpS</b>.',50000000000,[11,2]);
  2525.  
  2526. order=40000;
  2527. new Game.Upgrade('Ultrascience','Research takes only <b>5 seconds</b>.',7,[9,2]);//debug purposes only
  2528. Game.Upgrades['Ultrascience'].hide=3;
  2529.  
  2530. order=10000;
  2531. type='cookie';power=15;
  2532. new Game.Upgrade('Eclipse cookies','Cookie production multiplier <b>+15%</b>.<q>Look to the cookie.</q>',9999999999999,[0,4]);
  2533. new Game.Upgrade('Zebra cookies','Cookie production multiplier <b>+15%</b>.',9999999999999,[1,4]);
  2534. type='';power=0;
  2535.  
  2536. order=100;
  2537. new Game.Upgrade('Quintillion fingers','The mouse and cursors gain <b>+100</b> cookies for each non-cursor object owned.<q>man, just go click click click click click, it\'s real easy, man.</q>',50000000000000,[3,6]);
  2538.  
  2539. order=40000;
  2540. new Game.Upgrade('Gold hoard','Golden cookies appear <b>really often</b>.',7,[10,1]);//debug purposes only
  2541. Game.Upgrades['Gold hoard'].hide=3;
  2542.  
  2543. order=15000;
  2544. new Game.Upgrade('Elder Covenant','[Switch]<br>Puts a permanent end to the elders\' wrath, at the price of 5% of your CpS.',6666666666666,[8,9],function()
  2545. {
  2546. Game.pledgeT=0;
  2547. Game.Lock('Revoke Elder Covenant');
  2548. Game.Unlock('Revoke Elder Covenant');
  2549. Game.Lock('Elder Pledge');
  2550. Game.Win('Elder calm');
  2551. });
  2552. Game.Upgrades['Elder Covenant'].hide=3;
  2553.  
  2554. new Game.Upgrade('Revoke Elder Covenant','[Switch]<br>You will get 5% of your CpS back, but the grandmatriarchs will return.',6666666666,[8,9],function()
  2555. {
  2556. Game.Lock('Elder Covenant');
  2557. Game.Unlock('Elder Covenant');
  2558. });
  2559. Game.Upgrades['Revoke Elder Covenant'].hide=3;
  2560.  
  2561. order=5000;
  2562. new Game.Upgrade('Get lucky','Golden cookie effects last <b>twice as long</b>.<q>You\'ve been up all night, haven\'t you?</q>',77777777777777,[10,1]);
  2563.  
  2564. order=15000;
  2565. new Game.Upgrade('Sacrificial rolling pins','Elder pledge last <b>twice</b> as long.',2888888888888,[2,9]);
  2566.  
  2567. order=10000;
  2568. type='cookie';power=15;
  2569. new Game.Upgrade('Snickerdoodles','Cookie production multiplier <b>+15%</b>.',99999999999999,[2,4]);
  2570. new Game.Upgrade('Stroopwafels','Cookie production multiplier <b>+15%</b>.<q>If it ain\'t dutch, it ain\'t much.</q>',99999999999999,[3,4]);
  2571. new Game.Upgrade('Macaroons','Cookie production multiplier <b>+15%</b>.',99999999999999,[4,4]);
  2572. type='';power=0;
  2573.  
  2574. order=40000;
  2575. new Game.Upgrade('Neuromancy','Can toggle upgrades on and off at will in the stats menu.',7,[4,9]);//debug purposes only
  2576. Game.Upgrades['Neuromancy'].hide=3;
  2577.  
  2578. order=10000;
  2579. type='cookie';power=15;
  2580. new Game.Upgrade('Empire biscuits','Cookie production multiplier <b>+15%</b>.',99999999999999,[5,4]);
  2581. new Game.Upgrade('British tea biscuits','Cookie production multiplier <b>+15%</b>.',99999999999999,[6,4]);
  2582. new Game.Upgrade('Chocolate british tea biscuits','Cookie production multiplier <b>+15%</b>.',99999999999999,[7,4]);
  2583. new Game.Upgrade('Round british tea biscuits','Cookie production multiplier <b>+15%</b>.',99999999999999,[8,4]);
  2584. new Game.Upgrade('Round chocolate british tea biscuits','Cookie production multiplier <b>+15%</b>.',99999999999999,[9,4]);
  2585. new Game.Upgrade('Round british tea biscuits with heart motif','Cookie production multiplier <b>+15%</b>.',99999999999999,[10,4]);
  2586. new Game.Upgrade('Round chocolate british tea biscuits with heart motif','Cookie production multiplier <b>+15%</b>.<q>Quite.</q>',99999999999999,[11,4]);
  2587. type='';power=0;
  2588.  
  2589.  
  2590. order=1000;
  2591. new Game.Upgrade('Sugar bosons','Antimatter condensers gain <b>+99,999</b> base CpS.',Game.Objects['Antimatter condenser'].basePrice*tier1,[13,0]);
  2592. new Game.Upgrade('String theory','Antimatter condensers are <b>twice</b> as efficient.',Game.Objects['Antimatter condenser'].basePrice*tier2,[13,0]);
  2593. new Game.Upgrade('Large macaron collider','Antimatter condensers are <b>twice</b> as efficient.<q>How singular!</q>',Game.Objects['Antimatter condenser'].basePrice*tier3,[13,1]);
  2594. new Game.Upgrade('Big bang bake','Antimatter condensers are <b>twice</b> as efficient.<q>And that\'s how it all began.</q>',Game.Objects['Antimatter condenser'].basePrice*tier4,[13,2]);
  2595.  
  2596. order=250;
  2597. new Game.Upgrade('Antigrandmas','Grandmas are <b>twice</b> as efficient.',Game.Objects['Antimatter condenser'].basePrice*tier2,[10,9],function(){Game.Objects['Grandma'].drawFunction();});
  2598.  
  2599. order=10000;
  2600. type='cookie';power=20;
  2601. new Game.Upgrade('Madeleines','Cookie production multiplier <b>+20%</b>.<q>Unforgettable!</q>',199999999999999,[12,3]);
  2602. new Game.Upgrade('Palmiers','Cookie production multiplier <b>+20%</b>.',199999999999999,[13,3]);
  2603. new Game.Upgrade('Palets','Cookie production multiplier <b>+20%</b>.',199999999999999,[12,4]);
  2604. new Game.Upgrade('Sabl&eacute;s','Cookie production multiplier <b>+20%</b>.',199999999999999,[13,4]);
  2605. type='';power=0;
  2606.  
  2607. order=20000;
  2608. new Game.Upgrade('Kitten overseers','You gain <b>more CpS</b> the more milk you have.<q>my purrpose is to serve you, sir</q>',900000000000000,[8,7]);
  2609.  
  2610. /*
  2611. new Game.Upgrade('Plain milk','Unlocks <b>plain milk</b>, available in the menu.',120000000000,[4,8]);
  2612. new Game.Upgrade('Chocolate milk','Unlocks <b>chocolate milk</b>, available in the menu.',120000000000,[5,8]);
  2613. new Game.Upgrade('Raspberry milk','Unlocks <b>raspberry milk</b>, available in the menu.',120000000000,[6,8]);
  2614. new Game.Upgrade('Ain\'t got milk','Unlocks <b>no milk please</b>, available in the menu.',120000000000,[0,8]);
  2615.  
  2616. new Game.Upgrade('Blue background','Unlocks the <b>blue background</b>, available in the menu.',120000000000,[0,9]);
  2617. new Game.Upgrade('Red background','Unlocks the <b>red background</b>, available in the menu.',120000000000,[1,9]);
  2618. new Game.Upgrade('White background','Unlocks the <b>white background</b>, available in the menu.',120000000000,[2,9]);
  2619. new Game.Upgrade('Black background','Unlocks the <b>black background</b>, available in the menu.',120000000000,[3,9]);
  2620. */
  2621.  
  2622.  
  2623. /*=====================================================================================
  2624. ACHIEVEMENTS
  2625. =======================================================================================*/
  2626. Game.Achievements=[];
  2627. Game.AchievementsById=[];
  2628. Game.AchievementsN=0;
  2629. Game.AchievementsOwned=0;
  2630. Game.Achievement=function(name,desc,icon,hide)
  2631. {
  2632. this.id=Game.AchievementsN;
  2633. this.name=name;
  2634. this.desc=desc;
  2635. this.icon=icon;
  2636. this.won=0;
  2637. this.disabled=0;
  2638. this.hide=hide||0;//hide levels : 0=show, 1=hide description, 2=hide, 3=secret (doesn't count toward achievement total)
  2639. this.order=this.id;
  2640. if (order) this.order=order+this.id*0.001;
  2641.  
  2642. Game.Achievements[this.name]=this;
  2643. Game.AchievementsById[this.id]=this;
  2644. Game.AchievementsN++;
  2645. return this;
  2646. }
  2647.  
  2648. Game.Win=function(what)
  2649. {
  2650. if (typeof what==='string')
  2651. {
  2652. if (Game.Achievements[what])
  2653. {
  2654. if (Game.Achievements[what].won==0)
  2655. {
  2656. Game.Achievements[what].won=1;
  2657. Game.Popup('Achievement unlocked :<br>'+Game.Achievements[what].name+'<br> ');
  2658. if (Game.Achievements[what].hide!=3) Game.AchievementsOwned++;
  2659. Game.recalculateGains=1;
  2660. }
  2661. }
  2662. }
  2663. else {for (var i in what) {Game.Win(what[i]);}}
  2664. }
  2665.  
  2666. Game.HasAchiev=function(what)
  2667. {
  2668. return (Game.Achievements[what]?Game.Achievements[what].won:0);
  2669. }
  2670.  
  2671. //define achievements
  2672. //WARNING : do NOT add new achievements in between, this breaks the saves. Add them at the end !
  2673.  
  2674. var order=100;//this is used to set the order in which the items are listed
  2675. //new Game.Achievement('name','description',[0,0]);
  2676. Game.moneyAchievs=[
  2677. 'Wake and bake', 1,
  2678. 'Making some dough', 100,
  2679. 'So baked right now', 1000,
  2680. 'Fledgling bakery', 10000,
  2681. 'Affluent bakery', 100000,
  2682. 'World-famous bakery', 1000000,
  2683. 'Cosmic bakery', 10000000,
  2684. 'Galactic bakery', 100000000,
  2685. 'Universal bakery', 1000000000,
  2686. 'Timeless bakery', 5000000000,
  2687. 'Infinite bakery', 10000000000,
  2688. 'Immortal bakery', 50000000000,
  2689. 'You can stop now', 100000000000,
  2690. 'Cookies all the way down', 500000000000,
  2691. 'Overdose', 1000000000000,
  2692. 'How?', 10000000000000
  2693. ];
  2694. for (var i=0;i<Game.moneyAchievs.length/2;i++)
  2695. {
  2696. var pic=[Math.min(10,i),5];
  2697. if (i==15) pic=[11,5];
  2698. new Game.Achievement(Game.moneyAchievs[i*2],'Bake <b>'+Beautify(Game.moneyAchievs[i*2+1])+'</b> cookie'+(Game.moneyAchievs[i*2+1]==1?'':'s')+'.',pic,2);
  2699. }
  2700.  
  2701. order=200;
  2702. Game.cpsAchievs=[
  2703. 'Casual baking', 1,
  2704. 'Hardcore baking', 10,
  2705. 'Steady tasty stream', 100,
  2706. 'Cookie monster', 1000,
  2707. 'Mass producer', 10000,
  2708. 'Cookie vortex', 100000,
  2709. 'Cookie pulsar', 1000000,
  2710. 'Cookie quasar', 10000000,
  2711. 'A world filled with cookies', 100000000,
  2712. 'Let\'s never bake again', 1000000000
  2713. ];
  2714. for (var i=0;i<Game.cpsAchievs.length/2;i++)
  2715. {
  2716. var pic=[i,5];
  2717. new Game.Achievement(Game.cpsAchievs[i*2],'Bake <b>'+Beautify(Game.cpsAchievs[i*2+1])+'</b> cookie'+(Game.cpsAchievs[i*2+1]==1?'':'s')+' per second.',pic,2);
  2718. }
  2719.  
  2720. order=30000;
  2721. new Game.Achievement('Sacrifice','Reset your game with <b>1 million</b> cookies baked.<q>Easy come, easy go.</q>',[11,6],2);
  2722. new Game.Achievement('Oblivion','Reset your game with <b>1 billion</b> cookies baked.<q>Back to square one.</q>',[11,6],2);
  2723. new Game.Achievement('From scratch','Reset your game with <b>1 trillion</b> cookies baked.<q>It\'s been fun.</q>',[11,6],2);
  2724.  
  2725. order=31000;
  2726. new Game.Achievement('Neverclick','Make <b>1 million</b> cookies by only having clicked <b>15 times</b>.',[12,0],3);
  2727. order=1000;
  2728. new Game.Achievement('Clicktastic','Make <b>1,000</b> cookies from clicking.',[11,0]);
  2729. new Game.Achievement('Clickathlon','Make <b>100,000</b> cookies from clicking.',[11,1]);
  2730. new Game.Achievement('Clickolympics','Make <b>10,000,000</b> cookies from clicking.',[11,1]);
  2731. new Game.Achievement('Clickorama','Make <b>1,000,000,000</b> cookies from clicking.',[11,2]);
  2732.  
  2733. order=1050;
  2734. new Game.Achievement('Click','Have <b>1</b> cursor.',[0,0]);
  2735. new Game.Achievement('Double-click','Have <b>2</b> cursors.',[0,6]);
  2736. new Game.Achievement('Mouse wheel','Have <b>50</b> cursors.',[1,6]);
  2737. new Game.Achievement('Of Mice and Men','Have <b>100</b> cursors.',[2,6]);
  2738. new Game.Achievement('The Digital','Have <b>200</b> cursors.',[3,6]);
  2739.  
  2740. order=1100;
  2741. new Game.Achievement('Just wrong','Sell a grandma.<q>I thought you loved me.</q>',[10,9],2);
  2742. new Game.Achievement('Grandma\'s cookies','Have <b>1</b> grandma.',[1,0]);
  2743. new Game.Achievement('Sloppy kisses','Have <b>50</b> grandmas.',[1,1]);
  2744. new Game.Achievement('Retirement home','Have <b>100</b> grandmas.',[1,2]);
  2745.  
  2746. order=1200;
  2747. new Game.Achievement('My first farm','Have <b>1</b> farm.',[2,0]);
  2748. new Game.Achievement('Reap what you sow','Have <b>50</b> farms.',[2,1]);
  2749. new Game.Achievement('Farm ill','Have <b>100</b> farms.',[2,2]);
  2750.  
  2751. order=1300;
  2752. new Game.Achievement('Production chain','Have <b>1</b> factory.',[4,0]);
  2753. new Game.Achievement('Industrial revolution','Have <b>50</b> factories.',[4,1]);
  2754. new Game.Achievement('Global warming','Have <b>100</b> factories.',[4,2]);
  2755.  
  2756. order=1400;
  2757. new Game.Achievement('You know the drill','Have <b>1</b> mine.',[3,0]);
  2758. new Game.Achievement('Excavation site','Have <b>50</b> mines.',[3,1]);
  2759. new Game.Achievement('Hollow the planet','Have <b>100</b> mines.',[3,2]);
  2760.  
  2761. order=1500;
  2762. new Game.Achievement('Expedition','Have <b>1</b> shipment.',[5,0]);
  2763. new Game.Achievement('Galactic highway','Have <b>50</b> shipments.',[5,1]);
  2764. new Game.Achievement('Far far away','Have <b>100</b> shipments.',[5,2]);
  2765.  
  2766. order=1600;
  2767. new Game.Achievement('Transmutation','Have <b>1</b> alchemy lab.',[6,0]);
  2768. new Game.Achievement('Transmogrification','Have <b>50</b> alchemy labs.',[6,1]);
  2769. new Game.Achievement('Gold member','Have <b>100</b> alchemy labs.',[6,2]);
  2770.  
  2771. order=1700;
  2772. new Game.Achievement('A whole new world','Have <b>1</b> portal.',[7,0]);
  2773. new Game.Achievement('Now you\'re thinking','Have <b>50</b> portals.',[7,1]);
  2774. new Game.Achievement('Dimensional shift','Have <b>100</b> portals.',[7,2]);
  2775.  
  2776. order=1800;
  2777. new Game.Achievement('Time warp','Have <b>1</b> time machine.',[8,0]);
  2778. new Game.Achievement('Alternate timeline','Have <b>50</b> time machines.',[8,1]);
  2779. new Game.Achievement('Rewriting history','Have <b>100</b> time machines.',[8,2]);
  2780.  
  2781. order=7000;
  2782. new Game.Achievement('One with everything','Have <b>at least 1</b> of every building.',[4,6],2);
  2783. new Game.Achievement('Mathematician','Have at least <b>1 time machine, 2 portals, 4 alchemy labs, 8 shipments</b> and so on (128 max).',[7,6],2);
  2784. new Game.Achievement('Base 10','Have at least <b>10 time machines, 20 portals, 30 alchemy labs, 40 shipments</b> and so on.',[8,6],2);
  2785.  
  2786. order=10000;
  2787. new Game.Achievement('Golden cookie','Click a <b>golden cookie</b>.',[10,1],1);
  2788. new Game.Achievement('Lucky cookie','Click <b>7 golden cookies</b>.',[10,1],1);
  2789. new Game.Achievement('A stroke of luck','Click <b>27 golden cookies</b>.',[10,1],1);
  2790.  
  2791. order=30200;
  2792. new Game.Achievement('Cheated cookies taste awful','Hack in some cookies.',[10,6],3);
  2793. order=30001;
  2794. new Game.Achievement('Uncanny clicker','Click really, really fast.<q>Well I\'ll be!</q>',[12,0],2);
  2795.  
  2796. order=5000;
  2797. new Game.Achievement('Builder','Own <b>100</b> buildings.',[4,6],1);
  2798. new Game.Achievement('Architect','Own <b>400</b> buildings.',[5,6],1);
  2799. order=6000;
  2800. new Game.Achievement('Enhancer','Purchase <b>20</b> upgrades.',[9,0],1);
  2801. new Game.Achievement('Augmenter','Purchase <b>50</b> upgrades.',[9,1],1);
  2802.  
  2803. order=11000;
  2804. new Game.Achievement('Cookie-dunker','Dunk the cookie.<q>You did it!</q>',[4,7],2);
  2805.  
  2806. order=10000;
  2807. new Game.Achievement('Fortune','Click <b>77 golden cookies</b>.<q>You should really go to bed.</q>',[10,1],1);
  2808. order=31000;
  2809. new Game.Achievement('True Neverclick','Make <b>1 million</b> cookies with <b>no</b> cookie clicks.<q>This kinda defeats the whole purpose, doesn\'t it?</q>',[12,0],3);
  2810.  
  2811. order=20000;
  2812. new Game.Achievement('Elder nap','Appease the grandmatriarchs at least <b>once</b>.<q>we<br>are<br>eternal</q>',[8,9],2);
  2813. new Game.Achievement('Elder slumber','Appease the grandmatriarchs at least <b>5 times</b>.<q>our mind<br>outlives<br>the universe</q>',[8,9],2);
  2814.  
  2815. order=1100;
  2816. new Game.Achievement('Elder','Own every grandma type.',[10,9],2);
  2817.  
  2818. order=20000;
  2819. new Game.Achievement('Elder calm','Declare a covenant with the grandmatriarchs.<q>we<br>have<br>fed</q>',[8,9],2);
  2820.  
  2821. order=5000;
  2822. new Game.Achievement('Engineer','Own <b>800</b> buildings.',[6,6],1);
  2823.  
  2824. order=10000;
  2825. new Game.Achievement('Leprechaun','Click <b>777 golden cookies</b>.',[10,1],1);
  2826. new Game.Achievement('Black cat\'s paw','Click <b>7777 golden cookies</b>.',[10,1],3);
  2827.  
  2828. order=30000;
  2829. new Game.Achievement('Nihilism','Reset your game with <b>1 quadrillion</b> cookies baked.<q>There are many things<br>that need to be erased</q>',[11,6],2);
  2830. //new Game.Achievement('Galactus\' Reprimand','Reset your game with <b>1 quintillion</b> coo- okay no I'm yanking your chain
  2831.  
  2832. order=1900;
  2833. new Game.Achievement('Antibatter','Have <b>1</b> antimatter condenser.',[13,0]);
  2834. new Game.Achievement('Quirky quarks','Have <b>50</b> antimatter condensers.',[13,1]);
  2835. new Game.Achievement('It does matter!','Have <b>100</b> antimatter condensers.',[13,2]);
  2836.  
  2837. order=6000;
  2838. new Game.Achievement('Upgrader','Purchase <b>100</b> upgrades.',[9,2],1);
  2839.  
  2840. order=7000;
  2841. new Game.Achievement('Centennial','Have at least <b>100 of everything</b>.',[9,6],2);
  2842.  
  2843.  
  2844. Game.RuinTheFun=function()
  2845. {
  2846. for (var i in Game.Upgrades)
  2847. {
  2848. Game.Unlock(Game.Upgrades[i].name);
  2849.  
  2850. Game.Upgrades[i].bought++;
  2851. if (Game.Upgrades[i].buyFunction) Game.Upgrades[i].buyFunction();
  2852. }
  2853. for (var i in Game.Achievements)
  2854. {
  2855. Game.Win(Game.Achievements[i].name);
  2856. }
  2857. Game.Earn(999999999999999999);
  2858. Game.upgradesToRebuild=1;
  2859. Game.recalculateGains=1;
  2860. }
  2861.  
  2862. /*=====================================================================================
  2863. GRANDMAPOCALYPSE
  2864. =======================================================================================*//** BEGIN EDIT **/
  2865. Game.UpdateGrandmapocalypse=function()
  2866. {
  2867. if (Game.Has('Elder Covenant') || Game.Objects['Grandma'].amount==0) Game.elderWrath=0;
  2868. else if (Game.pledgeT>0)//if the pledge is active, lower it
  2869. {
  2870. Game.pledgeT--;
  2871. if (Game.pledgeT==0)//did we reach 0? make the pledge purchasable again
  2872. {
  2873. Game.Lock('Elder Pledge');
  2874. Game.Unlock('Elder Pledge');
  2875. Game.elderWrath=1;
  2876. }
  2877. }
  2878. else
  2879. {
  2880. if (Game.Has('One mind') && Game.elderWrath==0)
  2881. {
  2882. Game.elderWrath=1;
  2883. }
  2884. if (Math.random()<0.001 && Game.elderWrath<Game.Has('One mind')+Game.Has('Communal brainsweep')+Game.Has('Elder Pact'))
  2885. {
  2886. Game.elderWrath++;//have we already pledged? make the elder wrath shift between different stages
  2887. }
  2888. if (Game.Has('Elder Pact') && Game.Upgrades['Elder Pledge'].unlocked==0)
  2889. {
  2890. Game.Lock('Elder Pledge');
  2891. Game.Unlock('Elder Pledge');
  2892. }
  2893. }
  2894. Game.elderWrathD+=((Game.elderWrath+1)-Game.elderWrathD)*0.001;//slowly fade to the target wrath state
  2895. }
  2896.  
  2897. Game.DrawGrandmapocalypse=function()
  2898. {
  2899. Game.defaultBg='bgBlue';
  2900. //handle background
  2901. if (Math.abs((Game.elderWrath+1)-Game.elderWrathD)>0.1)
  2902. {
  2903. if (Game.elderWrathD<1)
  2904. {
  2905. Game.bgR=0;
  2906. if (Game.bg!=Game.defaultBg || Game.bgFade!=Game.defaultBg)
  2907. {
  2908. Game.bg=Game.defaultBg;
  2909. Game.bgFade=Game.defaultBg;
  2910. l('backgroundLayer1').style.background='url(img/'+Game.bg+'.jpg)';
  2911. l('backgroundLayer2').style.background='url(img/'+Game.bgFade+'.jpg)';
  2912. l('backgroundLayer1').style.backgroundSize='auto';
  2913. l('backgroundLayer2').style.backgroundSize='auto';
  2914. }
  2915. }
  2916. else if (Game.elderWrathD>=1 && Game.elderWrathD<2)
  2917. {
  2918. Game.bgR=(Game.elderWrathD-1)/1;
  2919. if (Game.bg!=Game.defaultBg || Game.bgFade!='grandmas1')
  2920. {
  2921. Game.bg=Game.defaultBg;
  2922. Game.bgFade='grandmas1';
  2923. l('backgroundLayer1').style.background='url(img/'+Game.bg+'.jpg)';
  2924. l('backgroundLayer2').style.background='url(img/'+Game.bgFade+'.jpg)';
  2925. l('backgroundLayer1').style.backgroundSize='auto';
  2926. l('backgroundLayer2').style.backgroundSize='512px';
  2927. }
  2928. }
  2929. else if (Game.elderWrathD>=2 && Game.elderWrathD<3)
  2930. {
  2931. Game.bgR=(Game.elderWrathD-2)/1;
  2932. if (Game.bg!='grandmas1' || Game.bgFade!='grandmas2')
  2933. {
  2934. Game.bg='grandmas1';
  2935. Game.bgFade='grandmas2';
  2936. l('backgroundLayer1').style.background='url(img/'+Game.bg+'.jpg)';
  2937. l('backgroundLayer2').style.background='url(img/'+Game.bgFade+'.jpg)';
  2938. l('backgroundLayer1').style.backgroundSize='512px';
  2939. l('backgroundLayer2').style.backgroundSize='512px';
  2940. }
  2941. }
  2942. else if (Game.elderWrathD>=3 && Game.elderWrathD<4)
  2943. {
  2944. Game.bgR=(Game.elderWrathD-3)/1;
  2945. if (Game.bg!='grandmas2' || Game.bgFade!='grandmas3')
  2946. {
  2947. Game.bg='grandmas2';
  2948. Game.bgFade='grandmas3';
  2949. l('backgroundLayer1').style.background='url(img/'+Game.bg+'.jpg)';
  2950. l('backgroundLayer2').style.background='url(img/'+Game.bgFade+'.jpg)';
  2951. l('backgroundLayer1').style.backgroundSize='512px';
  2952. l('backgroundLayer2').style.backgroundSize='512px';
  2953. }
  2954. }
  2955. Game.bgRd+=(Game.bgR-Game.bgRd)*0.5;
  2956. l('backgroundLayer2').style.opacity=Game.bgR;
  2957. //why are these so slow (maybe replaceable with a large canvas)
  2958. /*var x=Math.sin(Game.T*0.2)*Math.random()*8;
  2959. var y=Math.sin(Game.T*0.2)*Math.random()*8;
  2960. l('backgroundLayer1').style.backgroundPosition=Math.floor(x)+'px '+Math.floor(y)+'px';
  2961. l('backgroundLayer2').style.backgroundPosition=Math.floor(x)+'px '+Math.floor(y)+'px';*/
  2962. }
  2963. };
  2964.  
  2965.  
  2966. /*=====================================================================================
  2967. DUNGEONS (unfinished)
  2968. =======================================================================================*/
  2969.  
  2970. LaunchDungeons();
  2971.  
  2972. /*=====================================================================================
  2973. INITIALIZATION END; GAME READY TO LAUNCH
  2974. =======================================================================================*/
  2975.  
  2976. Game.LoadSave();
  2977.  
  2978. Game.ready=1;
  2979. l('javascriptError').innerHTML='';
  2980. l('javascriptError').style.display='none';
  2981. Game.Loop();
  2982. }
  2983.  
  2984. /*=====================================================================================
  2985. LOGIC
  2986. =======================================================================================*/
  2987. Game.Logic=function()
  2988. {
  2989. Game.UpdateGrandmapocalypse();
  2990.  
  2991. //handle milk and milk accessories
  2992. Game.milkProgress=Game.AchievementsOwned/25;
  2993. if (Game.milkProgress>=0.5) Game.Unlock('Kitten helpers');
  2994. if (Game.milkProgress>=1) Game.Unlock('Kitten workers');
  2995. if (Game.milkProgress>=2) Game.Unlock('Kitten engineers');
  2996. if (Game.milkProgress>=3) Game.Unlock('Kitten overseers');
  2997. Game.milkH=Math.min(1,Game.milkProgress)*0.35;
  2998. Game.milkHd+=(Game.milkH-Game.milkHd)*0.02;
  2999.  
  3000. if (Game.autoclickerDetected>0) Game.autoclickerDetected--;
  3001.  
  3002. //handle research
  3003. if (Game.researchT>0)
  3004. {
  3005. Game.researchT--;
  3006. }
  3007. if (Game.researchT==0 && Game.nextResearch)
  3008. {
  3009. Game.Unlock(Game.UpgradesById[Game.nextResearch].name);
  3010. Game.Popup('Researched : '+Game.UpgradesById[Game.nextResearch].name);
  3011. Game.nextResearch=0;
  3012. Game.researchT=-1;
  3013. }
  3014.  
  3015. //handle cookies
  3016. if (Game.recalculateGains) Game.CalculateGains();;
  3017. Game.Earn(Game.cookiesPs/Game.fps);//add cookies per second
  3018. //var cps=Game.cookiesPs+Game.cookies*0.01;//exponential cookies
  3019. //Game.Earn(cps/Game.fps);//add cookies per second
  3020.  
  3021. for (var i in Game.Objects)
  3022. {
  3023. var me=Game.Objects[i];
  3024. me.totalCookies+=me.storedTotalCps/Game.fps;
  3025. }
  3026. if (Game.cookies && Game.T%Math.ceil(Game.fps/Math.min(10,Game.cookiesPs))==0 && Game.prefs.numbers) Game.cookieParticleAdd();//cookie shower
  3027. if (Game.frenzy>0)
  3028. {
  3029. Game.frenzy--;
  3030. if (Game.frenzy==0) Game.recalculateGains=1;
  3031. }
  3032. if (Game.clickFrenzy>0)
  3033. {
  3034. Game.clickFrenzy--;
  3035. if (Game.clickFrenzy==0) Game.recalculateGains=1;
  3036. }
  3037. if (Game.T%(Game.fps*5)==0 && Game.ObjectsById.length>0)//check some achievements and upgrades
  3038. {
  3039. //if (Game.Has('Arcane sugar') && !Game.Has('Elder Pact')) Game.Unlock('Elder Pact');//temporary fix for something stupid I've done
  3040.  
  3041. //if (Game.Objects['Factory'].amount>=50 && Game.Objects['Factory'].specialUnlocked==0) {Game.Objects['Factory'].unlockSpecial();Game.Popup('You have unlocked the factory dungeons!');}
  3042. if (isNaN(Game.cookies)) {Game.cookies=0;Game.cookiesEarned=0;Game.recalculateGains=1;}
  3043.  
  3044. if (Game.cookiesEarned>=9999999) Game.Unlock(['Oatmeal raisin cookies','Peanut butter cookies','Plain cookies','Sugar cookies']);
  3045. if (Game.cookiesEarned>=99999999) Game.Unlock(['Coconut cookies','White chocolate cookies','Macadamia nut cookies']);
  3046. if (Game.cookiesEarned>=999999999) Game.Unlock(['Double-chip cookies','White chocolate macadamia nut cookies','All-chocolate cookies']);
  3047. if (Game.cookiesEarned>=9999999999) Game.Unlock(['Dark chocolate-coated cookies','White chocolate-coated cookies']);
  3048. if (Game.cookiesEarned>=99999999999) Game.Unlock(['Eclipse cookies','Zebra cookies']);
  3049. if (Game.cookiesEarned>=999999999999) Game.Unlock(['Snickerdoodles','Stroopwafels','Macaroons']);
  3050. if (Game.cookiesEarned>=999999999999 && Game.Has('Snickerdoodles') && Game.Has('Stroopwafels') && Game.Has('Macaroons'))
  3051. {
  3052. Game.Unlock('Empire biscuits');
  3053. if (Game.Has('Empire biscuits')) Game.Unlock('British tea biscuits');
  3054. if (Game.Has('British tea biscuits')) Game.Unlock('Chocolate british tea biscuits');
  3055. if (Game.Has('Chocolate british tea biscuits')) Game.Unlock('Round british tea biscuits');
  3056. if (Game.Has('Round british tea biscuits')) Game.Unlock('Round chocolate british tea biscuits');
  3057. if (Game.Has('Round chocolate british tea biscuits')) Game.Unlock('Round british tea biscuits with heart motif');
  3058. if (Game.Has('Round british tea biscuits with heart motif')) Game.Unlock('Round chocolate british tea biscuits with heart motif');
  3059. }
  3060. if (Game.cookiesEarned>=9999999999999) Game.Unlock(['Madeleines','Palmiers','Palets','Sabl&eacute;s']);
  3061.  
  3062. for (var i=0;i<Game.moneyAchievs.length/2;i++)
  3063. {
  3064. if (Game.cookiesEarned>=Game.moneyAchievs[i*2+1]) Game.Win(Game.moneyAchievs[i*2]);
  3065. }
  3066. var buildingsOwned=0;
  3067. var oneOfEach=1;
  3068. var mathematician=1;
  3069. var base10=1;
  3070. var centennial=1;
  3071. for (var i in Game.Objects)
  3072. {
  3073. buildingsOwned+=Game.Objects[i].amount;
  3074. if (!Game.HasAchiev('One with everything')) {if (Game.Objects[i].amount==0) oneOfEach=0;}
  3075. if (!Game.HasAchiev('Mathematician')) {if (Game.Objects[i].amount<Math.min(128,Math.pow(2,(Game.ObjectsById.length-Game.Objects[i].id)-1))) mathematician=0;}
  3076. if (!Game.HasAchiev('Base 10')) {if (Game.Objects[i].amount<(Game.ObjectsById.length-Game.Objects[i].id)*10) base10=0;}
  3077. if (!Game.HasAchiev('Centennial')) {if (Game.Objects[i].amount<100) centennial=0;}
  3078. }
  3079. if (oneOfEach==1) Game.Win('One with everything');
  3080. if (mathematician==1) Game.Win('Mathematician');
  3081. if (base10==1) Game.Win('Base 10');
  3082. if (centennial==1) Game.Win('Centennial');
  3083. if (Game.cookiesEarned>=1000000 && Game.cookieClicks<=15) Game.Win('Neverclick');
  3084. if (Game.cookiesEarned>=1000000 && Game.cookieClicks<=0) Game.Win('True Neverclick');
  3085. if (Game.handmadeCookies>=1000) {Game.Win('Clicktastic');Game.Unlock('Plastic mouse');}
  3086. if (Game.handmadeCookies>=100000) {Game.Win('Clickathlon');Game.Unlock('Iron mouse');}
  3087. if (Game.handmadeCookies>=10000000) {Game.Win('Clickolympics');Game.Unlock('Titanium mouse');}
  3088. if (Game.handmadeCookies>=1000000000) {Game.Win('Clickorama');Game.Unlock('Adamantium mouse');}
  3089. if (Game.cookiesEarned<Game.cookies) Game.Win('Cheated cookies taste awful');
  3090.  
  3091. if (buildingsOwned>=100) Game.Win('Builder');
  3092. if (buildingsOwned>=400) Game.Win('Architect');
  3093. if (buildingsOwned>=800) Game.Win('Engineer');
  3094. if (Game.UpgradesOwned>=20) Game.Win('Enhancer');
  3095. if (Game.UpgradesOwned>=50) Game.Win('Augmenter');
  3096. if (Game.UpgradesOwned>=100) Game.Win('Upgrader');
  3097.  
  3098. if (!Game.HasAchiev('Elder') && Game.Has('Farmer grandmas') && Game.Has('Worker grandmas') && Game.Has('Miner grandmas') && Game.Has('Cosmic grandmas') && Game.Has('Transmuted grandmas') && Game.Has('Altered grandmas') && Game.Has('Grandmas\' grandmas')) Game.Win('Elder');
  3099. if (Game.Objects['Grandma'].amount>=6 && !Game.Has('Bingo center/Research facility') && Game.HasAchiev('Elder')) Game.Unlock('Bingo center/Research facility');
  3100. if (Game.pledges>0) Game.Win('Elder nap');
  3101. if (Game.pledges>=5) Game.Win('Elder slumber');
  3102. if (Game.pledges>=10) Game.Unlock('Sacrificial rolling pins');
  3103.  
  3104. if (!Game.HasAchiev('Cookie-dunker') && l('bigCookie').getBoundingClientRect().bottom>l('milk').getBoundingClientRect().top+16 && Game.milkProgress>0.1) Game.Win('Cookie-dunker');
  3105. }
  3106.  
  3107. Game.cookiesd+=(Game.cookies-Game.cookiesd)*0.3;
  3108.  
  3109. if (Game.storeToRebuild) Game.RebuildStore();
  3110. if (Game.upgradesToRebuild) Game.RebuildUpgrades();
  3111.  
  3112. if (Game.T%(Game.fps)==0) document.title=Beautify(Game.cookies)+' '+(Game.cookies==1?'cookie':'cookies')+' - Cookie Clicker';
  3113.  
  3114. Game.TickerAge--;
  3115. if (Game.TickerAge<=0 || Game.Ticker=='') Game.getNewTicker();
  3116.  
  3117. var veilLimit=0;//10;
  3118. if (Game.veil==1 && Game.cookiesEarned>=veilLimit) Game.veilOff();
  3119. else if (Game.veil==0 && Game.cookiesEarned<veilLimit) Game.veilOn();
  3120.  
  3121. Game.goldenCookie.update();
  3122.  
  3123. if (Game.T%(Game.fps*60)==0 && Game.T>Game.fps*10 && Game.prefs.autosave) Game.WriteSave();
  3124. if (Game.T%(Game.fps*60*30)==0 && Game.T>Game.fps*10 && Game.prefs.autoupdate) Game.CheckUpdates();
  3125.  
  3126. Game.T++;
  3127. }
  3128.  
  3129. /*=====================================================================================
  3130. DRAW
  3131. =======================================================================================*/
  3132. Game.Draw=function()
  3133. {
  3134. if (Math.floor(Game.T%Game.fps/4)==0) Game.DrawGrandmapocalypse();
  3135.  
  3136. //handle milk and milk accessories
  3137. if (Game.prefs.milk)
  3138. {
  3139. var x=Math.floor((Game.T*2+Math.sin(Game.T*0.1)*2+Math.sin(Game.T*0.03)*2-(Game.milkH-Game.milkHd)*2000)%480);
  3140. var y=0;
  3141. var m1=l('milkLayer1');
  3142. var m2=l('milkLayer2');
  3143. m1.style.backgroundPosition=x+'px '+y+'px';
  3144. m2.style.backgroundPosition=x+'px '+y+'px';
  3145. l('milk').style.height=(Game.milkHd*100)+'%';
  3146. var m1o=1;
  3147. var m2o=0;
  3148. var m1i='milkWave';
  3149. var m2i='chocolateMilkWave';
  3150. if (Game.milkProgress<1) {m1o=1;m1i='milkWave';m2i='chocolateMilkWave';}
  3151. else if (Game.milkProgress<2) {m1o=1-(Game.milkProgress-1);m1i='milkWave';m2i='chocolateMilkWave';}
  3152. else if (Game.milkProgress<3) {m1o=1-(Game.milkProgress-2);m1i='chocolateMilkWave';m2i='raspberryWave';}
  3153. else {m1o=1;m1i='raspberryWave';m2i='raspberryWave';}
  3154. m2o=1-m1o;
  3155. if (m1.style.backgroundImage!='url(img/'+m1i+'.png') m1.style.backgroundImage='url(img/'+m1i+'.png)';
  3156. if (m2.style.backgroundImage!='url(img/'+m2i+'.png') m2.style.backgroundImage='url(img/'+m2i+'.png)';
  3157. m1.style.opacity=m1o;
  3158. m2.style.opacity=m2o;
  3159. }
  3160.  
  3161. if (Game.prefs.particles)
  3162. {
  3163. //shine
  3164. var r=Math.floor((Game.T*0.5)%360);
  3165. var me=l('cookieShine');
  3166. me.style.transform='rotate('+r+'deg)';
  3167. me.style.mozTransform='rotate('+r+'deg)';
  3168. me.style.webkitTransform='rotate('+r+'deg)';
  3169. me.style.msTransform='rotate('+r+'deg)';
  3170. me.style.oTransform='rotate('+r+'deg)';
  3171.  
  3172. //cursors
  3173. var r=((-Game.T*0.05)%360);
  3174. var me=l('cookieCursors');
  3175. me.style.transform='rotate('+r+'deg)';
  3176. me.style.mozTransform='rotate('+r+'deg)';
  3177. me.style.webkitTransform='rotate('+r+'deg)';
  3178. me.style.msTransform='rotate('+r+'deg)';
  3179. me.style.oTransform='rotate('+r+'deg)';
  3180. }
  3181.  
  3182.  
  3183. //handle cursors
  3184.  
  3185. if (Game.prefs.particles)
  3186. {
  3187. var amount=Game.Objects['Cursor'].amount;
  3188. for (var i=0;i<amount;i++)
  3189. {
  3190. var me=l('cursor'+i);
  3191. /*
  3192. var w=132;
  3193. w+=Math.pow(Math.sin(((Game.T*0.05+(i/amount)*Game.fps)%Game.fps)/Game.fps*Math.PI*3),2)*15+5;
  3194. var x=Math.floor(Math.sin((i/amount)*Math.PI*2)*w)-16;
  3195. var y=Math.floor(Math.cos((i/amount)*Math.PI*2)*w)-16;
  3196. */
  3197. var n=Math.floor(i/50);
  3198. var a=((i+0.5*n)%50)/50;
  3199. var w=0;
  3200. w=(Math.sin(Game.T*0.025+(((i+n*12)%25)/25)*Math.PI*2));
  3201. if (w>0.997) w=1.5;
  3202. else if (w>0.994) w=0.5;
  3203. else w=0;
  3204. w*=-4;
  3205. //w+=Math.pow(Math.sin(((Game.T*0.05+(i/amount)*Game.fps)%Game.fps)/Game.fps*Math.PI*3),2)*15+5;
  3206.  
  3207. var x=(Math.sin(a*Math.PI*2)*(140+n*16+w))-16;
  3208. var y=(Math.cos(a*Math.PI*2)*(140+n*16+w))-16;
  3209. var r=Math.floor(-(a)*360);
  3210. me.style.left=x+'px';
  3211. me.style.top=y+'px';
  3212. }
  3213. }
  3214.  
  3215. //handle cookies
  3216. if (Game.prefs.particles)
  3217. {
  3218. if (Game.elderWrathD<=1.5)
  3219. {
  3220. if (Game.cookiesPs>=1000) l('cookieShower').style.backgroundImage='url(img/cookieShower3.png)';
  3221. else if (Game.cookiesPs>=500) l('cookieShower').style.backgroundImage='url(img/cookieShower2.png)';
  3222. else if (Game.cookiesPs>=50) l('cookieShower').style.backgroundImage='url(img/cookieShower1.png)';
  3223. else l('cookieShower').style.backgroundImage='none';
  3224. l('cookieShower').style.backgroundPosition='0px '+(Math.floor(Game.T*2)%512)+'px';
  3225. }
  3226. if (Game.elderWrathD>=1 && Game.elderWrathD<1.5) l('cookieShower').style.opacity=1-((Game.elderWrathD-1)/0.5);
  3227. }
  3228.  
  3229. var unit=(Math.round(Game.cookiesd)==1?' cookie':' cookies');
  3230. if (Math.round(Game.cookiesd).toString().length>11) unit='<br>cookies';
  3231. l('cookies').innerHTML=Beautify(Math.round(Game.cookiesd))+unit+'<div style="font-size:50%;">per second : '+Beautify(Game.cookiesPs,1)+'</div>';//display cookie amount
  3232.  
  3233. /*
  3234. var el=l('bigCookie');
  3235. var s=Math.pow(Math.min(1,Game.cookies/100000),0.5)*1+0.5;
  3236. el.style.transform='scale('+s+')';
  3237. el.style.mozTransform='scale('+s+')';
  3238. el.style.webkitTransform='scale('+s+')';
  3239. el.style.msTransform='scale('+s+')';
  3240. el.style.oTransform='scale('+s+')';
  3241. */
  3242.  
  3243. Game.TickerDraw();
  3244.  
  3245. for (var i in Game.Objects)
  3246. {
  3247. var me=Game.Objects[i];
  3248.  
  3249. //make products full-opacity if we can buy them
  3250. if (Game.cookies>=me.price) l('product'+me.id).className='product enabled'; else l('product'+me.id).className='product disabled';
  3251.  
  3252. //update object info
  3253. if (l('rowInfo'+me.id) && Game.T%5==0) l('rowInfoContent'+me.id).innerHTML='&bull; '+me.amount+' '+(me.amount==1?me.single:me.plural)+'<br>&bull; producing '+Beautify(me.storedTotalCps,1)+' '+(me.storedTotalCps==1?'cookie':'cookies')+' per second<br>&bull; total : '+Beautify(me.totalCookies)+' '+(Math.floor(me.totalCookies)==1?'cookie':'cookies')+' '+me.actionName;
  3254. }
  3255.  
  3256. //make upgrades full-opacity if we can buy them
  3257. for (var i in Game.UpgradesInStore)
  3258. {
  3259. var me=Game.UpgradesInStore[i];
  3260. if (Game.cookies>=me.basePrice) l('upgrade'+i).className='crate upgrade enabled'; else l('upgrade'+i).className='crate upgrade disabled';
  3261. }
  3262.  
  3263. if (Math.floor(Game.T%Game.fps/2)==0) Game.UpdateMenu();
  3264.  
  3265. Game.cookieParticlesUpdate();
  3266. Game.cookieNumbersUpdate();
  3267. Game.particlesUpdate();
  3268. }
  3269.  
  3270. /*=====================================================================================
  3271. MAIN LOOP
  3272. =======================================================================================*/
  3273. Game.Loop=function()
  3274. {
  3275. //update game logic !
  3276. Game.catchupLogic=0;
  3277. Game.Logic();
  3278. Game.catchupLogic=1;
  3279.  
  3280. //latency compensator
  3281. Game.accumulatedDelay+=((new Date().getTime()-Game.time)-1000/Game.fps);
  3282. Game.accumulatedDelay=Math.min(Game.accumulatedDelay,1000*5);//don't compensate over 5 seconds; if you do, something's probably very wrong
  3283. Game.time=new Date().getTime();
  3284. while (Game.accumulatedDelay>0)
  3285. {
  3286. Game.Logic();
  3287. Game.accumulatedDelay-=1000/Game.fps;//as long as we're detecting latency (slower than target fps), execute logic (this makes drawing slower but makes the logic behave closer to correct target fps)
  3288. }
  3289. Game.catchupLogic=0;
  3290.  
  3291. Game.Draw();
  3292.  
  3293. setTimeout(Game.Loop,1000/Game.fps);
  3294. }
  3295. }
  3296.  
  3297.  
  3298. /*=====================================================================================
  3299. LAUNCH THIS THING
  3300. =======================================================================================*/
  3301. Game.Launch();
  3302.  
  3303. window.onload=function()
  3304. {
  3305. if (!Game.ready) Game.Init();
  3306. };
Add Comment
Please, Sign In to add comment