Skip to content

Commit

Permalink
Final attempt to solve the NMR/CD option in gamecreate...
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleepcap committed Aug 19, 2012
1 parent e42a269 commit 0aad631
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 25 deletions.
7 changes: 4 additions & 3 deletions gamecreate.php
Expand Up @@ -146,12 +146,13 @@
$input['targetSCs'] = (int)$input['targetSCs'];
$input['countryID'] = (int)$input['countryID'];

if ( $input['specialCDturn'] == '∞' ) $input['specialCDturn'] = 999;
$input['specialCDturn'] = (int)$input['specialCDturn'];
if ( $input['specialCDturn'] < 0 ) $input['specialCDturn'] = 0;
if ( $input['specialCDturn'] < 0 ) $input['specialCDturn'] = 0;
if ( $input['specialCDturn'] > 99 ) $input['specialCDturn'] = 99;

$input['specialCDcount'] = (int)$input['specialCDcount'];
if ( $input['specialCDcount'] < 0 ) $input['specialCDcount'] = 0;
if ( $input['specialCDcount'] < 0 ) $input['specialCDcount'] = 0;
if ( $input['specialCDcount'] > 99 ) $input['specialCDcount'] = 99;

// Create Game record & object
require_once('gamemaster/game.php');
Expand Down
9 changes: 5 additions & 4 deletions gamepanel/game.php
Expand Up @@ -263,16 +263,17 @@ function gameVariants() {
$alternatives[]='WTA';

// The NMR-policy defaults
if( $this->specialCDturn != Config::$specialCDturnsDefault && $this->specialCDcount != Config::$specialCDcountDefault && $this->specialCDturn >= $this->turn)
if( ($this->specialCDturn != Config::$specialCDturnsDefault || $this->specialCDcount != Config::$specialCDcountDefault) && $this->specialCDturn >= $this->turn)
{
if ( $this->specialCDturn == 0 && $this->specialCDcount == 0 )
if ( $this->specialCDturn == 0 )
$alternatives[]='NMR: Off';
elseif( $this->specialCDturn == 5 && $this->specialCDcount == 2 )
$alternatives[]='NMR: Committed';
elseif( $this->specialCDturn == 99 && $this->specialCDcount == 5 )
elseif( $this->specialCDturn > 90 && $this->specialCDcount > 90 )
$alternatives[]='NMR: Serious';
else
$alternatives[]='NMR:'.$this->specialCDturn.'/'.$this->specialCDcount;

$alternatives[]='NMR:'.($this->specialCDturn > 90 ? '&infin;' : $this->specialCDturn).'/'.($this->specialCDcount > 90 ? '&infin;' : ($this->specialCDcount == 0 ? 'off' : $this->specialCDcount));
}

// Show the end of the game in the options if set.
Expand Down
63 changes: 47 additions & 16 deletions locales/English/gamecreate.php
Expand Up @@ -307,34 +307,66 @@ function changeMinPhases(i){
NMR policy:
</li>
<li class="formlistfield">
<?php
$specialCDturnsTxt = ( Config::$specialCDturnsDefault == 0 ? 'off' : (Config::$specialCDturnsDefault > 99 ? '&infin;' : Config::$specialCDturnsDefault) );
$specialCDcountTxt = ( Config::$specialCDcountDefault == 0 ? 'off' : (Config::$specialCDcountDefault > 99 ? '&infin;' : Config::$specialCDcountDefault) );
?>

<input type="hidden" id="specialCDturn" name="newGame[specialCDturn]" value="<?php print $specialCDturnsTxt;?>">
<input type="hidden" id="specialCDcount" name="newGame[specialCDcount]" value="<?php print $specialCDcountTxt;?>">

<select id="NMRpolicy" name="newGame[NMRpolicy]"
onChange="
opt = this.value.split('/');
document.getElementById('specialCDturn').value = opt[0];
document.getElementById('specialCDcount').value = opt[1];
if (this.value == '0/0') {
if (this.value == 'c/c') {
$('NMRpolicyCustom').show();
$('NMRpolicyText').hide();
} else {
$('NMRpolicyCustom').hide();
opt = this.value.split('/');
document.getElementById('specialCDturn').value = opt[0];
document.getElementById('specialCDcount').value = opt[1];
if (opt[0] == 0) opt[0] = 'off'; if (opt[0] > 90) opt[0] = '&infin;';
if (opt[1] == 0) opt[1] = 'off'; if (opt[1] > 90) opt[1] = '&infin;';
document.getElementById('specialCDturnCustom').value = opt[0];
document.getElementById('specialCDcountCustom').value = opt[1];
document.getElementById('NMRpolicyText').innerHTML = ' - Turns: <b>' + opt[0] + '</b> - Delay: <b>' + opt[1] + '</b>';
$('NMRpolicyCustom').hide();
$('NMRpolicyText').show();
}
">
<option value="off/off">Off</option>
<option value="<?php print Config::$specialCDturnsDefault;?>/<?php print Config::$specialCDcountDefault;?>" selected>Default</option>
<option value="0/0">Off</option>
<option value="<?php print $specialCDturnsTxt;?>/<?php print $specialCDcountTxt;?>" selected>Default</option>
<option value="5/2">Committed</option>
<option value="99/5">Serious</option>
<option value="0/0">Custom</option>
<option value="99/99">Serious</option>
<option value="c/c">Custom</option>
</select>


<span id="NMRpolicyCustom" style="display:none">
- Turns: </b><input type="text" id="specialCDturn" onChange="document.getElementById('NMRpolicy').selectedIndex = 4;" name="newGame[specialCDturn]" size="2" value="<?php print Config::$specialCDturnsDefault;?>">
- Delay: </b><input type="text" id="specialCDcount" onChange="document.getElementById('NMRpolicy').selectedIndex = 4;" name="newGame[specialCDcount]" size="2" value="<?php print Config::$specialCDcountDefault;?>">
- Turns: </b><input
type="text"
id="specialCDturnCustom"
size="2"
value='<?php print $specialCDturnsTxt; ?>'
onkeypress="if (event.keyCode==13) this.blur(); return event.keyCode!=13"
onChange="document.getElementById('NMRpolicy').selectedIndex = 4;
document.getElementById('specialCDturn').value = this.value;
if (this.value > 90) this.value = '&infin;';
if (this.value == 0) this.value = 'off';"
>
- Delay: </b><input
type="text"
id="specialCDcountCustom"
value = '<?php print $specialCDcountTxt; ?>'
onkeypress="if (event.keyCode==13) this.blur(); return event.keyCode!=13"
onChange="document.getElementById('NMRpolicy').selectedIndex = 4;
document.getElementById('specialCDcount').value = this.value;
if (this.value > 90) this.value = '&infin;';
if (this.value == 0) this.value = 'off';"
size="2"
>
</span>
<span id="NMRpolicyText">
- Turns: <b><?php print Config::$specialCDturnsDefault;?></b>
- Delay: <b><?php print Config::$specialCDcountDefault;?></b>
- Turns: <b><?php print $specialCDturnsTxt;?></b> - Delay: <b><?php print $specialCDcountTxt;?></b>
</span>
</li>
<li class="formlistdesc">
Expand All @@ -343,8 +375,7 @@ function changeMinPhases(i){
<li><strong>Turns:</strong> How many turns this action will be in effect for.</li>
<li><strong>Delay:</strong> How much time to advertise and find a replacement player (the current phase will be extended by the current phase length that many times).</li>
</ul>
<strong>Attention:</strong> A custom entered "0" for deleay will <u>not</u> turn this feature off, but delay the processing till a replacement is found.
<br /><br /><strong>Default:</strong> <?php print Config::$specialCDturnsDefault;?> / <?php print Config::$specialCDcountDefault;?>
<br /><strong>Default:</strong> <?php print $specialCDturnsTxt;?> / <?php print $specialCDcountTxt;?>
</li>

<li class="formlisttitle">
Expand Down
4 changes: 2 additions & 2 deletions objects/game.php
Expand Up @@ -557,7 +557,7 @@ function needsProcess()
$search = 'Missing orders for '.$this->Variant->turnAsDate($this->turn).' ('.$this->phase.')';
$sql='SELECT COUNT(*) FROM wD_GameMessages WHERE message LIKE "%'.$search.'%" AND toCountryID = 0 AND fromCountryID = 0 AND gameID='.$this->id;
list($extCount)=$DB->sql_row($sql);
if ($extCount < $this->specialCDcount || $this->specialCDcount == 0)
if ($extCount < $this->specialCDcount || $this->specialCDcount > 90)
{
$this->processTime = time() + $this->phaseMinutes*60;
$this->minimumBet = $this->Members->pointsLowestCD();
Expand All @@ -568,7 +568,7 @@ function needsProcess()
WHERE id = ".$this->id);
$gameMasterText = 'Missing orders for '.$this->Variant->turnAsDate($this->turn).' ('.$this->phase.'). Extending phase.';
$repeat = $this->specialCDcount - $extCount - 1;
if ($this->specialCDcount == 0)
if ($this->specialCDcount > 90)
$gameMasterText .= 'The phase will extend again till you find a replacement.';
elseif ($repeat > 0)
$gameMasterText .= 'The phase will extend '.$repeat.' time'.($repeat > 1 ? 's':'').' again if you do not find a replacement.';
Expand Down

0 comments on commit 0aad631

Please sign in to comment.