function relation_processRelationUpdate($tag, $relationData, $db, $FORCE = 0) { global $relationList; if (!$FORCE) { if (strcasecmp($tag, $relationData['tag']) == 0) { return -7; } if (!($ownTribeInfo = tribe_getTribeByTag($tag, $db))) { return -6; } if (!($targetTribeInfo = tribe_getTribeByTag($relationData['tag'], $db))) { return -6; } if (!$ownTribeInfo['valid']) { return -17; } $relationType = $relationData['relationID']; $relationInfo = $relationList[$relationType]; if (!($relation = relation_getRelation($tag, $relationData['tag'], $db))) { return -3; } $relationTypeActual = $relation['own']['relationType']; if ($relationTypeActual == $relationType) { // change to actual relation? return -14; } if (!$relation['own']['changeable']) { return -4; } // check if switching to same relation as target or relation is possible if ($relation['other']['relationType'] != $relationType && !relation_isPossible($relationType, $relation['own']['relationType'])) { //from return -5; } $relationFrom = $relation['own']['relationType']; $relationTo = $relationType; if (!$FORCE && $relationList[$relationTo]['isWarAlly']) { //generally allowes? if (!$relationList[$relationFrom]['isAlly']) { return -18; } if (!$relationList[$relation['other']['relationType']]['isAlly']) { return -19; } if (!relation_haveSameEnemy($ownTribeInfo['tag'], $targetTribeInfo['tag'], TRUE, FALSE, $db)) { return -20; } } $relationTypeOtherActual = $relation['other']['relationType']; // check minimum size of target tribe if it´s not an ultimatum if (($relationInfo['targetSizeDiffDown'] > 0 || $relationInfo['targetSizeDiffUp'] > 0) && !$relationList[$relationTypeOtherActual]['isUltimatum']) { $from_points = max(0, tribe_getMight($tag, $db)); $target_points = max(0, tribe_getMight($relationData['tag'], $db)); if (!tribe_isTopTribe($db, $relationData['tag'])) { if ($relationInfo['targetSizeDiffDown'] > 0 && $from_points - $relationInfo['targetSizeDiffDown'] > $target_points) { return -12; } } if (!tribe_isTopTribe($db, $relationData['tag'])) { if ($relationInfo['targetSizeDiffUp'] > 0 && $from_points + $relationInfo['targetSizeDiffUp'] < $target_points) { return -13; } } } } // if switching to the same relation of other clan towards us, // use their treaty's end_time! if ($relationType == $relation['other']['relationType'] && $relationType != 0) { $end_time = $relation['other']['duration']; } else { $duration = $relationList[$relationTypeActual]['transitions'][$relationType]['time']; } if ($relationList[$relationFrom]['isPrepareForWar'] && $relationList[$relationTo]['isWar']) { $OurFame = $relation['own']['fame']; $OtherFame = $relation['other']['fame']; } else { $OurFame = 0; $OtherFame = 0; } if (!relation_setRelation($tag, $targetTribeInfo['tag'], $relationType, $duration, $db, $end_time, $relation['own']['tribe_rankingPoints'], $relation['own']['target_rankingPoints'], $OurFame)) { return -3; } // calculate elo if war ended if ($relationList[$relationType]['isWarWon']) { ranking_calculateElo($db, $tag, $relation['own']['tribe_rankingPoints'], $relationData['tag'], $relation['own']['target_rankingPoints']); } else { if ($relationList[$relationType]['isWarLost']) { ranking_calculateElo($db, $relationData['tag'], $relation['own']['target_rankingPoints'], $tag, $relation['own']['tribe_rankingPoints']); } } // insert history message if ($message = $relationList[$relationType]['historyMessage']) { relation_insertIntoHistory($tag, relation_prepareHistoryMessage($tag, $targetTribeInfo['tag'], $message), $db); } $relationName = $relationList[$relationType]['name']; tribe_sendTribeMessage($tag, TRIBE_MESSAGE_RELATION, "Haltung gegenüber {$targetTribeInfo['tag']} " . "geändert", "Ihr Stammesanführer hat die Haltung Ihres " . "Stammes gegenüber dem Stamm " . "{$targetTribeInfo['tag']} auf {$relationName} " . "geändert."); tribe_sendTribeMessage($targetTribeInfo['tag'], TRIBE_MESSAGE_RELATION, "Der Stamm {$tag} ändert seine Haltung", "Der Stammesanführer des Stammes {$tag} " . "hat die Haltung seines " . "Stammes ihnen gegenüber " . "auf {$relationName} " . "geändert."); // switch other side if necessary (and not at this type already) if (!$end_time && ($oST = $relationInfo['otherSideTo']) >= 0) { if (!relation_setRelation($targetTribeInfo['tag'], $tag, $oST, $duration, $db, 0, $relation['other']['tribe_rankingPoints'], $relation['other']['target_rankingPoints'], $OtherFame)) { return -3; } // insert history if ($message = $relationList[$oST]['historyMessage']) { relation_insertIntoHistory($targetTribeInfo['tag'], relation_prepareHistoryMessage($tag, $targetTribeInfo['tag'], $message), $db); } $relationName = $relationList[$oST]['name']; tribe_sendTribeMessage($targetTribeInfo['tag'], TRIBE_MESSAGE_RELATION, "Haltung gegenüber {$tag} " . "geändert", "Die Haltung Ihres " . "Stammes gegenüber dem Stamm " . "{$tag} wurde automatisch auf {$relationName} " . "geändert."); tribe_sendTribeMessage($tag, TRIBE_MESSAGE_RELATION, "Der Stamm {$targetTribeInfo['tag']} ändert " . "seine " . "Haltung", "Der Stamm {$targetTribeInfo['tag']} " . "hat die Haltung ihnen gegenüber " . "automatisch auf {$relationName} " . "geändert."); } tribe_generateMapStylesheet(); return 3; }
function relation_processRelationUpdate($tag, $relationData, $db) { global $relationList; if (strcasecmp($tag, $relationData[tag]) == 0) { return -7; } if (!($targetTribeInfo = tribe_getTribeByTag($relationData[tag], $db))) { return -6; } $relationType = $relationData[relationID]; $relationInfo = $relationList[$relationType]; if (!($relation = relation_getRelation($tag, $relationData[tag], $db))) { return -3; } $relationTypeActual = $relation[own][relationType]; if ($relationTypeActual == $relationType) { // change to actual relation? return -13; } if (!$relation[own][changeable]) { return -4; } // check if switching to same relation as target or relation is possible if ($relation[other][relationType] != $relationType && !relation_isPossible($relationType, $relation[own][relationType])) { return -5; } // check minimum size of target tribe // BUT: relation of target tribe to us is always ok! if ($relationInfo[targetMinSize] > 0.0 && $relation[other][relationType] != relationType) { if (($from_points = tribe_getMight($tag, $db)) < 0) { $from_points = 0; } if (($target_points = tribe_getMight($relationData['tag'], $db)) < 0) { $target_points = 0; } if ($from_points * $relationInfo[targetMinSize] > $target_points) { return -12; } } // if switching to the same relation of other clan towards us, // use their treaty's end_time! if ($relationType == $relation[other][relationType] && $relationType != 0) { $end_time = $relation[other][duration]; } else { $duration = $relationList[$relationTypeActual][transitions][$relationType][time]; } if (!relation_setRelation($tag, $targetTribeInfo[tag], $relationType, $duration, $db, $end_time, $relation[own][tribe_rankingPoints], $relation[own][target_rankingPoints])) { return -3; } // insert history message if ($message = $relationList[$relationType][historyMessage]) { relation_insertIntoHistory($tag, relation_prepareHistoryMessage($tag, $targetTribeInfo[tag], $message), $db); } $relationName = $relationList[$relationType][name]; tribe_sendTribeMessage($tag, TRIBE_MESSAGE_RELATION, "Haltung gegenüber {$targetTribeInfo['tag']} " . "geändert", "Ihr Clananführer hat die Haltung Ihres " . "Clans gegenüber dem Clan " . "{$targetTribeInfo['tag']} auf {$relationName} " . "geändert."); tribe_sendTribeMessage($targetTribeInfo[tag], TRIBE_MESSAGE_RELATION, "Der Clan {$tag} ändert seine Haltung", "Der Clananführer des Clans {$tag} " . "hat die Haltung seines " . "Clans ihnen gegenüber " . "auf {$relationName} " . "geändert."); // switch other side if necessary (and not at this type already) if (!$end_time && ($oST = $relationInfo[otherSideTo]) >= 0) { if (!relation_setRelation($targetTribeInfo[tag], $tag, $oST, $duration, $db, 0, $relation[other][tribe_rankingPoints], $relation[other][target_rankingPoints])) { return -3; } // insert history if ($message = $relationList[$oST][historyMessage]) { relation_insertIntoHistory($targetTribeInfo[tag], relation_prepareHistoryMessage($tag, $targetTribeInfo[tag], $message), $db); } $relationName = $relationList[$oST][name]; tribe_sendTribeMessage($targetTribeInfo[tag], TRIBE_MESSAGE_RELATION, "Haltung gegenüber {$tag} " . "geändert", "Die Haltung Ihres " . "Clans gegenüber dem Clan " . "{$tag} wurde automatisch auf {$relationName} " . "geändert."); tribe_sendTribeMessage($tag, TRIBE_MESSAGE_RELATION, "Der Clan {$targetTribeInfo['tag']} ändert " . "seine " . "Haltung", "Der Clan {$targetTribeInfo['tag']} " . "hat die Haltung ihnen gegenüber " . "automatisch auf {$relationName} " . "geändert."); } return 3; }