Outils du site


fr:developpers:documentation_library_formula

Ceci est une ancienne révision du document !


Ogame formula Library

OGSpy détient une bibliothèque implémentant les formules d'Ogame.

  • côté PHP (includes/ogame.php), complète permettant d'aider la manipulation des formules Ogame dans les pages OGSpy comme dans les mod.
    • programmation terminée
  • côté JS (js/ogame_formula.js), les fonctions nécessaires à des utilisations dynamiques (production, consommation, temps, coût, ect.)
    • programmation en cours

Types et fonctions de base

Ressources

La manipulation des ressources est un type sous la forme d'un tableau contenant toutes les ressources.

PHP
/** @brief Get an Ogame ressources array.
 *  
 *  @param[in] int $metal,$cristal,$deut The needed ressources
 *  @param[in] int $NRJ,$AM              Optional ressources (0 default)
 *  @return array('M','C','D','NRJ','AM'), default is 0
 */
function ogame_array_ressource($metal, $cristal, $deut, $NRJ = 0, $AM = 0);
 
//Exemple d'initialisation
$prod = ogame_array_ressource(0, 0, 0);
$prod['M'] = 44;
$cout_base['M'] = ogame_array_ressource(  60   ,  15    , 0); //Prix de base d'une mine de métal.

Nom de base

Comment être sûr d'un nom d'un bâtiment ou autre élément OGame enregistré avec OGSpy, et éviter de les redéfinir au risque d'un oublier ?

La fonction suivante, et ses alter-ego (is ?), sont essentielles dans la manipulation automatique.

PHP
/** @brief Give database names of a buiding/research/fleet/defence/class/ressources.
 *  
 *  @return array('BAT'=>array, 'RECH'=>array, 'VSO'=>array, 'DEF'=>array, 'CLASS'=>array, 'RESS'=>array)
 */
function ogame_get_element_names()
{
    $names = array();
 
    $names['BAT'] = array(  // Bâtiments :
        'M',    //Mine de métal
        'C',    //Mine de cristal
        'D',    //Synthétiseur de deutérium
        'CES',  //Centrale électrique solaire
        'CEF',  //Centrale électrique de fusion
        'UdR',  //Usine de robots
        'UdN',  //Usine de nanites
        'CSp',  //Chantier spatial
        'HM',   //Hangar de métal
        'HC',   //Hangar de cristal
        'HD',   //Réservoir de deutérium
        'Lab',  //Laboratoire
        'Ter',  //Terraformeur
        'DdR',  //Dépot de ravitaillement
        'Silo', //Silo de missiles
        'Dock', //Dock spatial
        'BaLu', //Base lunaire
        'Pha',  //Phalange de capteur
        'PoSa', //Porte de saut spatial
        );
    $names['RECH'] = array( // Recherches :
        'Esp',           //Technologie espionage
        'Ordi',          //Technologie ordinateur
        'Armes',         //Technologie armes
        'Bouclier',      //Technologie bouclier
        'Protection',    //Technologie protection des vaisseaux spatiaux
        'NRJ',           //Technologie énergie
        'Hyp',           //Technologie hyperespace
        'RC',            //Réacteur à combustion
        'RI',            //Réacteur à impulsion
        'PH',            //Propulsion hyperespace
        'Laser',         //Technologie laser
        'Ions',          //Technologie à ions
        'Plasma',        //Technologie plasma
        'RRI',           //Réseau de recherche intergalactique
        'Graviton',      //Technologie graviton
        'Astrophysique', //Astrophysique
        );
    $names['VSO'] = array(  // Flottes :
        'PT',   //Petit transporteur
        'GT',   //Grand transporteur
        'CLE',  //Chasseur léger
        'CLO',  //Chasseur lourd
        'CR',   //Croiseur
        'VB',   //Vaisseau de bataille
        'VC',   //Vaisseau de colonisation
        'REC',  //Recycleur
        'SE',   //Sonde d'espionnage
        'BMD',  //Bombardier
        'DST',  //Destructeur
        'EDLM', //Étoile de la mort
        'TRA',  //Traqueur
        'SAT',  //Satellite solaire
        'FOR',  //Foreuse
        'FAU',  //Faucheur
        'ECL',  //Éclaireur
        );
    $names['DEF'] = array(  // Défenses :
        'LM',  //Lanceur de missiles
        'LLE', //Artillerie laser légère
        'LLO', //Artillerie laser lourde
        'CG',  //Canon de Gauss
        'AI',  //Artillerie à ions
        'LP',  //Lanceur de plasma
        'PB',  //Petit bouclier
        'GB',  //Grand bouclier
        'MIC', //Missile d'interception
        'MIP', //Missile interplanétaire
        );
    $names['CLASS'] = array(
        'none', //Aucune classe
        'COL',  //Classe collecteur
        'GEN',  //Classe général
        'EXP',  //Classe explorateur
        );
    $names['RESS'] = array(
        'M',   //métal
        'C',   //cristal
        'D',   //deutérium
        'NRJ', //énergie
        'AM',  //AM
        );
 
    return $names;
}
/**
 *  @brief Détermine si c'est un bâtiment, une recherche, un vaisseau, une défense ou une classe.
 *  
 *  @param[in] string $nom Nom à rechercher, correspond au nom en BDD
 *  @return false|string 'BAT' bâtiment, 'RECH' recherche, 'DEF' défense, 'VSO' vaisseau, 'CLASS' classe et false sinon
 */
function ogame_is_element($nom);
function ogame_is_a_defence($nom)  { return ogame_is_element($nom) === 'DEF'; }
function ogame_is_a_fleet($nom)    { return ogame_is_element($nom) === 'VSO'; }
function ogame_is_a_building($nom) { return ogame_is_element($nom) === 'BAT'; }
function ogame_is_a_research($nom) { return ogame_is_element($nom) === 'RECH'; }
 
//Exemple d'utilisations :
$names = ogame_get_element_names();
 
foreach (array_merge($names['VSO'], $names['DEF']) as $element) {
    $result[$element] = ogame_element_cout_base($element); //Récupérer les prix de base de chaque vaisseaux et défenses
    if (ogame_is_element($element) === 'VSO') {
        //Faire quelque chose spécifique pour les vaisseaux
    }
}

Formules liées à la production

LA fonction à utiliser pour calculer la production d'un empire est la suivante pour chaque planète :

/** @brief Calculates planet production and consumption.
 *  
 *  @param[in] array $user_building   Planet info ('M','C','D','CES','CEF','SAT','FOR','temperature_max','coordinates','M_percentage','C_percentage','D_percentage','CES_percentage','CEF_percentage','Sat_percentage','FOR_percentage',array 'booster_tab') 0 as default value
 *  @param[in] array $user_technology Techno info ('NRJ','Plasma') 
 *  @param[in] array $user_data       User info (array('user_class'=>'COL'/...,'off_commandant','off_amiral','off_ingenieur','off_geologue', or 'off_full')
 *  @param[in] array $server_config   Ogame univers info ('speed_uni')
 *  @return array('prod_reel,'prod_theorique','ratio','conso_E','prod_E',  //Production totale
 *      'prod_CES','prod_CEF','prod_SAT','prod_FOR',   //production énergie de chaque unité
 *      'prod_M','prod_C','prod_D','prod_base', //production ressources de chaque mine
 *      'prod_booster','prod_off','prod_Plasma','prod_classe',   //production des bonus
 *      'M','C','D','NRJ','AM', =>héritage du type ressource pour les valeurs retournées.
 *      'nb_FOR_maxed',
 *      ) à part ratio/conso_E/prod_E (float) les autres sont array('M','C','D','NRJ','AM')
 *  
 *  @details remplace les fonctions ratio et bilan_production_ratio
 */
function ogame_production_planet($user_building, $user_technology = null, $user_data = null, $server_config = null);
 
//Exemple d'utilisations :
$user_empire = user_get_empire($user_data['user_id']);
$user_production = user_empire_production($user_empire, $user_data, $server_config['speed_uni']);   //=>Vous devrez utiliser cette fonction qui fait le calcul d'un empire
//Sinon :
    foreach() { //Pour chaque planète :
        $planet_prod[$i] = ogame_production_planet($user_empire['user_building'], $user_empire['user_technology'], $user_data, $server_config);
    }
echo $planet_prod[1]['prod_M']['M']; //=> production de la mine de métal
echo $planet_prod[1]['prod_M']['NRJ']; //=> consommation d'énergie de la mine de métal (!nombre négatif!)
echo $planet_prod[1]['prod_reel']['M']; //=> production totale de métal de la planète (mine,classe,officiers,booster,plasma,etc.)
//Mais aussi individullement :

Formules des coûts

Formules du temps

Les caratéristiques Ogame

Les détails d'infos pour les vaisseaux et défenses

Les prérequis de chaque élement OGame

Autres formules

Fonctions utilitaires

/** @brief Return planet position from coordinates.
 *  @param[in] string $coordinates planet coordinates (galaxy:system:position)
 *  @return int planet position
 */
function ogame_find_planet_position($coordinates);

Récapitulatif des prototypes de fonctions de la Ogame formula Library

/** @brief Get an Ogame ressources array.
 *  
 *  @param[in] int $metal,$cristal,$deut The needed ressources
 *  @param[in] int $NRJ,$AM              Optional ressources (0 default)
 *  @return array('M','C','D','NRJ','AM'), default is 0
 */
function ogame_array_ressource($metal, $cristal, $deut, $NRJ = 0, $AM = 0);
/** @brief Get an Ogame details array pour def/vso.
 *  
 *  @param[in] int  $structure,$bouclier,$attaque   Generic details of def/vso
 *  @param[in] int  $vitesse,$fret,$conso           Optional details of vso (0 default)
 *  @param[in] bool $civil                          If vso is civil or not (default true)
 *  @return array('structure','bouclier','attaque','vitesse','fret','conso',(array)'rapidfire',(bool)'civil')
 */
function ogame_array_detail($structure, $bouclier, $attaque, $vitesse=0, $fret=0, $conso=0, $civil=true);
/** @brief Give database names of a buiding/research/fleet/defence/class/ressources.
 *  
 *  @return array('BAT'=>array, 'RECH'=>array, 'VSO'=>array, 'DEF'=>array, 'CLASS'=>array, 'RESS'=>array)
 */
function ogame_get_element_names();
/** @brief Détermine si c'est un bâtiment, une recherche, un vaisseau, une défense ou une classe.
 *  
 *  @param[in] string $nom Nom à rechercher, correspond au nom en BDD
 *  @return false|string 'BAT' bâtiment, 'RECH' recherche, 'DEF' défense, 'VSO' vaisseau, 'CLASS' classe et false sinon
 */
function ogame_is_element($nom);
function ogame_is_a_defence($nom)  { return ogame_is_element($nom) === 'DEF'; }
function ogame_is_a_fleet($nom)    { return ogame_is_element($nom) === 'VSO'; }
function ogame_is_a_building($nom) { return ogame_is_element($nom) === 'BAT'; }
function ogame_is_a_research($nom) { return ogame_is_element($nom) === 'RECH'; }
 
/** @brief Return planet position from coordinates. 
 *  @param[in] string $coordinates planet coordinates (galaxy:system:position)
 *  @return int planet position
 */
function ogame_find_planet_position($coordinates);
 
////////////PRODUCTION fonctions :
/**
 *  @brief Return position ressources bonus in Ogame.
 *  
 *  @param[in] int $position The wanted position
 *  @return array('M','C','D','NRJ','AM') of bonus, default is 0%
 */
function ogame_production_position($position);
/**
 *  @brief Calculates foreuse coefficient on base production.
 *  
 *  @param[in] array $user_building array of mines level and FOR number (array('M','C','D','FOR'))
 *  @param[in] array $user_data     array with class and officiers infos (array('user_class'=>'COL'/...,'off_geologue' or 'off_full'))
 *  @return array('bonus', 'nb_FOR_maxed') bonus=foreuse bonus coefficient ; nb_FOR_maxed=limit nb if too much
 */
function ogame_production_bonus_foreuse($user_building, $user_data);
/**
 *  @brief Calculates building/sat/for or base production and consumption.
 *  
 *  @param[in] string $building        The wanted building/sat/for ('base','M','C','D','CES','CEF','SAT','FOR')
 *  @param[in] array  $user_building   Planet info ('M','C','D','CES','CEF','SAT','FOR','temperature_max','coordinates') 0 as default value
 *  @param[in] array  $user_technology Techno info ('NRJ','Plasma') 0 as default value
 *  @param[in] array  $user_data       User info (array('user_class'=>'COL'/...,'off_geologue' or 'off_full')
 *  @param[in] array  $server_config   Ogame univers info ('speed_uni',(bool)'final_calcul') / final_calcul permet de déterminer si les valeurs retournées seront manipulées avec les % de production ressources, et donc sans arrondi.
 *  @return array('M','C','D','NRJ','AM') of production
 *  
 *  @details remplace les fonctions consumption et partiellement production,production_sat,production_foreuse
 */
function ogame_production_building($building, $user_building = null, $user_technology = null, $user_data = null, $server_config = null);
/**
 *  @brief Calculates planet production and consumption.
 *  
 *  @param[in] array $user_building   Planet info ('M','C','D','CES','CEF','SAT','FOR','temperature_max','coordinates','M_percentage','C_percentage','D_percentage','CES_percentage','CEF_percentage','Sat_percentage','FOR_percentage',array 'booster_tab') 0 as default value
 *  @param[in] array $user_technology Techno info ('NRJ','Plasma') 
 *  @param[in] array $user_data       User info (array('user_class'=>'COL'/...,'off_commandant','off_amiral','off_ingenieur','off_geologue', or 'off_full')
 *  @param[in] array $server_config   Ogame univers info ('speed_uni')
 *  @return array('prod_reel,'prod_theorique','ratio','conso_E','prod_E',  //Production totale
 *      'prod_CES','prod_CEF','prod_SAT','prod_FOR',   //production énergie de chaque unité
 *      'prod_M','prod_C','prod_D','prod_base', //production ressources de chaque mine
 *      'prod_booster','prod_off','prod_Plasma','prod_classe',   //production des bonus
 *      'M','C','D','NRJ','AM', =>héritage du type ressource pour les valeurs retournées.
 *      'nb_FOR_maxed',
 *      ) à part conso_E/prod_E (float) les autres sont array('M','C','D','NRJ','AM')
 *  
 *  @details remplace les fonctions ratio et bilan_production_ratio
 */
function ogame_production_planet($user_building, $user_technology = null, $user_data = null, $server_config = null);
 
/**
 * @brief Calculates the planet storage capacity (taille hangar).
 *
 * @param[in] int $level Storage building level
 * @return float capacity
 */
function ogame_depot_capacity($level);
/**
 *  @brief Calculates phalanx range.
 *  
 *  @param[in] int   $level         Level of the phalanx
 *  @param[in] array $user_class    User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none))
 *  @return Range in system
 */
function ogame_phalanx_range($level, $user_class = 'none');
/**
 *  @brief Calculates MIP range.
 *  
 *  @param[in] int $impulsion Techno impulsion (RI)
 *  @return int Range in system
 */
function ogame_missile_range($impulsion = 1);
/**
 *  @brief Calculates MIP speed.
 *  
 *  @param[in] int $nb_system Number of sub-system from current planet
 *  @param[in] int $speed_uni Univers speed
 *  @return int Speed in seconds
 */
function ogame_missile_speed($nb_system, $speed_uni = 1);
/**
 *  @brief Calculates additional case given by terraformer.
 *  
 *  @param[in] int $level The terra level
 *  @return int Number of additional case
 */
function ogame_terra_case($level);
 
/**
 *  @brief Return base price of an Ogame bat/vso/def/rech
 *  
 *  @param[in] string $name The name as in Database, all for all element
 *  @return array('M', 'C','D, 'NRJ') of the chosen element (array of these if 'all')
 */
function ogame_element_cout_base($name = 'all');
/**
 *  @brief Calculates price of an Ogame bat/vso/def/rech
 *  
 *  @param[in] string $name  The chosen name, as in Database
 *  @param[in] int    $level The chosen level for bat/rech or the number of def/vso
 *  @return array('M', 'C','D, 'NRJ')
 */
function ogame_element_cout($name, $level);
/**
 *  @brief Calculates the evolve coefficient of a building and research.
 *  
 *  @param[in] string $name Building/research name, as in Database
 *  @return array('M', 'C','D, 'NRJ') array of coefficient by ressource
 */
function ogame_element_evolve_coef($name);
/**
 *  @brief Calculates the price of an Ogame element to it current level.
 *  
 *  @param[in] string $name  Name of building/research/fleet/defence, like in name in database
 *  @param[in] int    $level The current level or the number of fleet/defence
 *  @return array('M', 'C','D, 'NRJ') ressources used to it current level
 */
function ogame_element_cumulate($name, $level);
/**
 *  @brief Calculates the price of all element of type (building,defence,fleet,research).
 *  
 *  @param[in] array  $user Array of element each planet or moon
 *  @param[in] string $type Type of element ('BAT' pour bâtiment, 'RECH' pour recherche, 'DEF' pour défense, 'VSO' pour vaisseau)
 *  @return float Total price (M+C+D).
 */
function ogame_all_cumulate($user, $type);
function all_building_cumulate($user_building) { return ogame_all_cumulate($user_building, 'BAT'); } //old
function all_defence_cumulate($user_defence)   { return ogame_all_cumulate($user_defence, 'DEF'); } //old
function all_fleet_cumulate($user_fleet)       { return ogame_all_cumulate($user_fleet, 'VSO'); }
function all_technology_cumulate($user_techno) { return ogame_all_cumulate($user_techno, 'RECH'); }
/**
 *  @brief Calculates destroy price of a building.
 *  
 *  @param[in] string $name       Building name, as in Database
 *  @param[in] int    $level      Building level
 *  @param[in] int    $techno_ions Level of techno ions
 *  @return false|array('M', 'C','D, 'NRJ'), false if undestroyable
 */
function ogame_building_destroy($name, $level, $techno_ions = 0);
 
//////FLOTTE
/**
 *  @brief Calculates deut consommation for parking of a fleet.
 *  
 *  @param[in] int $conso The conso of the fleet
 *  @param[in] int $hour  Number of hours in parking
 *  @return float Deut conso for this hour of parking
 */
function ogame_fleet_conso_statio($conso, $hour);
/**
 *  @brief Return base details of Ogame def/vso.
 *  
 *  @param[in] string $name The name as in Database, all for all element
 *  @return array('structure','bouclier','attaque','vitesse','fret','conso',(array)'rapidfire',(bool)'civil')
 *      rapidfire=array('PT'=>x, ...) array of all fleet and defence; if x>0 then again else from
 *//Coût de base des vaisseaux                 structure,bouclier,attaque,vitesse   ,fret    ,conso,civil)
    $details_base['PT']   = ogame_array_detail(4000   , 10     , 5     , 5000     , 5000   , 10);
    $details_base['PT']['rapidfire']   = array('SE'=>5,'SAT'=>5,'FOR'=>5, 'CLO'=>-3,'TRA'=>-3,'EDLM'=>-250);
 */
function ogame_elements_details_base($name = 'all');
/**
 *  @brief Calculates technical data of a fleet or defence.
 *  
 *  @param[in] string     $name        The name, like name in Database
 *  @param[in] array      $user_techno The array of technologies
 *  @param[in] string|int $classe      The user class //array('none','COL','GEN','EXP') - (1=Collectionneur)[0=aucune, 2=général, 3=explorateur])
 *  @return array('nom','structure','bouclier','attaque','vitesse','fret','conso',(array)'rapidfire',(bool)'civil',(array)'cout') of the wanted fleet or defence.
 *      rapidfire=array('PT'=>x, ...) array of all fleet and defence; if x>0 then again else from
 *      cout=array of ogame_element_cumulate()=array('M','C','D','NRJ)
 */
function ogame_elements_details($name, $user_techno = null, $classe = 0);
/**
 *  @brief Calculates technical data of all fleet/defence.
 *  
 *  @param[in] array      $user_techno The array of technologies
 *  @param[in] string|int $classe The user class //array('none','COL','GEN','EXP') - (1=Collectionneur)[0=aucune, 2=général, 3=explorateur])
 *  @return array of all fleet/defence with are array of details from ogame_elements_details()
 */
function ogame_all_details($user_techno = null, $classe = 0);
 
/**
 *  @brief Calculates technical data of Ogame requirement.
 *  
 *  @param[in] string $nom The name, like name in Database
 *  @return array('none','COL','GEN','EXP' : bool for class, 'CES',etc. : int for all bat/rech name in database)
 */
function ogame_elements_requirement($name = 'all');
/**
 *  @brief Calculates technical data of Ogame requirement of all building/research/fleet/defence.
 *  
 *  @return array of all building/research/fleet/defence with are array of requirement from ogame_elements_requirement()
 */
function ogame_all_requirement();
 
/**
 *  @brief Calculates cumulate lab network.
 *  
 *  @param[in] array $user_empire       From user_get_empire()
 *  @param[in] int   $current_planet_id Current planet to run a research, if not best lab (theory).
 *  @return int Number of cumulate lab network
 */
function ogame_labo_cumulate($user_empire, $current_planet_id = -1);
 
/**
 *  @brief Calculates construction time of a OGame element bat/vso/def/rech.
 *  
 *  @param[in] string $name          The name, like name in Database
 *  @param[in] int    $level         The level or number for def/vso
 *  @param[in] array  $user_building Array of bat level ('CSp','UdR','UdN','Lab')
 *  @param[in] int    $cumul_labo    Number of cumulate lab network (only for rech)
 *  @param[in] array  $user_class    User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none))
 *  @return float Time in seconds
 */
function ogame_construction_time($name, $level, $user_building, $cumul_labo = 0, $user_class = 'none');
fr/developpers/documentation_library_formula.1611352537.txt.gz · Dernière modification : 2021/03/12 14:09 (modification externe)