Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente |
fr:developpers:documentation_library_formula [2021/01/27 14:59] – pitch314 | fr:developpers:documentation_library_formula [Date inconnue] (Version actuelle) – supprimée - modification externe (Date inconnue) 127.0.0.1 |
---|
====== 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, etc.) | |
* programmation en cours | |
| |
<note important>En Javascript, les tableaux sont des objets et sont manipulés par référence (comme en C), pointant vers la localisation du tableau. | |
| |
Contrairement au PHP, il n'y pas de copie explicite ($a = $b), il faut copier manuellement les éléments si l'on veut garder les valeurs du tableau originel.</note> | |
| |
===== Types et fonctions de base ===== | |
==== Ressources ==== | |
La manipulation des ressources est un type sous la forme d'un tableau contenant toutes les ressources. | |
<code php PHP> | |
/** @brief Get an Ogame resources array. | |
* | |
* @param[in] int $metal,$cristal,$deut The needed resources | |
* @param[in] int $NRJ,$AM Optional resources (0 default) | |
* @return array('M','C','D','NRJ','AM'), default is 0 | |
*/ | |
function ogame_array_ressource($metal, $cristal, $deut, $NRJ = 0, $AM = 0); | |
| |
//Exemples d'initialisations | |
$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. | |
</code> | |
| |
==== 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. | |
<code php PHP> | |
/** @brief Give database names of a building/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épôt 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 espionnage | |
'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'; } | |
| |
//Exemples 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 | |
} | |
} | |
</code> | |
| |
===== Formules liées à la production ===== | |
LA fonction à utiliser pour calculer la production d'un empire est la suivante pour chaque planète : | |
<code php PHP> | |
/** @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 ('user_class'=>'COL'/...,'off_commandant','off_amiral','off_ingenieur','off_geologue', or 'off_full') | |
* @param[in] array $server_config Ogame universe info ('speed_uni') | |
* @return array('prod_reel, // (array ress) Production réel en prenant en compte le ratio (M/C/D ressources, NRJ prod moins la conso) | |
* 'prod_theorique', // (array ress) Producton théorique M/C/D (ratio=1, 100%) | |
* 'ratio', // (float) le ratio de production NRJ (prod_E / conso_E) | |
* 'conso_E','prod_E', // (float) Production NRJ prod_E > 0, conso_E < 0 | |
* 'prod_CES','prod_CEF','prod_SAT', // (array ress) production énergie de chaque unité ('D' de prod_CEF contient la conso en deut de la CEF) | |
* 'prod_FOR', // (array ress) production M/C/D et conso NRJ | |
* 'prod_M','prod_C','prod_D','prod_base', // (array ress) Production ressources de chaque mine (M/C/D) et leur conso (NRJ) | |
* 'prod_booster','prod_off','prod_Plasma','prod_classe', // (array ress) Production des bonus | |
* 'M','C','D','NRJ','AM', =>héritage du type ressource pour les valeurs retournées. | |
* 'nb_FOR_maxed', // (int) Nombre max de foreuse utilisées | |
* ) à part ratio/conso_E/prod_E (float) les autres sont array('M','C','D','NRJ','AM') | |
*/ | |
function ogame_production_planet($user_building, $user_technology = null, $user_data = null, $server_config = null); | |
| |
//Exemples 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 individuellement : | |
| |
</code> | |
C'est cette fonction qui calcule la production en prenant tout en compte. C'est aussi la seule permettant de connaître la prod des différents bonus. | |
Sinon pour la production de base d'un bâtiment | |
<code php PHP> | |
/** @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') 0 as default value | |
* @param[in] array $user_data User info for FOR only (array('user_class'=>'COL'/...,'off_geologue' or 'off_full') | |
* @param[in] array $server_config Ogame universe 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 | |
*/ | |
function ogame_production_building($building, $user_building = null, $user_technology = null, $user_data = null, $server_config = null); | |
| |
//Exemples d'utilisations : | |
$prod = ogame_production_building('M',array('M'=>38,'coordinates'=>'2:2:8'),null,null,array('speed_uni'=>8); | |
//$prod['M'] = production d'une mine de métal 38 en position 8 sur un X8 | |
$prod = ogame_production_building('CEF',array('CEF'=>25),array('NRJ'=>20),null,array('speed_uni'=>8); | |
//$prod['NRJ'] = production d'énergie d'une centrale de fusion 25 avec la techno 20 | |
//$prod['D'] = la consommation (nombre négatif) de deutérium de cette CEF23 sur un univers X8 | |
$prod = ogame_production_building('FOR',array('FOR'=>800,'M'=>35,'C'=>35,'D'=>35),null,array('user_class'=>'COL','off_ingenieur'=>1),array('speed_uni'=>8); | |
//$prod[M/C/D] = la production des FOR pour mines 35/35/35 en fonction de la classe, en fonction du nombre max de FOR autorisé (8*MCD + 10%COL+ing) sur un X8 | |
//$prod[NRJ] = la conso NRJ du nombre max de FOR autorisées de base (0-100%) | |
| |
//Connaître le nombre de FOR max : | |
/** @brief Calculates maximum number of foreuse. | |
* @param[in] int $mine_M,$mine_C,$mine_D Mine level | |
* @param[in] array $user_data array with class and officiers infos (array('user_class'=>'COL'/...,'off_geologue' or 'off_full')) | |
* @return int The max | |
*/ | |
function ogame_production_foreuse_max($mine_M, $mine_C, $mine_D, $user_data); | |
</code> | |
| |
===== Formules des coûts ===== | |
Connaître le coût d'un élément (bat/vso/def/rech) notamment pour un évolution ou le prix de plusieurs défenses : | |
<code php PHP> | |
/** @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); | |
| |
//Exemples d'utilisations : | |
$cout = ogame_element_cout('M', 39); // Le prix en ressource d'une M39 | |
$cout = ogame_element_cout('NRJ', 21); // Le prix en ressource d'une NRJ21 | |
$cout = ogame_element_cout('EDLM', 1000); // Le prix en ressource de 1000 EDLM | |
</code> | |
Afin de connaître le nombre total de ressource investit il faut utilisation la fonction suivante : | |
<code php PHP> | |
/** @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') resources used to it current level | |
* NOTE : pour les vso/def cette fonction est identique à ogame_element_cout() | |
*/ | |
function ogame_element_cumulate($name, $level); | |
| |
//Exemples d'utilisations | |
$cout = ogame_element_cumulate('M', 39); // Le nombre de ressource investit, en cumul, pour une M39 | |
</code> | |
Néanmoins, dans le calcul des points d'une planète, il sera plus simple d'utiliser la fonction suivante : | |
<code php PHP> | |
/** @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); | |
| |
//Exemples d'utilisations : | |
$point_building = ogame_all_cumulate($user_empire['building'], 'BAT'); //à faire pour chaque planète | |
$point_defense = ogame_all_cumulate($user_empire['defense'], 'DEF'); //à faire pour chaque planète | |
$point_techno = ogame_all_cumulate($user_empire['technology'], 'RECH'); | |
$point_fleet = ogame_all_cumulate($user_fleet, 'VSO'); //Nécessite le mod-flotte pour un utilisateur | |
| |
$point_fleet_exp = ogame_all_cumulate($expedition_fleet, 'VSO'); //Soit pour la flotte la notre, l'alien/pirate ou pour les vaisseaux rapportés d'expédition. | |
//Il suffit que dans $expedition_fleet il y ait les id des vaiseaux (PT,GT, etc.) et leur nombre, tout le reste est ignoré. | |
</code> | |
| |
À tout hasard, si l'on veut le prix de la destruction d'un bâtiment : | |
<code php PHP> | |
/** @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); | |
</code> | |
| |
===== Formules du temps ===== | |
<code php PHP> | |
/** @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' / le reste est ignoré) | |
* @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'); | |
| |
//Exemples d'utilisations : | |
$temps_M = ogame_construction_time('M', 38, array('UdR'=>10,'UdN'=>8); //Temps de construction en seconde d'une M38 avec robot 10 et nanite 8. | |
$temps_RIP = ogame_construction_time('EDLM',1000,array('UdR'=>10,'UdN'=>8,'CSp'=>20); //Temps de construction en seconde de 1000RIP avec robot 10 et nanite 8 dans un chantier 20. | |
$temps_RIP = ogame_construction_time('EDLM',1000,$user_building); //Sinon plus automatique pour la planète courante | |
| |
$cumul_labo = ogame_labo_cumulate($user_empire['building'], $current_planet_id); //Si déterminé avec le labo d'un planète donnée | |
$cumul_labo = ogame_labo_cumulate($user_empire['building']); //Sinon en prennant les plus haut labos | |
$temp_NRJ = ogame_construction_time('NRJ', 21, array('Lab'=>20)); //Si l'on veut savoir sur 1 seul labo. | |
$temp_NRJ = ogame_construction_time('NRJ', 21, null, 200); //Temps de construction de NRJ21 avec 200 labo connectés. | |
$temp_NRJ = ogame_construction_time('NRJ', 21, null, 200, 'EXP'); //Temps de construction de NRJ21 avec 200 labos connectés et avec les -25% de l'explorateur. | |
| |
$a=ogame_construction_time('NRJ',21,array('Lab'=>18,'CSp'=>12,'UdR'=>10,'UdN'=>7),234); | |
$year=gmdate('Y',$a)-1970; | |
$week=gmdate('W',$a)-1; | |
$day=gmdate('z',$a)-$week*7; | |
echo $year.'a '.$week.'s '.$day.'j '.gmdate('H:i:s',$a);" //0a 21s 1j 17:37:13 | |
</code> | |
| |
===== Formules liées à la flotte ===== | |
En préliminaire, un formule permettant de fournir la distance entre 2 coordonées : | |
<code php PHP> | |
/** | |
* @brief Calculates distance between 2 coordinates. | |
* | |
* @param[in] string $a, $b Coordinates ('g:s:p') | |
* 'g1:s1:p1'->'g2:s2:p2' : normal distance calcul | |
* ':s1:p1'->'x:s2:p2 : distance between system/planet (only system is ':s1:') | |
* '::p1'->'x:x:p2 : distance between planet | |
* @param[in] array $user_techno List of techno ('RC','RI','PH', only these are checked) | |
* @param[in] string $class User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none)) | |
* @param[in] array $server_config Info of universe ('num_of_galaxies','num_of_systems','donutGalaxy','donutSystem' only these are checked) default 9/499/1/1 | |
* @return array(int 'distance','type') [default=O,'p'], type='g' for between galaxy, 's' for between system and 'p' for between a sub-system | |
*/ | |
function ogame_fleet_distance($a, $b, $user_techno=null, $class='none', $server_config=null); | |
| |
//Exemples d'utilisations : | |
$distance = ogame_fleet_distance($coord_from, $coord_to, $server_config); | |
switch ($distance['type']) { | |
case 'g': //between galaxy | |
//faire quelque chose avec $distance['distance'] pour une distance entre galaxies | |
break; | |
case 's': //between system (so inside same galaxy) | |
//faire quelque chose avec $distance['distance'] pour une distance entre systèmes d'une même galaxie | |
break; | |
case 'p': //between sub-system (so in same galaxy and same system) | |
if ($distance['distance'] === 0) { // to moon/cdr | |
//faire quelque chose avec $distance['distance'] pour une distance sur la même planète (lune ou cdr) | |
} else { //to other planet in same system | |
//faire quelque chose avec $distance['distance'] pour une distance entre planète d'un même sous-système | |
} | |
break; | |
default: | |
break; | |
} | |
</code> | |
| |
Pour connaître la consommation d'un stationnement ou expédition la fonction est la suivante : | |
<code php PHP> | |
/** @brief Calculates deut consummation for parking/expe 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); | |
</code> | |
| |
<code php PHP> | |
/** | |
* @brief Calculates the slowest chip speed of a fleet. | |
* | |
* @param[in] array $fleet List of chips | |
* @param[in] array $user_techno List of techno ('RC','RI','PH', le reste est ignoré) | |
* @param[in] string $class User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none)) | |
* @return int the slowest speed | |
*/ | |
function ogame_fleet_slowest_speed($fleet, $user_techno=null, $class='none'); | |
/** | |
* @brief Calculates time and conso to send a fleet. | |
* | |
* @param[in] string $coord_from,$coord_to Coordinates begin and end | |
* @param[in] array $fleet Array of fleet and their number (array('PT'=>10,etc.)) | |
* @param[in] int $speed_per Percentage of speed wanted | |
* @param[in] array $user_techno List of techno ('RC','RI','PH', le reste est ignoré) | |
* @param[in] string $class User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none)) | |
* @param[in] array $server_config Info of universe ('num_of_galaxies','num_of_systems','donutGalaxy','donutSystem' only these are checked) default 9/499/1/1 | |
* @param[in] string $type Indicates specific mission ('statio'/'expe', 'fuite') | |
* @param[in] int $hour_mission Number of hour of the specific mission | |
* @return array('conso', 'time'), time in seconds (one trip only) | |
*/ | |
function ogame_fleet_send($coord_from, $coord_to, $fleet, $speed_per=100, $user_techno=null, $class='none', $server_config=null, $type='', $hour_mission=0) | |
| |
//Exemples d'utilisations | |
ogame_fleet_send('1:1:1','1:1:1',array('PT'=>260),100,array('RC'=>20,'RI'=>17,'PH'=>16),'COL')); | |
echo gmdate('z:H:i:s',$a['time']); //jour:heure:minute:seconde | |
</code> | |
| |
===== Les caractéristiques Ogame ===== | |
==== Les détails d'infos pour les vaisseaux et défenses ==== | |
Les vaisseaux et les défenses dans Ogame ont des caractéristiques supplémentaires définie permettant leur utilisation dans les combats (structure,attaque,bouclier,rapidfire fait et subi,consommation,vitesse,fret). | |
La fonction suivante permet de récupérer ses valeurs de base, mais si les technologies sont fournies en les calculant à la bonne valeur. | |
<code php PHP> | |
function ogame_elements_details_base($name = 'all'); //Si on veut seulement les détails de base | |
/** @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 (utilisées : Armes/Bouclier/Protection/RC/RI/PH/Hyp) | |
* @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 = 'none'); | |
/** @brief Calculates technical data of all fleet/defence. | |
* @return array of all fleet/defence with are array of details from ogame_elements_details | |
*/ | |
function ogame_all_details($user_techno = null, $classe = 0); | |
| |
$detail_PT = ogame_elements_details_base('PT'); | |
//identique à ogame_elements_details('PT'); | |
print_r($detail_PT); | |
// Array( 'nom'=>'PT',structure'=>4000,'Bouclier'=>10,'attaque'=>5,'vitesse'=>5000,'fret'=>5000,'conso'=>10,'civil'=>true,'cout'=>['M'=>2000,'C'=>2000,D/NRJ/AM=>0], | |
// rapidfire=>['SE'=>5,'SAT'=>5,'FOR'=>5 : rapidfire fait | |
// 'CLO'=>-3,'TRA'=>-3,'EDLM'=>-250 : rapidfire subi | |
// 'PT'=>0,GT'=>0, etc pour tout les autres vaisseaux] ) | |
$detail_PT = ogame_elements_details_base('PT',array('Armes'=>20,'Bouclier'=>20,'Protection'=>20,'RC'=>20,'RI'=>17,'Hyp'=>20),'COL'); | |
//ou simplement ogame_elements_details_base('PT',$user_techno,$user_data['user_class']); | |
//Calcule les les infos du PT en fonction des techno militaire 20/20/20, des techno de vitesse 20/17 et de l'hyperespace et de la classe pour le fret. | |
print_r($detail_PT); | |
// Array( 'nom'=>'PT',structure'=>12000,'Bouclier'=>30,'attaque'=>15,'vitesse'=>54000,'fret'=>11250,'conso'=>20,'civil'=>true,'cout'=>inchangé,'rapidfire'=>inchangé) | |
</code> | |
| |
==== Les prérequis de chaque élément OGame ==== | |
La plus part des éléments Ogame ont des prérequis pour les débloquer, que ce soit un niveau de bâtiment, de technologies. | |
<code php PHP> | |
/** @brief Calculates technical data of Ogame requirement for bat/vso/def/rech. | |
* | |
* @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(); | |
| |
//Exemples d'utilisations : | |
$requi_graviton = ogame_elements_requirement('Graviton'); | |
$names = ogame_get_element_names(); | |
foreach ($names['RECH'] as $element) { | |
if ($requi_graviton[$element] !== 0) { | |
echo 'Prérequis de la techno' . $element . 'au niveau minimum : ' . $requi_graviton[$element]; | |
} | |
} | |
$current_lab = $user_building['Lab']; | |
if ($current_lab < $requi_graviton['Lab']) { | |
echo 'Graviton impossible car le niveau du laboratoire est insiffisant (min=' . $requi_graviton['Lab'] . ').'; | |
} | |
</code> | |
| |
===== Autres formules ===== | |
==== Hangars ==== | |
Capacité des hangars : | |
<code php PHP> | |
/** @brief Calculates the planet storage capacity (taille hangar). | |
* @param[in] int $level Storage building level | |
* @return float capacity | |
*/ | |
function ogame_depot_capacity($level); | |
</code> | |
| |
==== Phalange ==== | |
Portée de la phalange : | |
<code php PHP> | |
/** @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 int Range in system | |
*/ | |
function ogame_phalanx_range($level, $user_class = 'none'); | |
</code> | |
| |
==== Missile ==== | |
Fonction en relation avec les missiles (portée et vitesse): | |
<code php PHP> | |
/** @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 Universe speed | |
* @return int Speed in seconds | |
*/ | |
function ogame_missile_speed($nb_system, $speed_uni = 1); | |
</code> | |
==== Case avec terraformer ==== | |
<code php PHP> | |
/** @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); | |
</code> | |
| |
===== Fonctions utilitaires ===== | |
<code php PHP> | |
/** @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); | |
/** @brief Return coordinates in array. | |
* @param[in] string $string_coord Coordinates, in string like in Database ('2:3:4') | |
* @return array('g','s','p') of int, default is 0 ('::6' give planet position of 6) | |
*/ | |
function ogame_find_coordinates($string_coord); | |
</code> | |
| |
===== Récapitulatif des prototypes de fonctions de la Ogame formula Library ===== | |
<code php> | |
/** @brief Get an Ogame resources array. | |
* | |
* @param[in] int $metal,$cristal,$deut The needed resources | |
* @param[in] int $NRJ,$AM Optional resources (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 building/research/fleet/defence/class/resources. | |
* | |
* @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); | |
/** @brief Return coordinates in array. | |
* @param[in] string $string_coord Coordinates, in string like in Database ('2:3:4') | |
* @return array('g','s','p') of int, default is 0 ('::6' give planet position of 6) | |
*/ | |
function ogame_find_coordinates($string_coord); | |
| |
////////////////////////// PRODUCTION fonctions : ////////////////////////////// | |
/** @brief Return position resources 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 maximum number of foreuse. | |
* @param[in] int $mine_M,$mine_C,$mine_D Mine level | |
* @param[in] array $user_data array with class and officiers infos (array('user_class'=>'COL'/...,'off_geologue' or 'off_full')) | |
* @return int The max | |
*/ | |
function ogame_production_foreuse_max($mine_M, $mine_C, $mine_D, $user_data); | |
/** @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 officers 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_foreuse_bonus($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') 0 as default value | |
* @param[in] array $user_data User info for FOR only (array('user_class'=>'COL'/...,'off_geologue' or 'off_full') | |
* @param[in] array $server_config Ogame universe 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 | |
*/ | |
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 ('user_class'=>'COL'/...,'off_commandant','off_amiral','off_ingenieur','off_geologue', or 'off_full') | |
* @param[in] array $server_config Ogame universe info ('speed_uni') | |
* @return array('prod_reel, // (array ress) Production réel en prenant en compte le ratio (M/C/D ressources, NRJ prod moins la conso) | |
* 'prod_theorique', // (array ress) Producton théorique M/C/D (ratio=1, 100%) | |
* 'ratio', // (float) le ratio de production NRJ (prod_E / conso_E) | |
* 'conso_E','prod_E', // (float) Production NRJ prod_E > 0, conso_E < 0 | |
* 'prod_CES','prod_CEF','prod_SAT', // (array ress) production énergie de chaque unité ('D' de prod_CEF contient la conso en deut de la CEF) | |
* 'prod_FOR', // (array ress) production M/C/D et conso NRJ | |
* 'prod_M','prod_C','prod_D','prod_base', // (array ress) Production ressources de chaque mine (M/C/D) et leur conso (NRJ) | |
* 'prod_booster','prod_off','prod_Plasma','prod_classe', // (array ress) Production des bonus | |
* 'M','C','D','NRJ','AM', =>héritage du type ressource pour les valeurs retournées. | |
* 'nb_FOR_maxed', // (int) Nombre max de foreuse utilisées | |
* ) à part ratio/conso_E/prod_E (float) les autres sont array('M','C','D','NRJ','AM') | |
*/ | |
function ogame_production_planet($user_building, $user_technology = null, $user_data = null, $server_config = null); | |
| |
//////////////////////////// COUT fonctions : ////////////////////////////////// | |
/** @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 resource | |
*/ | |
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') resources 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); | |
| |
//////////////////////////// TEMPS fonctions : ///////////////////////////////// | |
/** @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'); | |
| |
//////////////////////////// FLOTTE fonctions : //////////////////////////////// | |
/** | |
* @brief Calculates deut consummation 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 Calculates the slowest chip speed of a fleet. | |
* | |
* @param[in] array $fleet List of chips | |
* @param[in] array $user_techno List of techno ('RC','RI','PH', le reste est ignoré) | |
* @param[in] string $class User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none)) | |
* @return int the slowest speed | |
*/ | |
function ogame_fleet_slowest_speed($fleet, $user_techno=null, $class='none'); | |
/** | |
* @brief Calculates distance between 2 coordinates. | |
* | |
* @param[in] string $a, $b Coordinates ('g:s:p') | |
* 'g1:s1:p1'->'g2:s2:p2' : normal distance calcul | |
* ':s1:p1'->'x:s2:p2 : distance between system/planet (only system is ':s1:') | |
* '::p1'->'x:x:p2 : distance between planet | |
* @param[in] array $user_techno List of techno ('RC','RI','PH', only these are checked) | |
* @param[in] string $class User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none)) | |
* @param[in] array $server_config Info of universe ('num_of_galaxies','num_of_systems','donutGalaxy','donutSystem' only these are checked) default 9/499/1/1 | |
* @return array(int 'distance','type') [default=O,'p'], type='g' for between galaxy, 's' for between system and 'p' for between a sub-system | |
*/ | |
function ogame_fleet_distance($a, $b, $user_techno=null, $class='none', $server_config=null); | |
/** | |
* @brief Calculates time and conso to send a fleet. | |
* | |
* @param[in] string $coord_from,$coord_to Coordinates begin and end | |
* @param[in] array $fleet Array of fleet and their number (array('PT'=>10,etc.)) | |
* @param[in] int $speed_per Percentage of speed wanted | |
* @param[in] array $user_techno List of techno ('RC','RI','PH', le reste est ignoré) | |
* @param[in] string $class User class ($user_data['user_class']=array('user_class'=>'COL'/GEN/EXP/none)) | |
* @param[in] array $server_config Info of universe ('num_of_galaxies','num_of_systems','donutGalaxy','donutSystem' only these are checked) default 9/499/1/1 | |
* @param[in] string $type Indicates specific mission ('statio'/'expe', 'fuite') | |
* @param[in] int $hour_mission Number of hour of the specific mission | |
* @return array('conso', 'time'), time in seconds (one trip only) | |
*/ | |
function ogame_fleet_send($coord_from, $coord_to, $fleet, $speed_per=100, $user_techno=null, $class='none', $server_config=null, $type='', $hour_mission=0) | |
/** @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 | |
*/ | |
| |
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 (utilisées : Armes/Bouclier/Protection/RC/RI/PH/Hyp) | |
* @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') | |
* @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(); | |
| |
//////////////////////////// DIVERS fonctions : //////////////////////////////// | |
/** @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 Universe 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); | |
</code> | |