Exemple #1
0
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&uuml;ber {$targetTribeInfo['tag']} " . "ge&auml;ndert", "Ihr Stammesanf&uuml;hrer hat die Haltung Ihres " . "Stammes gegen&uuml;ber dem Stamm " . "{$targetTribeInfo['tag']} auf {$relationName} " . "ge&auml;ndert.");
    tribe_sendTribeMessage($targetTribeInfo['tag'], TRIBE_MESSAGE_RELATION, "Der Stamm {$tag} &auml;ndert seine Haltung", "Der Stammesanf&uuml;hrer des Stammes {$tag} " . "hat die Haltung seines " . "Stammes ihnen gegen&uuml;ber " . "auf {$relationName} " . "ge&auml;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&uuml;ber {$tag} " . "ge&auml;ndert", "Die Haltung Ihres " . "Stammes gegen&uuml;ber dem Stamm " . "{$tag}  wurde automatisch auf {$relationName} " . "ge&auml;ndert.");
        tribe_sendTribeMessage($tag, TRIBE_MESSAGE_RELATION, "Der Stamm {$targetTribeInfo['tag']} &auml;ndert " . "seine " . "Haltung", "Der Stamm {$targetTribeInfo['tag']} " . "hat die Haltung ihnen gegen&uuml;ber " . "automatisch auf {$relationName} " . "ge&auml;ndert.");
    }
    tribe_generateMapStylesheet();
    return 3;
}
Exemple #2
0
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&uuml;ber {$targetTribeInfo['tag']} " . "ge&auml;ndert", "Ihr Clananf&uuml;hrer hat die Haltung Ihres " . "Clans gegen&uuml;ber dem Clan " . "{$targetTribeInfo['tag']} auf {$relationName} " . "ge&auml;ndert.");
    tribe_sendTribeMessage($targetTribeInfo[tag], TRIBE_MESSAGE_RELATION, "Der Clan {$tag} &auml;ndert seine Haltung", "Der Clananf&uuml;hrer des Clans {$tag} " . "hat die Haltung seines " . "Clans ihnen gegen&uuml;ber " . "auf {$relationName} " . "ge&auml;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&uuml;ber {$tag} " . "ge&auml;ndert", "Die Haltung Ihres " . "Clans gegen&uuml;ber dem Clan " . "{$tag}  wurde automatisch auf {$relationName} " . "ge&auml;ndert.");
        tribe_sendTribeMessage($tag, TRIBE_MESSAGE_RELATION, "Der Clan {$targetTribeInfo['tag']} &auml;ndert " . "seine " . "Haltung", "Der Clan {$targetTribeInfo['tag']} " . "hat die Haltung ihnen gegen&uuml;ber " . "automatisch auf {$relationName} " . "ge&auml;ndert.");
    }
    return 3;
}