public static function processRelationUpdate($tribeData, $targetData, $relationID, $force = false) { if (empty($tribeData) || empty($targetData)) { return -30; } $tribeMight = self::getMight($tribeData['tribeID']); $targetMight = self::getMight($targetData['tribeID']); if (!$force) { if ($tribeData['tribeID'] == $targetData['tribeID']) { return -14; } if (!$tribeData['valid']) { return -16; } $relationInfo = $GLOBALS['relationList'][$relationID]; $relation = self::getRelationBetween($tribeData['tribeID'], $targetData['tribeID']); if ($relation === false) { return -17; } if ($relation['own']['relationType'] == $relationID) { // change to actual relation? return -18; } if (!$relation['own']['changeable']) { return -19; } // check if switching to same relation as target or relation is possible if ($relation['other']['relationType'] != $relationID && !self::isPossible($relationID, $relation['own']['relationType'])) { return -20; } if (!$force && $GLOBALS['relationList'][$relationID]['isWarAlly']) { //generally allowes? if (!$GLOBALS['relationList'][$relation['own']['relationType']]['isAlly']) { return -21; } if (!$GLOBALS['relationList'][$relation['other']['relationType']]['isAlly']) { return -22; } if (!self::hasSameEnemy($tribeData['tribeID'], $targetData['tribeID'], true, true)) { return -23; } } $relationTypeOtherActual = $relation['other']['relationType']; // check minimum size of target tribe if it's not an ultimatum if (($relationInfo['targetSizeDiffDown'] > 0 || $relationInfo['targetSizeDiffUp'] > 0) && !$GLOBALS['relationList'][$relationTypeOtherActual]['isUltimatum']) { $from_points = max(0, $tribeMight); $target_points = max(0, $targetMight); $targetTopTribe = Tribe::isTopTribe($targetData['tribeID']); if ($targetTopTribe == false) { if ($relationInfo['targetSizeDiffDown'] > 0 && $from_points - $relationInfo['targetSizeDiffDown'] > $target_points) { return -24; } if ($relationInfo['targetSizeDiffUp'] > 0 && $from_points + $relationInfo['targetSizeDiffUp'] < $target_points) { return -25; } } } } // if switching to the same relation of other clan towards us, // use their treaty's end_time! if ($relationID == $relation['other']['relationType'] && $relationID != 0) { $duration = 0; $end_time = $relation['other']['duration']; } else { $duration = $GLOBALS['relationList'][$relation['own']['relationType']]['transitions'][$relationID]['time']; $end_time = 0; } if ($GLOBALS['relationList'][$relation['own']['relationType']]['isPrepareForWar'] && $GLOBALS['relationList'][$relationID]['isWar']) { $OurFame = $relation['own']['fame']; $OtherFame = $relation['other']['fame']; } else { $OurFame = 0; $OtherFame = 0; } if (!self::setRelation($tribeData['tribeID'], $targetData['tribeID'], $relationID, $duration, $end_time, $relation['own']['tribe_rankingPoints'], $relation['own']['target_rankingPoints'], $OurFame)) { return -3; } // calculate elo if war ended if ($GLOBALS['relationList'][$relationID]['isWarWon']) { Tribe::calculateElo($tribeData['tribeID'], $tribeMight, $targetData['tribeID'], $targetMight); Tribe::updateWonLost($tribeData['tribeID'], $targetData['tribeID'], false); } else { if ($GLOBALS['relationList'][$relationID]['isWarLost']) { Tribe::calculateElo($targetData['tribeID'], $targetMight, $tribeData['tribeID'], $tribeMight); Tribe::updateWonLost($tribeData['tribeID'], $targetData['tribeID'], true); } } // insert history message if (isset($GLOBALS['relationList'][$relationID]['historyMessage'])) { Tribe::setHistory($tribeData['tribeID'], Tribe::prepareHistoryMessage($tribeData['tag'], $targetData['tag'], $GLOBALS['relationList'][$relationID]['historyMessage'])); } TribeMessage::sendIntern($tribeData['tribeID'], Tribe::MESSAGE_RELATION, sprintf(_("Haltung gegenüber %s geändert"), $targetData['tag']), sprintf(_("Ihr Stammesanführer hat die Haltung Ihres Stammes gegenüber dem Stamm %s auf %s geändert."), $targetData['tag'], $GLOBALS['relationList'][$relationID]['name'])); TribeMessage::sendIntern($targetData['tribeID'], Tribe::MESSAGE_RELATION, sprintf(_("Der Stamm %s ändert seine Haltung"), $tribeData['tag']), sprintf(_("Der Stammesanführer des Stammes %s hat die Haltung seines Stammes ihnen gegenüber auf %s geändert."), $tribeData['tag'], $GLOBALS['relationList'][$relationID]['name'])); // switch other side if necessary (and not at this type already) if (!$end_time && ($oST = $relationInfo['otherSideTo']) >= 0) { if (!self::setRelation($targetData['tribeID'], $tribeData['tribeID'], $oST, $duration, 0, $relation['other']['tribe_rankingPoints'], $relation['other']['target_rankingPoints'], $OtherFame)) { return -17; } // insert history if (isset($GLOBALS['relationList'][$oST]['historyMessage'])) { Tribe::setHistory($targetData['tribeID'], Tribe::prepareHistoryMessage($tribeData['tag'], $targetData['tag'], $GLOBALS['relationList'][$oST]['historyMessage'])); } TribeMessage::sendIntern($tribeData['tribeID'], Tribe::MESSAGE_RELATION, sprintf(_("Der Stamm %s ändert seine Haltung"), $targetData['tag']), sprintf(_("Der Stamm %s hat die Haltung ihnen gegenüber automatisch auf %s geändert."), $targetData['tag'], $GLOBALS['relationList'][$oST]['name'])); TribeMessage::sendIntern($targetData['tribeID'], Tribe::MESSAGE_RELATION, sprintf(_("Haltung gegenüber %s geändert"), $tribeData['tag']), sprintf(_("Die Haltung Ihres Stammes gegenüber dem Stamm %s wurde automatisch auf %s geändert."), $tribeData['tag'], $GLOBALS['relationList'][$oST]['name'])); } return 7; }