/
gamecreate.php
executable file
·484 lines (432 loc) · 21.3 KB
/
gamecreate.php
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
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
defined('IN_CODE') or die('This script can not be run by itself.');
/**
* @package Base
* @subpackage Forms
*/
?>
<div class="content-bare content-board-header content-title-header">
<div class="pageTitle barAlt1">Create a new game</div>
<div class="pageDescription">Start a new customized game of Diplomacy.</div>
</div>
<div class="content content-follow-on">
<?php
// game creation tutorial
if (isset($_COOKIE['wD-Tutorial-GameCreate']))
{
$tutorialMessage = l_t('
This is the game creation page. In order to create a new game, you just need to fill out
the following form. These slides will give you a quick overview of what you need to think
about in order to make your game and make sure that you know what each setting you select
means.
<br>
On webDiplomacy, you can play games against humans or bots. If you want to play against other players,
you\'re in the right place. You can just fill out this form. If you want to play against bots,
you can click "Play a Game Against Bots." Our bots are artificial intelligence users, so they are not
computer players like you might encounter in online chess, for example. They are very unique and
they are trained rigorously based on the decisions real players made, which means they are both
intelligent and unpredictable. Give them a try sometime, you might be surprised how good they are!
<br>
You should first give your game an appropriate title, determine how much you want each player
to have to bet to join, and how long each phase would last. If you want to play a game that lasts
a few hours in the evening but takes your full attention, your phase length should be 5 or 10 minutes,
or a "live" game. If you want the game to take place over time instead of requiring your full attention
one night, pick a longer phase length, or a "non-live" game.
<br>
By default, your game has 7 days to fill. You can change that the time to fill game if you like, but the
important thing to know is that if you are creating a non-live game, your game will start when it is
filled, not when the time to fill expires. So, for example, if your non-live game has 7 days to fill
but is full within 3 days, it will start in 3 days, not 7. A live game will be "scheduled," meaning that
it will not start until the time to fill has expired, even if it fills early.
<br>
If you are playing with friends, family, or people you know outside of webDiplomacy, you are required
to set an invite code to your game. You can send this invite code to whoever you want to invite and know
that people who you do not want in your game will not accidentally join. If you are just looking for a
game with some other players, you do not need to add an invite code.
<br>
You also get to choose whether players can send messages or not, whether players are anonymized or
displayed, what map you want to play on, how the game should be scored, and more. For more information on
these settings, just click the "?" icon next to them on the form after you close this tutorial. Good luck!
');
libHTML::help('Create New Game', $tutorialMessage);
unset($_COOKIE['wD-Tutorial-GameCreate']);
setcookie('wD-Tutorial-GameCreate', '', time()-3600);
}
?>
<p><a href="botgamecreate.php">Play A Game Against Bots</a></p>
<div class = "gameCreateShow">
<form method="post">
<p>
<strong>Game Name:</strong></br>
<input class = "gameCreate" type="text" name="newGame[name]" value="" size="30">
</p>
<strong>Bet size: (5-<?php print $User->points.libHTML::points(); ?>)</strong>
<img id = "modBtnBet" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="betModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close5">×</span>
<p><strong>Bet:</strong> </br>
The bet required to join this game. This is the amount of points that all players, including you,
must put into the game's "pot" (<a href="points.php" class="light">read more</a>).<br /><br />
</p>
</div>
</div>
<input class = "gameCreate" type="text" name="newGame[bet]" size="7" value="<?php print $formPoints ?>" />
</br></br>
<strong>Phase length: (5 min - 10 days)</strong>
<img id = "modBtnPhaseLength" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="phaseLengthModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close4">×</span>
<p><strong>Phase Length: </strong></br>
How long each phase of the game will last in hours. Longer phase hours means a slow game with more time to talk.
Shorter phases require players be available to check the game frequently.
</p>
</div>
</div>
<select class = "gameCreate" name="newGame[phaseMinutes]" id="selectPhaseMinutes">
<?php
$phaseList = array(5,7, 10, 15, 20, 30, 60, 120, 240, 360, 480, 600, 720, 840, 960, 1080, 1200, 1320,
1440, 1440+60, 2160, 2880, 2880+60*2, 4320, 5760, 7200, 8640, 10080, 14400);
foreach ($phaseList as $i) { print '<option value="'.$i.'"'.($i==1440 ? ' selected' : '').'>'.libTime::timeLengthText($i*60).'</option>'; }
?>
</select>
<p id="phaseSwitchPeriodPara">
<strong>Time Until Phase Swap</strong></br>
<select class = "gameCreate" id="selectPhaseSwitchPeriod" name="newGame[phaseSwitchPeriod]">
<?php
$phaseList = array(-1, 10, 15, 20, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330, 360);
foreach ($phaseList as $i)
{
if ($i != -1)
{
print '<option value="'.$i.'"'.($i==-1 ? ' selected' : '').'>'.libTime::timeLengthText($i*60).'</option>';
}
else
{
print '<option value="'.$i.'"'.($i==-1 ? ' selected' : '').'> No phase switch</option>';
}
}
?>
</select>
</p>
<p id="nextPhaseMinutesPara">
<strong>Phase Length After Swap</strong></br>
<select class = "gameCreate" id="selectNextPhaseMinutes" name="newGame[nextPhaseMinutes]">
<?php
$phaseList = array(1440, 1440+60, 2160, 2880, 2880+60*2, 4320, 5760, 7200, 8640, 10080, 14400);
foreach ($phaseList as $i)
{
print '<option value="'.$i.'"'.($i==1440 ? ' selected' : '').'>'.libTime::timeLengthText($i*60).'</option>';
}
?>
</select>
</p>
<p>
<strong>Time to Fill Game: (5 min - 14 days)</strong></br>
<select class = "gameCreate" id="wait" name="newGame[joinPeriod]">
<?php
$phaseList = array(5,7, 10, 15, 20, 30, 60, 120, 240, 360, 480, 600, 720, 840, 960, 1080, 1200, 1320,
1440, 1440+60, 2160, 2880, 2880+60*2, 4320, 5760, 7200, 8640, 10080, 14400, 20160);
foreach ($phaseList as $i)
{
print '<option value="'.$i.'"'.($i==10080 ? ' selected' : '').'>'.libTime::timeLengthText($i*60).'</option>';
}
?>
</select>
</p>
<strong>Game Messaging:</strong>
<img id = "modBtnMessaging" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="messagingModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close7">×</span>
<p><strong>Game Messaging:</strong> </br>
The type of messaging allowed in a game.</br></br>
All: Global and Private Messaging allowed. </br></br>
Global Only: Only Global Messaging allowed.</br></br>
None: No messaging allowed.</br></br>
Rulebook: No messaging allowed during build and retreat phases.</br>
</p>
</div>
</div>
<select class = "gameCreate" id="pressType" name="newGame[pressType]" onchange="setBotFill()">
<option name="newGame[pressType]" value="Regular" selected>All </option>
<option name="newGame[pressType]" value="PublicPressOnly">Global only</option>
<option name="newGame[pressType]" value="NoPress">None (No messaging)</option>
<option name="newGame[pressType]" value="RulebookPress">Per rulebook</option>
</select>
</br></br>
<strong>Variant type (map choices):</strong>
<img id = "modBtnVariant" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="variantModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close3">×</span>
<p><strong>Variant:</strong> </br>
Type of Diplomacy game from a selection of maps and alternate rule settings available. Click any of the variant names to view the details on the variants page.
<br /><br />
<strong>Available variants:</strong> </br>
<?php
foreach(Config::$variants as $variantID=>$variantName)
{
if($variantID != 57)
{
$Variant = libVariant::loadFromVariantName($variantName);
print $Variant->link().'</br>';
}
}
?>
<br/>
*Please note that 1 vs 1 games will default to a 5 point bet as an unranked game no matter what bet/game type are selected.
</p>
</div>
</div>
<select id="variant" class = "gameCreate" name="newGame[variantID]" onchange="setBotFill()">
<?php
$first=true;
foreach(Config::$variants as $variantID=>$variantName)
{
if($variantID != 57)
{
$Variant = libVariant::loadFromVariantName($variantName);
if($first) { print '<option name="newGame[variantID]" selected value="'.$variantID.'">'.$variantName.'</option>'; }
else { print '<option name="newGame[variantID]" value="'.$variantID.'">'.$variantName.'</option>'; }
$first=false;
}
}
print '</select>';
?>
</br></br>
<div id="botFill" style="display:none">
<strong>Fill Empty Spots with Bots: </strong>
<img id = "modBtnBot" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="botModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close8">×</span>
<p><strong>Fill with Bots:</strong> </br>
If the game has at least 2 human players it will
fill with bots if there are empty spaces at the designated start time instead of being cancelled. This type
of game will default to a 5 point bet, unranked, and anonymous regardless of what settings you select. If the game
fills with 7 human players it will run just like any normal game and will be included in classic stats.
</p>
</div>
</div>
<input type="checkbox" id="botBox" class="gameCreate" name="newGame[botFill]" value="Yes">
</br></br>
</div>
<strong>Scoring:(<a href="points.php#DSS">See scoring types here</a>)</strong>
<img id = "modBtnScoring" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="scoringModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close2">×</span>
<p><strong>Scoring:</strong> </br>
This setting determines how points are split up if/when the game draws. <br/><br/>
In Draw-Size Scoring, the pot is split equally between the remaining players when the game draws (this setting used to be called WTA).
<br/><br/>
In Sum-of-Squares scoring, the pot is divided depending on how many centers you control when the game draws.
<br/><br/>
In both Draw-Size Scoring and Sum-of-Squares, any solo winner receieves the whole pot.
<br/><br/>
Unranked games have no effect on your points at the end of the game; your bet is refunded whether you won, drew or lost.
</p>
</div>
</div>
<select class = "gameCreate" name="newGame[potType]">
<option name="newGame[potType]" value="Winner-takes-all" selected>DSS (Equal split for draws)</option>
<option name="newGame[potType]" value="Sum-of-squares">SoS (Weighted split on draw)</option>
<option name="newGame[potType]" value="Unranked">Unranked</option>
</select></br></br>
<strong>Anonymous players: </strong>
<img id = "modBtnAnon" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="anonModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close6">×</span>
<p><strong>Anonymous players: </strong></br>
Decide if player names should be shown or hidden.</br></br> *Please note that games with no messaging are always anonymous regardless of what is set here to prevent cheating.
</p>
</div>
</div>
<select class = "gameCreate" name="newGame[anon]">
<option name="newGame[anon]" value="No" selected>No</option>
<option name="newGame[anon]" value="Yes">Yes</option>
</select>
<p>
<strong>Draw votes:</strong></br>
<select class = "gameCreate" name="newGame[drawType]">
<option name="newGame[drawType]" value="draw-votes-public" checked>Show draw votes</option>
<option name="newGame[drawType]" value="draw-votes-hidden">Hide draw votes</option>
</select>
</p>
<p>
<strong>Required reliability rating:</strong></br>
<input id="minRating" class = "gameCreate" type="text" name="newGame[minimumReliabilityRating]" size="2" value="<?php print $defaultRR ?>"
onkeypress="if (event.keyCode==13) this.blur(); return event.keyCode!=13"
onChange="
this.value = parseInt(this.value);
if (this.value == 'NaN' ) this.value = 0;
if (this.value < 0 ) this.value = 0;
if (this.value > <?php print $maxRR ?> ) this.value = <?php print $User->reliabilityRating ?>;"/>
</p>
<strong>Excused delays per player:</strong>
<img id = "modBtnDelays" height="16" width="16" src="images/icons/help.png" alt="Help" title="Help" />
<div id="delayModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close1">×</span>
<p><strong>Excused delays per player:</strong></br>
The number of excused delays before a player is removed from the game and can be replaced.
If a player is missing orders at a deadline, the deadline will reset and the player will be
charged 1 excused delay. If they are out of excuses they will go into Civil Disorder.
The game will only progress with missing orders if no replacement is found within one phase of a player being forced into Civil Disorder.
Set this value low to prevent delays to your game, set it higher to be more forgiving to people who might need occasional delays.
</p>
</div>
</div>
<select class = "gameCreate" id="NMR" name="newGame[excusedMissedTurns]">
<?php
for ($i=0; $i<=4; $i++) { print '<option value="'.$i.'"'.($i==1 ? ' selected' : '').'>'.$i.(($i==0)?' (strict)':'').'</option>'; }
?>
</select>
<p>
<img src="images/icons/lock.png" alt="Private" /> <strong>Add Invite Code (optional):</strong></br>
<input class = "gameCreate" type="password"autocomplete="new-password" name="newGame[password]" value="" size="20" /></br>
Confirm: <input class = "gameCreate" autocomplete="new-password" type="password" name="newGame[passwordcheck]" value="" size="20" /></br>
</p>
<p class="notice">
<input class = "green-Submit" type="submit" value="Create">
</p>
</br>
<?php
print libAuth::formTokenHTML();
?>
</form>
</div>
<script>
// Get the modal
var modal1 = document.getElementById('delayModal');
var modal2 = document.getElementById('scoringModal');
var modal3 = document.getElementById('variantModal');
var modal4 = document.getElementById('phaseLengthModal');
var modal5 = document.getElementById('betModal');
var modal6 = document.getElementById('anonModal');
var modal7 = document.getElementById('messagingModal');
var modal8 = document.getElementById('botModal');
// Get the button that opens the modal
var btn1 = document.getElementById("modBtnDelays");
var btn2 = document.getElementById("modBtnScoring");
var btn3 = document.getElementById("modBtnVariant");
var btn4 = document.getElementById("modBtnPhaseLength");
var btn5 = document.getElementById("modBtnBet");
var btn6 = document.getElementById("modBtnAnon");
var btn7 = document.getElementById("modBtnMessaging");
var btn8 = document.getElementById("modBtnBot");
// Get the <span> element that closes the modal
var span1 = document.getElementsByClassName("close1")[0];
var span2 = document.getElementsByClassName("close2")[0];
var span3 = document.getElementsByClassName("close3")[0];
var span4 = document.getElementsByClassName("close4")[0];
var span5 = document.getElementsByClassName("close5")[0];
var span6 = document.getElementsByClassName("close6")[0];
var span7 = document.getElementsByClassName("close7")[0];
var span8 = document.getElementsByClassName("close8")[0];
// When the user clicks the button, open the modal
btn1.onclick = function() { modal1.style.display = "block"; }
btn2.onclick = function() { modal2.style.display = "block"; }
btn3.onclick = function() { modal3.style.display = "block"; }
btn4.onclick = function() { modal4.style.display = "block"; }
btn5.onclick = function() { modal5.style.display = "block"; }
btn6.onclick = function() { modal6.style.display = "block"; }
btn7.onclick = function() { modal7.style.display = "block"; }
btn8.onclick = function() { modal8.style.display = "block"; }
// When the user clicks on <span> (x), close the modal
span1.onclick = function() { modal1.style.display = "none"; }
span2.onclick = function() { modal2.style.display = "none"; }
span3.onclick = function() { modal3.style.display = "none"; }
span4.onclick = function() { modal4.style.display = "none"; }
span5.onclick = function() { modal5.style.display = "none"; }
span6.onclick = function() { modal6.style.display = "none"; }
span7.onclick = function() { modal7.style.display = "none"; }
span8.onclick = function() { modal8.style.display = "none"; }
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal1) { modal1.style.display = "none"; }
if (event.target == modal2) { modal2.style.display = "none"; }
if (event.target == modal3) { modal3.style.display = "none"; }
if (event.target == modal4) { modal4.style.display = "none"; }
if (event.target == modal5) { modal5.style.display = "none"; }
if (event.target == modal6) { modal6.style.display = "none"; }
if (event.target == modal7) { modal7.style.display = "none"; }
if (event.target == modal8) { modal8.style.display = "none"; }
}
function setBotFill(){
content = document.getElementById("botFill");
ePress = document.getElementById("pressType");
pressType = ePress.options[ePress.selectedIndex].value;
eVariant = document.getElementById("variant");
variant = eVariant.options[eVariant.selectedIndex].value;
if (pressType == "NoPress" && variant == 1){
content.style.display = "block";
}
else{
content.style.display = "none";
document.getElementById("botBox").checked = false;
}
}
// Display nextPhaseMinutes paragraph only if phaseSwitchPeriod has selected a period.
nextPhaseMinutesPara = document.getElementById("nextPhaseMinutesPara");
selectPhaseSwitchPeriod = document.getElementById("selectPhaseSwitchPeriod");
phaseSwitchPeriodPara = document.getElementById("phaseSwitchPeriodPara");
selectPhaseMinutes = document.getElementById("selectPhaseMinutes");
nextPhaseMinutesPara.style.display = "none";
phaseSwitchPeriodPara.style.display = "none";
function updatePhasePeriod(){
if (selectPhaseMinutes.value > 60){
phaseSwitchPeriodPara.style.display = "none";
nextPhaseMinutesPara.style.display = "none";
}
else{
phaseSwitchPeriodPara.style.display = "block";
if (selectPhaseSwitchPeriod.value == -1){
nextPhaseMinutesPara.style.display = "none";
}
else{
nextPhaseMinutesPara.style.display = "block";
}
}
var phaseLength = parseInt(selectPhaseMinutes.value);
for (i = 0; i < selectPhaseSwitchPeriod.length; i++){
var optVal = parseInt(selectPhaseSwitchPeriod.options[i].value);
if (optVal <= 0 || optVal > phaseLength){
selectPhaseSwitchPeriod.options[i].hidden = false;
selectPhaseSwitchPeriod.options[i].disabled = false;
}
else{
selectPhaseSwitchPeriod.options[i].hidden = true;
selectPhaseSwitchPeriod.options[i].disabled = true;
}
}
}
selectPhaseSwitchPeriod.addEventListener("change", updatePhasePeriod)
selectPhaseMinutes.addEventListener("change", updatePhasePeriod)
</script>
<?php libHTML::$footerIncludes[] = l_j('help.js'); ?>