2008-11-04 11:00:00 +00:00
< ? php
if ( ! defined ( 'INDEX' )) { header ( 'Location: ../' ); exit ; }
include_once ( _FCORE . " hb_game/Class/class.gerefile.php " );
$page = 'chantierspatial' ;
$titre = 'Chantier spatial' ;
$TEMP_vaisseaux = array ();
$nbstop = count ( $nomvaisn );
if ( empty ( $queryPlanete [ 'file_vais' ])) $file = new gererFile ( $queryUser [ 'prodfile' ] + 2 );
else {
$file = unserialize ( $queryPlanete [ 'file_vais' ]);
$file -> limite = $queryUser [ 'prodfile' ] + 2 ;
}
if ( $queryPlanete [ 'chantier_spatial' ] == 0 ) {
$template -> assign ( 'message' , 'Vous devez d\'abord construire un ' . strtolower ( $batiment [ 8 ]));
$template -> assign ( 'script' , '<script type="text/javascript">setTimeout(\'document.location.href="?p=batiments";\', 4000);</script>' );
$template -> assign ( 'couleur' , 'red' );
$template -> display ( 'game/erreur.tpl' );
exit ;
}
//Lancement d'une nouvelle construction
2008-11-16 11:00:00 +00:00
if ( isset ( $_GET [ 'v' ]) && is_numeric ( $_GET [ 'v' ]) && ! empty ( $nomvaisn [ $_GET [ 'v' ]]) && ! empty ( $_POST [ 'nombre' ])) {
2008-11-04 11:00:00 +00:00
$i = $_GET [ 'v' ];
$nbv = floor ( $_POST [ 'nombre' ]);
2008-11-16 11:00:00 +00:00
$a = $nomvaisnCALC [ $i ][ 0 ];
$b = $nomvaisnCALC [ $i ][ 1 ];
$c = $nomvaisnCALC [ $i ][ 2 ];
if ( $a * $nbv > $metal || $b * $nbv > $cristal || $c * $nbv > $hydrogene ) {
if ( $a != 0 ) $nbvm = $metal / $a ;
if ( $b == 0 ) $nbvc = $nbvm ;
else $nbvc = $cristal / $b ;
if ( $c == 0 ) $nbvh = $nbvc ;
else $nbvh = $hydrogene / $c ;
if ( $a == 0 ) $nbvm = $nbvh ;
$nbv = floor ( min ( $nbvm , $nbvc , $nbvh ));
}
2008-11-04 11:00:00 +00:00
if ( requestDeblok ( $nomvaisnTECH [ $i ], $queryPlanete , $queryUser ) && $nbv > 0 ) {
$n = ( $queryPlanete [ $nomvaisnVAR [ $i ]] + 1 );
2008-11-16 11:00:00 +00:00
$metal -= $a * $nbv ;
$cristal -= $b * $nbv ;
$hydrogene -= $c * $nbv ;
2008-11-04 11:00:00 +00:00
if ( $metal < 0 || $cristal < 0 || $hydrogene < 0 ) {
$template -> assign ( 'message' , 'Vous n\'avez pas assez de ressources pour démarrer cette construction.' );
$template -> assign ( 'script' , '<script type="text/javascript">setTimeout(\'document.location.href="?p=chantierspatial";\', 3500);</script>' );
$template -> assign ( 'couleur' , 'red' );
$template -> display ( 'game/erreur.tpl' );
exit ;
}
eval ( $nomvaisnCALC [ $i ][ 3 ]);
if ( $file -> addObjet ( $i , $nbv , ceil ( $sec ))) {
$export = serialize ( $file );
$bdd -> connexion ();
$bdd -> escape ( $export );
$bdd -> query ( " UPDATE $table_planete SET file_vais = ' $export ', metal = ' $metal ', cristal = ' $cristal ', hydrogene = ' $hydrogene ' WHERE id = ' $idPlan '; " );
$bdd -> deconnexion ();
}
else {
$template -> assign ( 'message' , 'Vous ne pouvez pas mettre plus de vaisseaux en file d\'attente.' );
$template -> assign ( 'script' , '<script type="text/javascript">setTimeout(\'document.location.href="?p=chantierspatial";\', 3500);</script>' );
$template -> assign ( 'couleur' , 'red' );
$template -> display ( 'game/erreur.tpl' );
exit ;
}
header ( 'Location: ?p=chantierspatial' );
exit ;
}
else {
$template -> assign ( 'message' , 'Vous n\'avez pas les technologies nécessaire pour construire ce vaisseau !' );
$template -> assign ( 'script' , '<script type="text/javascript">setTimeout(\'document.location.href="?p=chantierspatial";\', 3500);</script>' );
$template -> assign ( 'couleur' , 'red' );
$template -> display ( 'game/erreur.tpl' );
exit ;
}
}
//Annulation d'une nouvelle construction
if ( isset ( $_GET [ 'a' ]) && isset ( $nomvaisn [ $_GET [ 'a' ]])) {
$i = $_GET [ 'a' ];
if ( ! isset ( $_GET [ 'n' ])) $nbv = 1 ;
else $nbv = $_GET [ 'n' ];
if ( $file -> existe ( $i )) {
$n = ( $queryPlanete [ $nomvaisnVAR [ $i ]] + 1 );
$a = $nomvaisnCALC [ $i ][ 0 ];
$b = $nomvaisnCALC [ $i ][ 1 ];
$c = $nomvaisnCALC [ $i ][ 2 ];
$nbvr = $file -> delobjet ( $i , $nbv );
$metal += $a * $nbvr ;
$cristal += $b * $nbvr ;
$hydrogene += $c * $nbvr ;
$export = serialize ( $file );
$bdd -> connexion ();
$bdd -> escape ( $export );
$bdd -> query ( " UPDATE $table_planete SET file_vais = ' $export ', metal = ' $metal ', cristal = ' $cristal ', hydrogene = ' $hydrogene ' WHERE id = ' $idPlan '; " );
$bdd -> deconnexion ();
header ( 'Location: ?p=chantierspatial' );
exit ;
}
}
//Règler la production à la châine
/* if ( isset ( $_GET [ 'r' ]) && ( $_GET [ 'r' ] == 1 || $_GET [ 'r' ] == 0 )) {
if ( $_GET [ 'r' ]) $file -> chaine = false ;
else $file -> chaine = true ;
$export = mysql_real_escape_string ( serialize ( $file ));
mysql_query ( " UPDATE planete SET file_vais = ' $export ' WHERE id = ' $idPlan '; " );
header ( 'Location: ?p=chantierspatial' );
exit ;
} */
for ( $i = 0 ; $i < $nbstop ; $i ++ ) {
$tr = 0 ; $a = 0 ; $b = 0 ; $c = 0 ; $sec = 0 ;
$nom_bdd = $nomvaisnVAR [ $i ]; $a = $nomvaisnCALC [ $i ][ 0 ]; $b = $nomvaisnCALC [ $i ][ 1 ]; $c = $nomvaisnCALC [ $i ][ 2 ]; eval ( $nomvaisnCALC [ $i ][ 3 ]);
if ( $queryPlanete [ $nom_bdd ] > 0 ) $nombre = $queryPlanete [ $nom_bdd ]; else $nombre = 0 ;
$n = ( $queryPlanete [ $nom_bdd ] + 1 );
if ( ! empty ( $nomvaisn [ $i ]) && requestDeblok ( $nomvaisnTECH [ $i ], $queryPlanete , $queryUser )) $TEMP_vaisseaux [] =
array (
'image' => $nomvaisi [ $i ],
'nom' => $nomvaisn [ $i ],
'nombre' => $nombre ,
'description' => $nomvaisd [ $i ],
'descriptione' => addslashes ( $nomvaisd [ $i ]),
'nec_metal' => $a ,
'nec_cristal' => $b ,
'nec_hydrogene' => $c ,
'nec_metalS' => separerNombres ( $a ),
'nec_cristalS' => separerNombres ( $b ),
'nec_hydrogeneS' => separerNombres ( $c ),
'temps' => sec ( $sec ),
'num' => $i
);
}
$template -> assign ( 'vaisseaux' , $TEMP_vaisseaux );
$template -> assign ( 'chaine' , $file -> chaine );
$fileBat = array_merge ( $file -> file );
$nbfile = count ( $fileBat );
if ( $nbfile == 1 ) $template -> assign ( 'Pchaine' , true );
else $template -> assign ( 'Pchaine' , false );
if ( $nbfile == 0 ) $template -> assign ( 'Vchaine' , true );
else $template -> assign ( 'Vchaine' , false );
for ( $i = 0 ; $i < $nbfile ; $i ++ ) {
$fileBat [ $i ][ 3 ] = $nomvaisn [ $fileBat [ $i ][ 0 ]];
$fileBat [ $i ][ 4 ] = $fileBat [ $i ][ 2 ] * $fileBat [ $i ][ 1 ];
if ( $i == 0 ) {
$fileBat [ $i ][ 2 ] -= time () - $file -> timestamp ;
$fileBat [ $i ][ 4 ] -= time () - $file -> timestamp ;
}
}
$template -> assign ( 'file' , $fileBat );
?>