Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function create_village($userid, $username = '', $direction) {
- global $config;
- global $cl_units;
- global $db;
- $result = $db->query( 'SELECT * from create_village' );
- $row = $db->Fetch( $result );
- if ($direction == 'random') {
- $min = min( $row['no'], ['nw'], ['sw'], ['so'] );
- switch ($min) {
- case $row['no']: {
- $direction = 'no';
- break;
- }
- case $row['nw']: {
- $direction = 'nw';
- break;
- }
- case $row['so']: {
- $direction = 'so';
- break;
- }
- case $row['sw']: {
- $direction = 'sw';
- }
- }
- } else {
- if ($direction = 'random_left') {
- $dir = array( '1' => 'no', '2' => 'sw', '3' => 'so', '4' => 'nw' );
- $direction = $dir[$rand = rand( 1, 4 )];
- } else {
- $direction = parse( $direction );
- }
- }
- $alpha = $row[$direction . '_alpha'];
- do {
- $db->query( 'UNLOCK TABLES' );
- $size_c = mt_rand( $row[$direction . '_c'], $longest_c - $long2 = round( ( $longest_c = max( $row['no_c'], ['nw_c'], ['sw_c'], ['so_c'] ) - $row[$direction . '_c'] ) / 2 ) );
- if (90 <= ( $alpha += 90 / $row[$direction . '_c'] * $zufall = rand( 130, 250 ) / 100 )) {
- $row[$direction . '_alpha'] = rand( 1, 25 );
- $do_alpha_to_null = true;
- $row[$direction . '_c'] += mt_rand( 1, 3 );
- $alpha = $row[$direction . '_alpha'];
- } else {
- $do_alpha_to_null = false;
- }
- $x = round( sin( $bogen = $alpha * 2 * pi( ) / 360 ) * $size_c );
- $y = round( cos( $bogen ) * $size_c );
- if ($direction == 'nw') {
- $x = 525 - $x;
- $y = 525 + $y;
- }
- if ($direction == 'no') {
- $x = 525 + $x;
- $y = 525 + $y;
- }
- if ($direction == 'so') {
- $x = 525 + $x;
- $y = 525 - $y;
- }
- if ($direction == 'sw') {
- $x = 525 - $x;
- $y = 525 - $y;
- }
- $db->query( 'LOCK TABLES villages read' );
- $result = $db->query( 'SELECT COUNT(id) AS count_village FROM villages WHERE x = ' . $x . ' AND y = ' . $y );
- if (!( $row2 = $db->Fetch( $result )['count_village'])) {
- $db->query( 'UNLOCK TABLES' );
- }
- }while (!( $row2['count_village'] == '1'));
- if ($userid != '-1') {
- $lang = new aLang( 'functions', $config['lang'] );
- $villagename = parse( entparse( $username ) . 's ' . $lang->get( 'village' ) );
- } else {
- $villagename = urldecode( $config['left_name'] );
- }
- $arr = convert_to_continents( $x, $y );
- $unit = $cl_units->get_array( 'name' );
- $db->query( 'INSERT into villages (x,y,name,userid,continent,last_prod_aktu,create_time,conmap_con) VALUES (\'' . $x . '\',\'' . $y . '\',\'' . $villagename . '\',\'' . $userid . ( '\',\'' . $arr['con'] . '\',\'' ) . time( ) . '\',\'' . time( ) . '\',\'' . get_conmap( $arr[con], $x, $y ) . '\')' );
- $db->query( 'INSERT into unit_place (villages_from_id,villages_to_id) VALUES (\'' . $villageid = $db->GetLastId( ) . '\',\'' . $villageid . '\')' );
- reload_village_points( $villageid );
- load_bh( $villageid );
- if ($userid != '-1') {
- $db->query( 'UPDATE users SET villages=villages+\'1\' where id=\'' . $userid . '\'' );
- reload_player_points( $userid );
- reload_player_rangs( );
- }
- $row[$direction . '_alpha'] = $alpha;
- if ($do_alpha_to_null) {
- $row[$direction . '_alpha'] = 0;
- }
- $add_sql = '';
- $create_lager = false;
- if (0 < $config['count_create_left']) {
- if ($userid != '-1') {
- if ($row['next_left'] <= 1) {
- $create_lager = true;
- $add_sql = ',next_left=\'' . $config['count_create_left'] . '\'';
- } else {
- $add_sql = ',next_left=next_left-1';
- }
- }
- }
- $db->query( 'UPDATE create_village SET nw_c=\'' . $row['nw_c'] . '\',no_c=\'' . ['no_c'] . '\',
- so_c=\'' . ['so_c'] . '\',sw_c=\'' . ['sw_c'] . ( '\',
- ' . $direction . '=' . $direction . '+1,
- nw_alpha=\'' ) . ['nw_alpha'] . '\',no_alpha=\'' . ['no_alpha'] . '\',
- so_alpha=\'' . ['so_alpha'] . '\',sw_alpha=\'' . ['sw_alpha'] . ( '\'
- ' . $add_sql ) );
- if ($create_lager) {
- create_village( '-1', '', 'random_left' );
- }
- if ($userid != '-1') {
- return $villageid;
- }
- }
Add Comment
Please, Sign In to add comment