Permalink
Browse files

Adjustment to loyalty automation - previous system had a chance of ne…

…ver updating loyalty value for dual accounts (etc) where the village is loaded more than once an hour and thus lastupdate in vdata table would never be more than 3600 seconds previously
  • Loading branch information...
1 parent 0c08118 commit aefd32777ad0a9fe67c694585bedfb700eeca7c1 @DPStokes DPStokes committed Oct 3, 2011
Showing with 15 additions and 15 deletions.
  1. +13 −13 GameEngine/Automation.php
  2. +1 −1 dorf1.php
  3. +1 −1 install/data/sql.sql
View
@@ -112,19 +112,18 @@ public function Automation() {
$this->ClearInactive();
$this->pruneResource();
$this->loyaltyRegeneration();
+ $this->healHero();
+ $this->celebrationComplete();
+ $this->demolitionComplete();
$this->culturePoints();
$this->researchComplete();$this->clearDeleting();
$this->buildComplete();
$this->marketComplete();
$this->trainingComplete();
- $this->sendunitsComplete();
$this->sendreinfunitsComplete();
$this->returnunitsComplete();
$this->sendSettlersComplete();
- $this->celebrationComplete();
- $this->demolitionComplete();
- $this->healHero();
-
+ $this->sendunitsComplete();
}
private function getfieldDistance($coorx1, $coory1, $coorx2, $coory2) {
@@ -187,21 +186,22 @@ public function getTypeLevel($tid,$vid) {
}
private function loyaltyRegeneration() {
global $database;
- $time = time()-3600;
$array = array();
- $q = "SELECT * FROM ".TB_PREFIX."vdata where lastupdate < $time";
+ $q = "SELECT * FROM ".TB_PREFIX."vdata WHERE loyalty<>100";
$array = $database->query_return($q);
-
- foreach($array as $loyalty) {
- if($loyalty['lastupdate'] < $time){
+ if(!empty($array)) {
+ foreach($array as $loyalty) {
if($this->getTypeLevel(25,$loyalty['wref']) >= 1){
$value = $this->getTypeLevel(25,$loyalty['wref']);
}elseif($this->getTypeLevel(26,$loyalty['wref']) >= 1){
$value = $this->getTypeLevel(26,$loyalty['wref']);
- }
- $q = "UPDATE ".TB_PREFIX."vdata SET loyalty = loyalty + $value WHERE wref = '".$loyalty['wref']."'";
+ } else {
+ $value = 0;
+ }
+ $newloyalty = min(100,$loyalty['loyalty']+$value*(time()-$loyalty['lastupdate'])*SPEED/(60*60));
+ $q = "UPDATE ".TB_PREFIX."vdata SET loyalty = $newloyalty WHERE wref = '".$loyalty['wref']."'";
$database->query($q);
- }
+ }
}
}
private function clearDeleting() {
View
@@ -64,7 +64,7 @@
<div id="mid">
<?php include("Templates/menu.tpl"); ?>
<div id="content" class="village1">
-<h1><?php echo $village->vname; if($village->loyalty!='100'){ if($village->loyalty>'33'){ $color="gr"; }else{ $color="re"; } ?><div id="loyality" class="<?php echo $color; ?>"><?php echo LOYALTY; ?> <?php echo $village->loyalty; ?>%</div><?php } ?></h1>
+<h1><?php echo $village->vname; if($village->loyalty!='100'){ if($village->loyalty>'33'){ $color="gr"; }else{ $color="re"; } ?><div id="loyality" class="<?php echo $color; ?>"><?php echo LOYALTY; ?> <?php echo floor($village->loyalty); ?>%</div><?php } ?></h1>
<?php include("Templates/field.tpl");
$timer = 1;
?>
View
@@ -1267,7 +1267,7 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%vdata` (
`crop` float(12,2) NOT NULL,
`maxcrop` int(10) unsigned NOT NULL,
`lastupdate` int(11) unsigned NOT NULL,
- `loyalty` int(3) NOT NULL DEFAULT '100',
+ `loyalty` float(9,6) unsigned NOT NULL DEFAULT '100',
`exp1` int(10) NOT NULL,
`exp2` int(10) NOT NULL,
`exp3` int(10) NOT NULL,

0 comments on commit aefd327

Please sign in to comment.