Skip to content

Commit

Permalink
Fixed timer issues with queues
Browse files Browse the repository at this point in the history
  • Loading branch information
pmotschmann committed Oct 27, 2019
1 parent d384941 commit d537f8f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 28 deletions.
2 changes: 1 addition & 1 deletion dist/main.js

Large diffs are not rendered by default.

88 changes: 68 additions & 20 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9439,7 +9439,15 @@ export const actions = {
reqs: { unify: 1 },
grant: ['unify',2],
not_tech: ['m_boost'],
cost: {},
cost: {
Army(){
let rating = global.race['no_plasmid'] ? 525 : 600;
if (global.race['no_crispr']){
rating -= 75;
}
return rating;
}
},
effect(){ return `<div>${loc('tech_wc_conquest_effect')}</div><div class="has-text-special">${loc('tech_unification_warning')}</div>`; },
action(){
let rating = global.race['no_plasmid'] ? 525 : 600;
Expand Down Expand Up @@ -9472,7 +9480,15 @@ export const actions = {
reqs: { unify: 1 },
grant: ['unify',2],
not_tech: ['m_boost'],
cost: {},
cost: {
Morale(){
let morale = global.race['no_plasmid'] ? 140 : 150;
if (global.race['no_crispr']){
morale -= 10;
}
return morale;
}
},
effect(){
return `<div>${loc('tech_wc_morale_effect',[races[global.race.species].home])}</div><div class="has-text-special">${loc('tech_unification_warning')}</div>`;
},
Expand Down Expand Up @@ -9507,7 +9523,15 @@ export const actions = {
reqs: { unify: 1 },
grant: ['unify',2],
not_tech: ['m_boost'],
cost: {},
cost: {
Money(){
let price = global.race['no_plasmid'] ? 3000000 : 5000000;
if (global.race['no_crispr']){
price -= 1000000;
}
return price;
}
},
effect(){ return `<div>${loc('tech_wc_money_effect',[races[global.race.species].home])}</div><div class="has-text-special">${loc('tech_unification_warning')}</div>`; },
action(){
let price = global.race['no_plasmid'] ? 3000000 : 5000000;
Expand Down Expand Up @@ -10998,14 +11022,16 @@ function actionDesc(parent,c_action,obj,old){
if (c_action.cost && !old){
var cost = $('<div></div>');
var costs = adjustCosts(c_action.cost);
Object.keys(costs).forEach(function (res) {
var res_cost = costs[res]();
if (res_cost > 0){
let label = res === 'Money' ? '$' : global.resource[res].name+': ';
label = label.replace("_", " ");
let color = global.resource[res].amount >= res_cost ? 'has-text-dark' : 'has-text-danger';
let display_cost = sizeApproximation(res_cost,1);
cost.append($(`<div class="${color}" data-${res}="${res_cost}">${label}${display_cost}</div>`));
Object.keys(costs).forEach(function (res){
if (res !== 'Morale' && res !== 'Army'){
let res_cost = costs[res]();
if (res_cost > 0){
let label = res === 'Money' ? '$' : global.resource[res].name+': ';
label = label.replace("_", " ");
let color = global.resource[res].amount >= res_cost ? 'has-text-dark' : 'has-text-danger';
let display_cost = sizeApproximation(res_cost,1);
cost.append($(`<div class="${color}" data-${res}="${res_cost}">${label}${display_cost}</div>`));
}
}
});
parent.append(cost);
Expand Down Expand Up @@ -11067,10 +11093,12 @@ export function payCosts(costs){
costs = adjustCosts(costs);
if (checkCosts(costs)){
Object.keys(costs).forEach(function (res){
let cost = costs[res]();
global['resource'][res].amount -= cost;
if (res === 'Knowledge'){
global.stats.know += cost;
if (res !== 'Morale' && res !== 'Army'){
let cost = costs[res]();
global['resource'][res].amount -= cost;
if (res === 'Knowledge'){
global.stats.know += cost;
}
}
});
return true;
Expand All @@ -11093,8 +11121,18 @@ export function checkAffordable(c_action,max){
function checkMaxCosts(costs){
var test = true;
Object.keys(costs).forEach(function (res){
var testCost = Number(costs[res]()) || 0;
if (global.resource[res].max >= 0 && testCost > Number(global.resource[res].max) && Number(global.resource[res].max) !== -1) {
if (res !== 'Morale' && res !== 'Army'){
var testCost = Number(costs[res]()) || 0;
if (global.resource[res].max >= 0 && testCost > Number(global.resource[res].max) && Number(global.resource[res].max) !== -1) {
test = false;
return false;
}
}
else if (res === 'Morale' && global.city.morale.current < Number(costs[res]())){
test = false;
return false;
}
else if (res === 'Army' && armyRating(global.civic.garrison.raid,'army') < Number(costs[res]())){
test = false;
return false;
}
Expand All @@ -11105,9 +11143,19 @@ function checkMaxCosts(costs){
function checkCosts(costs){
var test = true;
Object.keys(costs).forEach(function (res){
var testCost = Number(costs[res]()) || 0;
let fail_max = global.resource[res].max >= 0 && testCost > global.resource[res].max ? true : false;
if (testCost > Number(global.resource[res].amount) + global.resource[res].diff || fail_max){
if (res !== 'Morale' && res !== 'Army'){
var testCost = Number(costs[res]()) || 0;
let fail_max = global.resource[res].max >= 0 && testCost > global.resource[res].max ? true : false;
if (testCost > Number(global.resource[res].amount) + global.resource[res].diff || fail_max){
test = false;
return false;
}
}
else if (res === 'Morale' && global.city.morale.current < Number(costs[res]())){
test = false;
return false;
}
else if (res === 'Army' && armyRating(global.civic.garrison.raid,'army') < Number(costs[res]())){
test = false;
return false;
}
Expand Down
15 changes: 10 additions & 5 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ export function timeCheck(c_action,track){
res_have = global.resource[res].max;
}
}
if (testCost > res_have && global.resource[res].diff > 0){
let r_time = (testCost - res_have) / global.resource[res].diff;
if (r_time > time){
time = r_time;
if (testCost > res_have){
if (global.resource[res].diff > 0){
let r_time = (testCost - res_have) / global.resource[res].diff;
if (r_time > time){
time = r_time;
}
}
else {
time = -1;
}
}
});
Expand All @@ -159,7 +164,7 @@ export function timeCheck(c_action,track){
export function timeFormat(time){
let formatted;
if (time < 0){
formatted = 'Never';
formatted = loc('time_never');
}
else {
time = +(time.toFixed(0));
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4030,7 +4030,7 @@ function midLoop(){
idx = i;
}
else {
time += timeCheck(t_action, global.settings.qAny ? { t: 0, r: {}} : spent);
time += global.settings.qAny ? timeCheck(t_action) : timeCheck(t_action, spent);
}
global.queue.queue[i]['time'] = time;
stop = global.settings.qAny ? false : true;
Expand Down Expand Up @@ -4097,7 +4097,7 @@ function midLoop(){
idx = i;
}
else {
time += timeCheck(t_action, global.settings.qAny ? { t: 0, r: {}} : spent);
time += global.settings.qAny ? timeCheck(t_action) : timeCheck(t_action, spent);
}
global.r_queue.queue[i]['time'] = time;
stop = global.settings.qAny ? false : true;
Expand Down

0 comments on commit d537f8f

Please sign in to comment.