A call costs: ${esc(words.join('; '))}.
` +
- `A call costs:
` +
+ `${esc(`${words.join('; ')}.`)}
${callKinds(c, name, what)}
` +
+ ``
);
}
@@ -141,7 +178,7 @@ function dayHTML(hh, mine) {
function dayClick(b, hh) {
const d = b.dataset;
if (d.plan === 'callAsk') {
- calling = +d.member;
+ calling = { member: +d.member, key: d.key === undefined ? null : d.key };
return undefined;
}
if (d.plan === 'callNo') {
@@ -150,7 +187,8 @@ function dayClick(b, hh) {
}
if (d.plan === 'call') {
calling = null;
- return Sim.head(st, st.player.pawn, 'call', d.urgent ? { member: +d.member, urgent: true } : { member: +d.member });
+ const args = d.key === undefined ? { member: +d.member } : { member: +d.member, key: d.key };
+ return Sim.head(st, st.player.pawn, 'call', d.urgent ? { ...args, urgent: true } : args);
}
if (d.plan === 'dayOrder')
return Sim.head(st, st.player.pawn, 'dayOrder', { member: +d.member, from: +d.from, to: +d.to });
diff --git a/src/sim/agents.js b/src/sim/agents.js
index fe4cafc4..378404d9 100644
--- a/src/sim/agents.js
+++ b/src/sim/agents.js
@@ -5,7 +5,7 @@ VB['sim/agents'] = (() => {
const { unbound, atWork } = VB['sim/pose'];
const { living, commanded } = VB['sim/records'];
const { isOpen } = VB['sim/kinds'];
- const { register } = VB['sim/commands'];
+ const { register, issue } = VB['sim/commands'];
const { cal, DAY, TICKS, WORK } = VB['sim/rules'];
const { eligible } = VB['sim/eligibility'];
const Carts = VB['sim/carts'];
@@ -177,6 +177,7 @@ VB['sim/agents'] = (() => {
}
delete a.errand;
delete a.sentHome;
+ delete a.calledTo;
unbind(a);
if (left) rerate(st, left); // a hand gone: the end is told again; the goal stays posted while it is wanted (VB-1812)
a.basis = null;
@@ -367,10 +368,19 @@ VB['sim/agents'] = (() => {
// The hours a pawn may work now: the working day, or past it a task lived by (VB-1547) or the player's command, and never a day owed
// already given (VB-1813: one rule for the day's end and the day given).
const mayWork = (st, a, j) => {
- if (dayGiven(st, a) || a.sentHome) return false;
+ if (dayGiven(st, a) || a.sentHome || a.calledTo) return false;
const h = cal(st.t).hour;
return (h >= WORK[0] && h < WORK[1]) || carriedOn(st, j) || commanded(st, a.id);
};
+ // A call answered (VB-1926; design.md, A load in hand): pawn a, called while it had a load in hand and the call not urgent, has brought
+ // the load in and let its task go; it now sets out for the task it was called to, if that is still open to it and the hours allow. Whether
+ // it did.
+ function answer(st, a, call) {
+ if (!call || a.path || !st.pawns[a.id].alive || a.away !== undefined) return false;
+ const j = st.jobs.get(call.key);
+ if (!j || !mayWork(st, a, j)) return false;
+ return issue(st, { actor: a.id, verb: 'work', target: call.key, source: 'planner' }) === true;
+ }
function onward(st, a, depth = 0) {
const j = a.job,
g = Doing.goalOf(st, a),
@@ -383,8 +393,11 @@ VB['sim/agents'] = (() => {
if (st.jobs.get(j.key) === j) dropJob(st, j);
a.job = null;
a.basis = null;
+ const call = a.calledTo;
+ delete a.calledTo;
unbind(a);
a.inside = false;
+ if (answer(st, a, call)) return;
// past the working day, free, it goes in, as one whose load came in does (arrived; VB-1812: a goal met at its work leg)
if ((given || h >= WORK[1] || h < WORK[0]) && !a.path && a.away === undefined && st.pawns[a.id].alive)
goHome(st, a);
@@ -401,7 +414,9 @@ VB['sim/agents'] = (() => {
if (s.blocked || depth > 8 || (!carrying && !mayWork(st, a, j))) {
// nothing it can do now (the reason is the step's), or the day is over: it lets the task go, which stays posted while wanted
if (s.blocked && st.jobs.get(j.key) === j && j.claims.length <= 1) dropJob(st, j);
+ const call = a.calledTo;
release(st, a);
+ if (answer(st, a, call)) return;
if (given && !a.path && !a.inside && unbound(a) && a.away === undefined) goHome(st, a); // its day given, home
return;
}
@@ -689,7 +704,15 @@ VB['sim/agents'] = (() => {
slot = attentionOf(j);
if (slot !== 'full')
hold(st, a, j); // a charge is minded beside the pawn's task (VB-251, VB-1750)
- else {
+ else if (c.args && c.args.call && !c.args.urgent && a.job && a.job !== j && a.load > 0 && !a.inside) {
+ // a head's call that is not urgent, to a hand with a load of another task in hand (VB-1926; design.md, A load in hand): the load is
+ // brought to its body's store first, by the rule, and the hand then sets out for the task called (answer), aiming to be there by
+ // args.by. An urgent call, or one to a hand with nothing in hand, sends it now: a load is set down where it stands (release).
+ // @state agent.calledTo (VB-1926): absent, or {key, by} of the head's call that waits for the load in hand to be brought in: the
+ // task called and the game time the hand aims to be at it. Written only here; cleared by release and when answered (onward).
+ a.calledTo = { key: j.key, by: Number.isFinite(c.args.by) ? c.args.by : st.t };
+ return { slot: 'call', key: j.key };
+ } else {
release(st, a);
// @state agent.opener (VB-1761): who opened the task in hand, 'head' (the planner's command: the head's allotment, call or duty)
// or 'pawn' (its own, or the player's); read only by its legs' `by` (sim/legs). Written only here.
@@ -703,6 +726,7 @@ VB['sim/agents'] = (() => {
},
active: (st, c, ref) => {
const a = st.agents[c.actor];
+ if (ref && ref.slot === 'call') return !!a.calledTo && a.calledTo.key === ref.key; // the load first; then a work command of its own
if (ref) return holds(a, ref);
return inSlot(a, 'full', c.target) || inSlot(a, 'mind', c.target);
},
@@ -739,6 +763,7 @@ VB['sim/agents'] = (() => {
// on (its caller says so, urgent): the load is put down where it stands, as release does.
if (a.job && a.load > 0 && !(c.args && c.args.urgent) && !a.inside) {
a.sentHome = true;
+ delete a.calledTo; // a call home after a call to a task stands in its place (VB-1926 review, F1)
return { home: 'after the load' };
}
if (a.job) release(st, a);
diff --git a/src/sim/day.js b/src/sim/day.js
index 1e7c7a9a..5c473b62 100644
--- a/src/sim/day.js
+++ b/src/sim/day.js
@@ -390,14 +390,15 @@ VB['sim/day'] = (() => {
// The head calls member p (design.md section 7, The head calls): to `dj`, the task with a deadline today it is the hand for, from work,
// from the road or from idling; else from its work to `top`, the first of its list, when that is much more urgent (switchRatio,
// switchMargin; VB-107).
+ // A call is not urgent (VB-1926; design.md, A load in hand): one with a load in hand brings it in first and comes after (the verb work,
+ // args.call). No rule of the head's marks a call urgent; the head that is played does, by its verb (call, args.urgent).
function call(st, hh, p, dj, top, c, memo, stand) {
const a = st.agents[p.id],
busy = !!a.job && attentionOf(a.job) === 'full';
if (a.taking > st.tick) return; // keeping hours of its levy for itself (breach)
if (dj && a.job !== dj && isOpen(st, dj) && c.hour <= WORK[1]) {
// the deadline calls: from work, from the road to it, or from idling (waiting, or out for company; not at an occasion)
- if (busy ? a.job && !(a.load > 0) : !a.job && unbound(a) && a.occasion === null)
- issue(st, workCommand(a.id, dj.key, 'planner'));
+ if (busy ? !a.calledTo : !a.job && unbound(a) && a.occasion === null) issue(st, calling(st, a.id, dj.key, false));
return;
}
if (!top || !busy || !atWork(a) || a.job === top[1] || !isOpen(st, top[1])) return;
@@ -408,6 +409,12 @@ VB['sim/day'] = (() => {
)
issue(st, workCommand(a.id, top[1].key, 'planner'));
}
+ // The head's call of member id to task `key`: the work command, marked a call (urgent or not) for the load in hand (sim/agents work).
+ // Not urgent, the member aims to be at it within MATCH.day.within hours (args.by).
+ const calling = (st, id, key, urgent) => ({
+ ...workCommand(id, key, 'planner'),
+ args: { call: true, urgent: !!urgent, by: st.t + MATCH.day.within },
+ });
// ---- the slot (VB-1558; design.md section 7, The day's work: "a task the due-queue opens in the day is weighed alone") ----
// Task j, newly due for household hh, put into the day's lists as they stand: each member allotted is weighed for it alone, and the pass
// of the allotment (man) gives it hands by its fit among the tasks already there and within the members' hours left (plan.day.free); a
@@ -926,8 +933,10 @@ VB['sim/day'] = (() => {
if (day.lists && day.lists[id] && day.lists[id].includes(c.args.key)) return 0;
return pastLevy(st, hh, id, h, day);
}
- // call({member, key}) (VB-1779): the member is called to task `key` now, from work, from the road home or from idling, as the head's
- // call (design.md section 7, The head calls): a work command the head opened. Past its levy left a demand (above).
+ // call({member, key, urgent}) (VB-1779): the member is called to task `key`, from work, from the road home or from idling, as the head's
+ // call (design.md section 7, The head calls): a work command the head opened. Not urgent (the default), a load in hand is brought to its
+ // body's store first and the member then comes, aiming to be there within MATCH.day.within hours; urgent, the load is set down where it
+ // stands, a pile, and the member comes now (VB-1926). Past its levy left a demand (above), either kind: the demand's yes calls again.
// call({member}): the member is called off: its list is emptied and it is off (plan.day.off) until the day is next allotted, and it lets its
// task go and walks home (the verb goHome: a load in hand is brought in first, or on an urgent call
// (args.urgent) put down where it stands, VB-1893). The cost, its walk home and
@@ -952,7 +961,7 @@ VB['sim/day'] = (() => {
const past = c.args.demand === true ? callPast(st, c) : 0;
if (past > 1e-9) return demand(st, c, c.args.member, past);
edited(st, planOf(st, 'household', c.target).day, c);
- return issue(st, workCommand(c.args.member, c.args.key, 'planner'));
+ return issue(st, calling(st, c.args.member, c.args.key, c.args.urgent));
}
const plan = planOf(st, 'household', c.target),
day = plan.day,
diff --git a/src/sim/reasons.js b/src/sim/reasons.js
index 1cf510bd..f3614c31 100644
--- a/src/sim/reasons.js
+++ b/src/sim/reasons.js
@@ -115,6 +115,17 @@ VB['sim/reasons'] = (() => {
const played = !!st.player && st.player.pawn === id;
if (commanded(st, id))
return played ? { by: 'player', why: 'you gave the order' } : { by: 'self', why: 'an order of its own' };
+ if (a.calledTo && a.job) {
+ // called, not urgently, with a load in hand (VB-1926; design.md, A load in hand): the load first, then the task called
+ const to = st.jobs.get(a.calledTo.key),
+ m = Math.round(cal(a.calledTo.by).hour * 60) % (24 * 60),
+ by = `${String(Math.floor(m / 60)).padStart(2, '0')}:${String(m % 60).padStart(2, '0')}`;
+ return {
+ by: 'call',
+ head,
+ why: `brings its load in first, then ${to ? KINDS[to.kind].label.toLowerCase() : 'the task called'}, aiming to be there by ${by}`,
+ };
+ }
if (j) {
const K = KINDS[j.kind],
why = cause(st, j, c),
diff --git a/src/sim/roles.js b/src/sim/roles.js
index 5001af31..6a7815f8 100644
--- a/src/sim/roles.js
+++ b/src/sim/roles.js
@@ -170,7 +170,10 @@ VB['sim/roles'] = (() => {
// (VB-1547): the hour after the end of work past which no task is begun, even of a kind that may be begun in the evening (the
// water, sim/kinds `evening`): 20:00, so that a half-hour fetch is home before the dark at every season (sim/rules dark: 21:00 at
// its earliest, midwinter).
- day: { horizon: 0.5, afternoon: 14, evening: 20 },
+ // `within` (VB-1926): the hours within which a member called while it has a load in hand, the call not urgent, aims to be at the
+ // task it is called to, its load brought in first (design.md, A load in hand): a target its plan aims at, shown on its card; nothing
+ // lapses if it is later.
+ day: { horizon: 0.5, afternoon: 14, evening: 20, within: 1 },
floor: 0.1, // a good fit (priority above poorFit) always bids at least the floor
distanceWeight: 0.15,
join: 0.8,
diff --git a/src/sim/timetable.js b/src/sim/timetable.js
index bf5d97f9..ac578d46 100644
--- a/src/sim/timetable.js
+++ b/src/sim/timetable.js
@@ -131,8 +131,10 @@ VB['sim/timetable'] = (() => {
// What calling member id off costs, as pawn `viewer` reckons it (the household's head when null), named before the call (the verb
// call, sim/day): walk, the hours of its walk home from where it stands; load, what it carries home now and would put down where it
// stands (0 when none); task, the key of its task in hand (or null) and left, the viewer's range of that task's hours left with its hands
- // ({lo, mid, hi}, or null).
- function callCost(st, id, viewer = null) {
+ // ({lo, mid, hi}, or null). With `key`, the call is to that task (VB-1926): to, its key; come, the hours until the member is at it, not
+ // urgent (the load brought in first, then the walk out from home) and urgent (straight from where it stands): {calm, now}, or null for
+ // a task gone.
+ function callCost(st, id, viewer = null, key = null) {
const p = st.pawns[id],
a = st.agents[id],
hh = p.household === null ? null : st.households[p.household];
@@ -142,9 +144,14 @@ VB['sim/timetable'] = (() => {
house = st.farmsteads[hh.farmstead].house,
j = a.job,
left = j && attentionOf(j) === 'full' ? Estimate.estimate(st, who, j) : null;
- const walk = a.inside ? 0 : walkHours(st, tileOf(st, id), house),
- load = a.load > 0 ? a.load : 0;
+ const at = tileOf(st, id),
+ walk = a.inside ? 0 : walkHours(st, at, house),
+ load = a.load > 0 ? a.load : 0,
+ to = key === null || key === undefined ? null : st.jobs.get(key),
+ now = to ? walkHours(st, at, to.site) : 0,
+ come = to && { calm: load > 0 ? walk + walkHours(st, house, to.site) : now, now };
return {
+ ...(key === null || key === undefined ? {} : { to: key, come: come || null }),
walk,
load,
// a call that is not urgent brings the load in first: about when the hand is in (hours; the walk to the store is the walk home,
diff --git a/tests/browser.js b/tests/browser.js
index f5de1d41..ffe11413 100644
--- a/tests/browser.js
+++ b/tests/browser.js
@@ -392,9 +392,12 @@ const errors = [], fail = (m) => { errors.push(m); console.error('BROWSER FAIL:'
{
await page.waitForSelector('#tileHouse .day-row', { timeout: 5000 }).catch(() => fail('the Plan tab shows no row of the day'));
if (!/by your reckoning/.test(await page.locator('#tileHouse').textContent())) fail('the day does not say whose reckoning its ranges are');
- await page.locator('#tileHouse [data-plan="callAsk"]').first().click();
+ await page.locator('#tileHouse [data-plan="callAsk"]:not([data-key])').first().click();
const cost = await page.locator('#tileHouse .day-cost').textContent().catch(() => '');
- if (!/A call costs: .*(walks home|is at home).*(carries)/.test(cost)) fail(`no cost named before the call: ${cost}`);
+ if (!/A call costs:.*(walks home|is at home).*(carries)/.test(cost)) fail(`no cost named before the call: ${cost}`);
+ // VB-1926: the call's kinds, each an icon and its label, the sentence one tap in
+ if (!(await page.locator('#tileHouse .day-cost .day-kind summary svg, #tileHouse .day-cost .day-kind summary img').count()))
+ fail('the call names its kind by no icon');
await page.click('#tileHouse [data-plan="callNo"]');
if (await page.locator('#tileHouse .day-cost').count()) fail('the cost stays after Leave at work');
const down = page.locator('#tileHouse [data-plan="dayOrder"][aria-label^="Leave"]:not([disabled])');
diff --git a/tests/lib/invariants.js b/tests/lib/invariants.js
index 5e6d4c30..c1ff9979 100644
--- a/tests/lib/invariants.js
+++ b/tests/lib/invariants.js
@@ -213,6 +213,9 @@ function checkState(st) {
for (const a of st.agents) {
// VB-1779: a breach's hours run to a tick (agent.taking); the goodwill gathered toward the head is under a ration, owed to a pawn
if (a && a.taking !== undefined && !Number.isFinite(a.taking)) bad.push(`agents[${a.id}].taking: ${a.taking}`);
+ // VB-1926: a call that waits for a load in hand (agent.calledTo {key, by}) is held only by a hand with a task in hand
+ if (a && a.calledTo !== undefined && (!a.job || typeof a.calledTo.key !== 'string' || !Number.isFinite(a.calledTo.by)))
+ bad.push(`agents[${a.id}].calledTo: ${JSON.stringify(a.calledTo)} with ${a.job ? 'a task' : 'no task'} in hand`);
const r = a && a.book;
if (!r) continue;
if (r.gw !== undefined && (!(Math.abs(r.gw) < 1 + 1e-9) || !st.pawns[r.gwTo])) bad.push(`agents[${a.id}].book.gw: ${r.gw} toward ${r.gwTo}`);
diff --git a/tests/methods.js b/tests/methods.js
index ed1b2380..906a75c6 100644
--- a/tests/methods.js
+++ b/tests/methods.js
@@ -947,6 +947,113 @@ console.log(
}
assert.deepStrictEqual(checkState(st), [], 'invariants');
}
+ // VB-1926: the head calls a member with a load in hand to another task (the verb call, {member, key}): not urgent, the load reaches the
+ // store before the member is at the task called, which it aims to reach within MATCH.day.within; urgent, the load lies as a titled pile
+ // where it stood and the member is there sooner
+ const came = {};
+ for (const urgent of [false, true]) {
+ const st = make(),
+ hh = st.households[0],
+ f = st.farmsteads[hh.farmstead],
+ forest = st.villages[f.village].wood[0];
+ while (cal(st.t).hour < WORK[0] + 1 || cal(st.t).hour > WORK[0] + 3) Sim.advance(st, 0.2);
+ const day = st.plans.households.get(hh.id).day,
+ a = members(st, hh).find((b) => !b.job && !b.path && b.id !== hh.holder && day.lists[b.id]);
+ assert(a, 'a member with a list in the day');
+ setAt(st, a, forest);
+ Object.assign(a, { load: TRAVEL.load, carry: 'logs' });
+ const j = Jobs.post(st, `test:wood:h${hh.id}`, 'wood', title(hh), forest, {
+ farm: f,
+ chosen: false,
+ amount: 9 * P(st),
+ }),
+ fd = f.fields[0];
+ fd.stage = 'stubble';
+ const to = Jobs.post(st, `test:plow:h${hh.id}`, 'plow', title(hh), fd.tile, { field: fd, farm: f });
+ const t0 = hh.timber || 0;
+ Agents.start(st, a, j);
+ Sim.advance(st, 0.1);
+ const at = here(st, a),
+ t1 = st.t;
+ const r = Sim.head(st, hh.holder, 'call', {
+ member: a.id,
+ key: to.key,
+ ...(urgent ? { urgent: true } : {}),
+ demand: true,
+ });
+ assert.strictEqual(r, true, `the call is made: ${r}`);
+ if (urgent) {
+ assert(
+ a.load === 0 && a.job === to && !a.calledTo,
+ `urgent: it comes now: ${a.load} ${a.job && a.job.key} ${JSON.stringify(a.calledTo)}`,
+ );
+ assert(
+ Lying.amountAt(st, at, 'wood', title(hh)) === TRAVEL.load,
+ 'the load lies as a pile with title where it stood',
+ );
+ } else {
+ assert(a.load > 0 && a.job === j && a.calledTo && a.calledTo.key === to.key, 'not urgent: the load first');
+ assert(
+ Math.abs(a.calledTo.by - t1 - VB['sim/roles'].MATCH.day.within) < 1e-9,
+ 'aiming to be there within the hour',
+ );
+ assert(
+ /brings its load in first/.test(Sim.reasonLine(st, a.id)),
+ `its card says so: ${Sim.reasonLine(st, a.id)}`,
+ );
+ }
+ let home = null;
+ for (let i = 0; i < 80 && !(a.job === to && VB['sim/pose'].atWork(a)); i++) {
+ Sim.advance(st, 0.1);
+ if (home === null && (hh.timber || 0) > t0) home = st.t;
+ }
+ assert(a.job === to && VB['sim/pose'].atWork(a), `at the task called (urgent ${urgent})`);
+ came[urgent] = st.t - t1;
+ if (!urgent)
+ assert(came[urgent] <= VB['sim/roles'].MATCH.day.within + 0.25, `there within about the hour: ${came[urgent]} h`);
+ if (!urgent) {
+ assert(home !== null && home <= t1 + came[urgent], 'the load reached the store before the member came');
+ assert(!(st.lying || []).some((l) => l.owner.id === hh.id && l.kind === 'wood'), 'nothing set down on the way');
+ }
+ assert.deepStrictEqual(checkState(st), [], 'invariants');
+ }
+ assert(came[true] < came[false], `urgent, it is there sooner (${came[true]} h, against ${came[false]} h)`);
+ // VB-1926 review, F1: a call home after a call to a task that waits for the load stands in its place: once the load is in the member
+ // goes in, and does not set out for the task called
+ {
+ const st = make(),
+ hh = st.households[0],
+ f = st.farmsteads[hh.farmstead],
+ forest = st.villages[f.village].wood[0];
+ while (cal(st.t).hour < WORK[0] + 1 || cal(st.t).hour > WORK[0] + 3) Sim.advance(st, 0.2);
+ const day = st.plans.households.get(hh.id).day,
+ a = members(st, hh).find((b) => !b.job && !b.path && b.id !== hh.holder && day.lists[b.id]);
+ setAt(st, a, forest);
+ Object.assign(a, { load: TRAVEL.load, carry: 'logs' });
+ const j = Jobs.post(st, `test:wood:h${hh.id}`, 'wood', title(hh), forest, {
+ farm: f,
+ chosen: false,
+ amount: 9 * P(st),
+ }),
+ fd = f.fields[0];
+ fd.stage = 'stubble';
+ const to = Jobs.post(st, `test:plow:h${hh.id}`, 'plow', title(hh), fd.tile, { field: fd, farm: f });
+ Agents.start(st, a, j);
+ Sim.advance(st, 0.1);
+ assert.strictEqual(
+ Sim.head(st, hh.holder, 'call', { member: a.id, key: to.key, demand: true }),
+ true,
+ 'called to the task',
+ );
+ assert(a.calledTo, 'the load first');
+ assert.strictEqual(Sim.head(st, hh.holder, 'call', { member: a.id }), true, 'then called home');
+ for (let i = 0; i < 60 && !(a.inside && a.load === 0); i++) Sim.advance(st, 0.1);
+ assert(
+ a.inside && a.job !== to && !a.calledTo,
+ `called home, it goes in: job ${a.job && a.job.key}, inside ${a.inside}`,
+ );
+ assert.deepStrictEqual(checkState(st), [], 'invariants');
+ }
console.log(
'methods: the wood in a real state: the five rows, the felled pile, a load in hand, the stray pile, no fetch kind',
);