summaryrefslogtreecommitdiff
path: root/play.js
blob: 1c6165b387e28625c649afd958d49984af3a4c57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
"use strict";

const CLEOPATRA = "Cleopatra";
const DEAD = "Dead";
const LEVY = "Levy";
const ENEMY = { "Caesar": "Pompeius", "Pompeius": "Caesar" };

let label_style = window.localStorage['julius-caesar/label-style'] || 'columbia';
let label_layout = window.localStorage['julius-caesar/label-layout'] || 'spread';

function toggle_blocks() {
	document.getElementById("blocks").classList.toggle("hide_blocks");
}

function set_simple_labels() {
	label_style = 'simple';
	document.getElementById("blocks").classList.remove("columbia-labels");
	document.getElementById("battle").classList.remove("columbia-labels");
	document.getElementById("blocks").classList.add("simple-labels");
	document.getElementById("battle").classList.add("simple-labels");
	window.localStorage['julius-caesar/label-style'] = label_style;
	update_map();
}

function set_columbia_labels() {
	label_style = 'columbia';
	document.getElementById("blocks").classList.remove("simple-labels");
	document.getElementById("battle").classList.remove("simple-labels");
	document.getElementById("blocks").classList.add("columbia-labels");
	document.getElementById("battle").classList.add("columbia-labels");
	window.localStorage['julius-caesar/label-style'] = label_style;
	update_map();
}

function set_spread_layout() {
	label_layout = 'spread';
	window.localStorage['julius-caesar/label-layout'] = label_layout;
	update_map();
}

function set_stack_layout() {
	label_layout = 'stack';
	window.localStorage['julius-caesar/label-layout'] = label_layout;
	update_map();
}

// Levy and hit animations for 'simple' blocks.
const step_down_animation = [
		{ transform: 'translateY(0px)' },
		{ transform: 'translateY(10px)' },
		{ transform: 'translateY(0px)' },
];
const step_up_animation = [
		{ transform: 'translateY(0px)' },
		{ transform: 'translateY(-10px)' },
		{ transform: 'translateY(0px)' },
];

let ui = {
	cards: {},
	card_backs: {},
	spaces: {},
	blocks: {},
	battle_menu: {},
	battle_block: {},
	old_steps: null,
	old_location: null,
	present: new Set(),
};

function on_log(text) {
	let p = document.createElement("div");
	text = text.replace(/&/g, "&");
	text = text.replace(/</g, "&lt;");
	text = text.replace(/>/g, "&gt;");

	text = text.replace(/\u2192 /g, "\u2192\xa0");
	text = text.replace(/Mare /g, "Mare\xa0");

	text = text.replace(/^([A-Z]):/, '<span class="$1"> $1 </span>');

	if (text.match(/^~ .* ~$/))
		p.className = 'br', text = text.substring(2, text.length-2);
	else if (text.match(/^Start Caesar/))
		p.className = 'C';
	else if (text.match(/^Start Pompeius/))
		p.className = 'P';
	else if (text.match(/^Start /))
		p.className = 'st', text = text.replace(/\.$/, "");
	else if (text.match(/^Battle in/))
		p.className = 'bs';

	if (text.match(/^Start /))
		text = text.substring(6);

	p.innerHTML = text;
	return p;
}

function on_focus_space(evt) {
	document.getElementById("status").textContent = evt.target.space;
}

function on_blur_space(evt) {
	document.getElementById("status").textContent = "";
}

function on_click_space(evt) {
	send_action('space', evt.target.space);
}

const STEPS = [ 0, "I", "II", "III", "IIII" ];

function block_description(b) {
	if (is_known_block(b)) {
		let s = BLOCKS[b].steps;
		let c = BLOCKS[b].initiative + BLOCKS[b].firepower;
		let levy = BLOCKS[b].levy;
		if (levy)
			return BLOCKS[b].name + " (" + levy + ") " + STEPS[s] + "-" + c;
		return BLOCKS[b].name + " " + STEPS[s] + "-" + c;
	}
	return block_owner(b);
}

function block_owner(who) {
	if (who in view.owner)
		return view.owner[who];
	return BLOCKS[who].owner;
}

function block_name(b) {
	return BLOCKS[b].name;
}

function on_focus_map_block(evt) {
	document.getElementById("status").textContent = block_description(evt.target.block);
}

function on_blur_map_block(evt) {
	document.getElementById("status").textContent = "";
}

function on_focus_battle_block(evt) {
	let b = evt.target.block;
	let msg = block_name(b);
	if (!evt.target.classList.contains("known"))
		msg = "Reserves";

	if (view.actions && view.actions.battle_fire && view.actions.battle_fire.includes(b))
		msg = "Fire with " + msg;
	else if (view.actions && view.actions.battle_retreat && view.actions.battle_retreat.includes(b))
		msg = "Retreat with " + msg;
	else if (view.actions && view.actions.battle_hit && view.actions.battle_hit.includes(b))
		msg = "Take hit on " + msg;

	document.getElementById("status").textContent = msg;
}

function on_blur_battle_block(evt) {
	document.getElementById("status").textContent = "";
}

function on_focus_battle_fire(evt) {
	document.getElementById("status").textContent =
		"Fire with " + block_name(evt.target.block);
}

function on_focus_battle_retreat(evt) {
	document.getElementById("status").textContent =
		"Retreat with " + block_name(evt.target.block);
}

function on_focus_battle_pass(evt) {
	document.getElementById("status").textContent =
		"Pass with " + block_name(evt.target.block);
}

function on_focus_battle_hit(evt) {
	document.getElementById("status").textContent =
		"Take hit on " + block_name(evt.target.block);
}

function on_blur_battle_button(evt) {
	document.getElementById("status").textContent = "";
}

function on_click_battle_block(evt) { send_action('block', evt.target.block); }
function on_click_battle_hit(evt) { send_action('battle_hit', evt.target.block); }
function on_click_battle_fire(evt) { send_action('battle_fire', evt.target.block); }
function on_click_battle_retreat(evt) { send_action('battle_retreat', evt.target.block); }

function on_click_battle_pass(evt) {
	if (window.confirm("Are you sure that you want to PASS with " + block_name(evt.target.block) + "?"))
		send_action('battle_pass', evt.target.block);
}

function on_click_map_block(evt) {
	let b = evt.target.block;
	let s = view.location[b];
	if (view.actions && view.actions.secret && view.actions.secret.includes(s))
		send_action('secret', [s, BLOCKS[b].color]);
	else if (!view.battle)
		send_action('block', b);
}

function build_map() {
	// These must match up with the sizes in play.html
	const city_size = 60+10;
	const sea_size = 70+10;

	ui.blocks_element = document.getElementById("blocks");
	ui.offmap_element = document.getElementById("offmap");
	ui.spaces_element = document.getElementById("spaces");

	for (let s in SPACES) {
		let space = SPACES[s];
		let element = document.createElement("div");
		element.classList.add("space");
		let size = (space.type === 'sea') ? sea_size : city_size;
		if (space.type === "sea")
			element.classList.add("sea");
		else
			element.classList.add("city");
		element.setAttribute("draggable", "false");
		element.addEventListener("mouseenter", on_focus_space);
		element.addEventListener("mouseleave", on_blur_space);
		element.addEventListener("click", on_click_space);
		element.style.left = (space.x - size/2) + "px";
		element.style.top = (space.y - size/2) + "px";
		if (space.type !== 'pool')
			document.getElementById("spaces").appendChild(element);
		element.space = s;
		ui.spaces[s] = element;
	}

	function build_map_block(b, block) {
		let element = document.createElement("div");
		element.classList.add("block");
		element.classList.add("known");
		element.classList.add(block.color);
		element.classList.add("block_"+block.label);
		element.addEventListener("mouseenter", on_focus_map_block);
		element.addEventListener("mouseleave", on_blur_map_block);
		element.addEventListener("click", on_click_map_block);
		element.block = b;
		ui.blocks[b] = element;
	}

	function build_battle_button(menu, b, c, click, enter, img_src) {
		let img = new Image();
		img.draggable = false;
		img.classList.add("action");
		img.classList.add(c);
		img.setAttribute("src", img_src);
		img.addEventListener("click", click);
		img.addEventListener("mouseenter", enter);
		img.addEventListener("mouseleave", on_blur_battle_button);
		img.block = b;
		menu.appendChild(img);
	}

	function build_battle_block(b, block) {
		let element = document.createElement("div");
		element.classList.add("block");
		element.classList.add(block.color);
		element.classList.add("block_"+block.label);
		element.addEventListener("mouseenter", on_focus_battle_block);
		element.addEventListener("mouseleave", on_blur_battle_block);
		element.addEventListener("click", on_click_battle_block);
		element.block = b;
		ui.battle_block[b] = element;

		let action_list = document.createElement("div");
		action_list.classList.add("battle_menu_list");
		action_list.appendChild(element);
		build_battle_button(action_list, b, "hit",
			on_click_battle_hit, on_focus_battle_hit,
			"/images/cross-mark.svg");
		build_battle_button(action_list, b, "fire",
			on_click_battle_fire, on_focus_battle_fire,
			"/images/pointy-sword.svg");
		build_battle_button(action_list, b, "retreat",
			on_click_battle_retreat, on_focus_battle_retreat,
			"/images/flying-flag.svg");
		build_battle_button(action_list, b, "pass",
			on_click_battle_pass, on_focus_battle_pass,
			"/images/sands-of-time.svg");

		let menu = document.createElement("div");
		menu.classList.add("battle_menu");
		menu.appendChild(element);
		menu.appendChild(action_list);
		menu.block = b;
		ui.battle_menu[b] = menu;
	}

	for (let b in BLOCKS) {
		let block = BLOCKS[b];
		block.color = (block.name === "Cleopatra" ? "Cleopatra" : block.owner);
		build_map_block(b, block);
		build_battle_block(b, block);
	}

	for (let c = 1; c <= 27; ++c)
		ui.cards[c] = document.getElementById("card+" + c);
	for (let c = 1; c <= 6; ++c)
		ui.card_backs[c] = document.getElementById("back+" + c);
}

function update_steps(block, element, animate) {
	let old_steps = ui.old_steps[block] || view.steps[block];
	let steps = view.steps[block];
	if (view.location[block] !== ui.old_location[block])
		animate = false;

	if (label_style === 'simple' && steps !== old_steps && animate) {
		let options = { duration: 700, easing: 'ease', iterations: Math.abs(steps-old_steps) }
		if (steps < old_steps)
			element.animate(step_down_animation, options);
		if (steps > old_steps)
			element.animate(step_up_animation, options);
	}

	element.classList.remove("r0");
	element.classList.remove("r1");
	element.classList.remove("r2");
	element.classList.remove("r3");
	element.classList.add("r"+(BLOCKS[block].steps - steps));
}

function layout_blocks(location, north, south) {
	if (label_layout === 'spread' || (location === LEVY || location === DEAD))
		layout_blocks_spread(location, north, south);
	else
		layout_blocks_stacked(location, north, south);
}

function layout_blocks_spread(location, north, south) {
	let wrap = SPACES[location].wrap;
	let s = north.length;
	let k = south.length;
	let n = s + k;
	let row, rows = [];
	let i = 0;

	function new_line() {
		rows.push(row = []);
		i = 0;
	}

	new_line();

	while (north.length > 0) {
		if (i === wrap)
			new_line();
		row.push(north.shift());
		++i;
	}

	// Break early if north and south fit in exactly two rows and more than two blocks.
	if (s > 0 && s <= wrap && k > 0 && k <= wrap && n > 2)
		new_line();

	while (south.length > 0) {
		if (i === wrap)
			new_line();
		row.push(south.shift());
		++i;
	}

	if (SPACES[location].layout_minor > 0.5)
		rows.reverse();

	for (let j = 0; j < rows.length; ++j)
		for (i = 0; i < rows[j].length; ++i)
			position_block_spread(location, j, rows.length, i, rows[j].length, rows[j][i]);
}

function position_block_spread(location, row, n_rows, col, n_cols, element) {
	let space = SPACES[location];
	let block_size = (label_style === 'columbia') ? 56+6 : 48+4;
	let padding = (location === LEVY || location === DEAD) ? 6 : 3;
	let offset = block_size + padding;
	let row_size = (n_rows-1) * offset;
	let col_size = (n_cols-1) * offset;
	let x = space.x - block_size/2;
	let y = space.y - block_size/2;

	if (space.layout_axis === 'X') {
		x -= col_size * space.layout_major;
		y -= row_size * space.layout_minor;
		x += col * offset;
		y += row * offset;
	} else {
		y -= col_size * space.layout_major;
		x -= row_size * space.layout_minor;
		y += col * offset;
		x += row * offset;
	}

	element.style.left = (x|0)+"px";
	element.style.top = (y|0)+"px";
}

function layout_blocks_stacked(location, secret, known) {
	let s = secret.length;
	let k = known.length;
	let both = secret.length > 0 && known.length > 0;
	let i = 0;
	while (secret.length > 0)
		position_block_stacked(location, i++, (s-1)/2, both ? 1 : 0, secret.shift());
	i = 0;
	while (known.length > 0)
		position_block_stacked(location, i++, (k-1)/2, 0, known.shift());
}

function position_block_stacked(location, i, c, k, element) {
	let space = SPACES[location];
	let block_size = (label_style === 'columbia') ? 56+6 : 48+4;
	let x = space.x + (i - c) * 16 + k * 12;
	let y = space.y + (i - c) * 16 - k * 12;
	element.style.left = ((x - block_size/2)|0)+"px";
	element.style.top = ((y - block_size/2)|0)+"px";
}

function show_block(element) {
	if (element.parentElement !== ui.blocks_element)
		ui.blocks_element.appendChild(element);
}

function hide_block(element) {
	if (element.parentElement !== ui.offmap_element)
		ui.offmap_element.appendChild(element);
}

function is_known_block(who) {
	if (view.game_over && player === 'Observer')
		return true;
	if (block_owner(who) === player)
		return true;
	let where = view.location[who];
	if (where === DEAD)
		return true;
	return false;
}

function is_visible_block(where, who) {
	if (view.game_over && player === 'Observer')
		return true;
	if (where === "Levy")
		return block_owner(who) === player;
	return true;
}

function update_map() {
	let layout = {};

	for (let s in SPACES)
		layout[s] = { north: [], south: [] };

	for (let b in view.location) {
		let info = BLOCKS[b];
		let element = ui.blocks[b];
		let space = view.location[b];
		if (is_visible_block(space, b)) {
			let moved = view.moved[b] ? " moved" : "";
			if (space === DEAD && info.type !== 'leader')
				moved = " moved";
			if (is_known_block(b)) {
				let image = " block_" + info.label;
				let known = " known";
				let jupiter = "";
				if (block_owner(b) !== BLOCKS[b].owner && view.game_over)
					jupiter = " jupiter";
				element.classList = info.color + known + " block" + image + moved + jupiter;
				update_steps(b, element, true);
			} else {
				let jupiter = "";
				let mars = "";
				let neptune = "";
				if (block_owner(b) !== BLOCKS[b].owner)
					jupiter = " jupiter";
				if (block_owner(b) === view.mars && space === view.surprise)
					mars = " mars";
				if (block_owner(b) === view.neptune && space === view.surprise)
					neptune = " neptune";
				element.classList = info.color + " block" + moved + jupiter + mars + neptune;
			}
			if (block_owner(b) === CAESAR)
				layout[space].north.push(element);
			else
				layout[space].south.push(element);
			show_block(element);
		} else {
			hide_block(element);
		}
	}

	for (let space in SPACES)
		layout_blocks(space, layout[space].north, layout[space].south);

	// Mark selections and highlights

	for (let where in SPACES) {
		if (ui.spaces[where]) {
			ui.spaces[where].classList.remove('highlight');
			ui.spaces[where].classList.remove('where');
		}
	}
	if (view.actions && view.actions.space)
		for (let where of view.actions.space)
			ui.spaces[where].classList.add('highlight');

	for (let b in BLOCKS) {
		ui.blocks[b].classList.remove('highlight');
		ui.blocks[b].classList.remove('selected');
	}
	if (!view.battle) {
		if (view.actions && view.actions.block)
			for (let b of view.actions.block)
				ui.blocks[b].classList.add('highlight');
		if (view.who)
			ui.blocks[view.who].classList.add('selected');
	}

	for (let b in BLOCKS) {
		let s = view.location[b];
		if (view.actions && view.actions.secret && view.actions.secret.includes(s))
			ui.blocks[b].classList.add('highlight');
	}
}

function compare_blocks(a, b, ballista) {
	let aa = BLOCKS[a].initiative;
	let bb = BLOCKS[b].initiative;
	if (aa === 'X') aa = ballista;
	if (bb === 'X') bb = ballista;
	if (aa === bb) {
		aa = BLOCKS[a].label;
		bb = BLOCKS[b].label;
	}
	return (aa < bb) ? -1 : (aa > bb) ? 1 : 0;
}

function sort_battle_row(root, ballista) {
	let swapped;
	let children = root.children;
	do {
		swapped = false;
		for (let i = 1; i < children.length; ++i) {
			if (compare_blocks(children[i-1].block, children[i].block, ballista) > 0) {
				children[i].after(children[i-1]);
				swapped = true;
			}
		}
	} while (swapped);
}

function update_battle() {
	function fill_cell(name, list, reserve, ballista) {
		let cell = window[name];

		ui.present.clear();

		for (let block of list) {
			ui.present.add(block);

			if (!cell.contains(ui.battle_menu[block]))
				cell.appendChild(ui.battle_menu[block]);

			if (block === view.who)
				ui.battle_menu[block].classList.add("selected");
			else
				ui.battle_menu[block].classList.remove("selected");

			ui.battle_block[block].classList.remove("highlight");
			ui.battle_menu[block].classList.remove('hit');
			ui.battle_menu[block].classList.remove('fire');
			ui.battle_menu[block].classList.remove('retreat');
			ui.battle_menu[block].classList.remove('pass');

			if (view.actions && view.actions.block && view.actions.block.includes(block))
				ui.battle_block[block].classList.add("highlight");
			if (view.actions && view.actions.battle_fire && view.actions.battle_fire.includes(block))
				ui.battle_menu[block].classList.add('fire');
			if (view.actions && view.actions.battle_retreat && view.actions.battle_retreat.includes(block))
				ui.battle_menu[block].classList.add('retreat');
			if (view.actions && view.actions.battle_pass && view.actions.battle_pass.includes(block))
				ui.battle_menu[block].classList.add('pass');
			if (view.actions && view.actions.battle_hit && view.actions.battle_hit.includes(block))
				ui.battle_menu[block].classList.add('hit');

			update_steps(block, ui.battle_block[block], true);
			if (reserve)
				ui.battle_block[block].classList.add("secret");
			else
				ui.battle_block[block].classList.remove("secret");
			if (view.moved[block] || reserve)
				ui.battle_block[block].classList.add("moved");
			else
				ui.battle_block[block].classList.remove("moved");
			if (reserve)
				ui.battle_block[block].classList.remove("known");
			else
				ui.battle_block[block].classList.add("known");
		}

		for (let b in BLOCKS) {
			if (!ui.present.has(b)) {
				if (cell.contains(ui.battle_menu[b]))
					cell.removeChild(ui.battle_menu[b]);
			}
		}

		sort_battle_row(cell, ballista);
	}

	if (player === CAESAR) {
		fill_cell("FR", view.battle.CR, true, 'B');
		fill_cell("FF", view.battle.CF, false, view.battle.A === CAESAR ? 'D' : 'B');
		fill_cell("EF", view.battle.PF, false, view.battle.A === CAESAR ? 'B' : 'D');
		fill_cell("ER", view.battle.PR, true, 'B');
	} else {
		fill_cell("FR", view.battle.PR, true, 'B');
		fill_cell("FF", view.battle.PF, false, view.battle.A === POMPEIUS ? 'D' : 'B');
		fill_cell("EF", view.battle.CF, false, view.battle.A === POMPEIUS ? 'B' : 'D');
		fill_cell("ER", view.battle.CR, true, 'B');
	}
}

function update_card_display(element, card, prior_card) {
	if (!card && !prior_card) {
		element.className = "show card card_back";
	} else if (prior_card) {
		element.className = "show card prior card_" + CARDS[prior_card].image;
	} else {
		element.className = "show card card_" + CARDS[card].image;
	}
}

function update_cards() {
	update_card_display(document.getElementById("caesar_card"), view.c_card, view.prior_c_card);
	update_card_display(document.getElementById("pompeius_card"), view.p_card, view.prior_p_card);

	for (let c = 1; c <= 27; ++c) {
		let element = ui.cards[c];
		if (view.hand.includes(c)) {
			element.classList.add("show");
			if (view.actions && view.actions.card) {
				if (view.actions.card.includes(c)) {
					element.classList.add("enabled");
					element.classList.remove("disabled");
				} else {
					element.classList.remove("enabled");
					element.classList.add("disabled");
				}
			} else {
				element.classList.remove("enabled");
				element.classList.remove("disabled");
			}
		} else {
			element.classList.remove("show");
		}
	}

	let n = view.hand.length;
	for (let c = 1; c <= 6; ++c)
		if (c <= n && player === 'Observer')
			ui.card_backs[c].classList.add("show");
		else
			ui.card_backs[c].classList.remove("show");
}

function on_update() {
	if (!ui.old_steps) {
		ui.old_steps = view.steps;
		ui.old_location = view.location;
	}

	document.getElementById("turn").className = "year_" + view.year;
	document.getElementById("caesar_vp").textContent = view.c_vp + " VP";
	document.getElementById("pompeius_vp").textContent = view.p_vp + " VP";
	if (view.turn < 1)
		document.getElementById("turn_info").textContent = `Year ${view.year}`;
	else
		document.getElementById("turn_info").textContent = `Turn ${view.turn} of Year ${view.year}`;

	action_button("surprise", "Surprise!");
	action_button("pass");
	action_button("undo", "Undo");

	update_cards();
	update_map();

	if (view.battle) {
		document.getElementById("battle_header").textContent = view.battle.title;
		document.getElementById("battle_message").textContent = view.battle.flash;
		document.getElementById("battle").classList.add("show");
		update_battle();
	} else {
		document.getElementById("battle").classList.remove("show");
	}

	ui.old_location = Object.assign({}, view.location);
	ui.old_steps = Object.assign({}, view.steps);
}

function select_card(c) {
	send_action('card', c);
}

build_map();

document.getElementById("blocks").classList.add(label_style+'-labels');
document.getElementById("battle").classList.add(label_style+'-labels');

drag_element_with_mouse("#battle", "#battle_header");
scroll_with_middle_mouse("main");