Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once 'config.php';
- include_once 'functions.php';
- include 'scoreboard_include.php';
- function generateFormation ($aSpelers, $aWissels, $aTeams, $aFormatie) {
- $aPlayers = array();
- $aChanges = array();
- $aAantal = array('K'=>0, 'V'=>0, 'M'=>0, 'A'=>0);
- $aPosities = array();
- for ( $i = 1; $i < sizeof($aSpelers); $i ++ ) {
- $sPositie = substr($aSpelers[$i]['bpositie'], 0, 1);
- $aPlayers[$i] = $aSpelers[$i]['bpositie'];
- $aPosities[$aSpelers[$i]['bpositie']] = TRUE;
- $aAantal[$sPositie] ++;
- }
- for ( $i = 1; $i < sizeof($aWissels); $i ++ ) {
- $aChanges[$i] = $aWissels[$i]['positie'];
- }
- if ($aAantal['K'] == 0) {
- foreach ( $aChanges as $nr => $pos ) {
- if ($pos == "K") {
- $aSpelers[] = array (
- 'naam' => $aWissels[$nr]['naam'],
- 'bpositie' => 'K',
- 'positie' => 'K',
- 'A' => $aWissels[$nr]['A'],
- 'M' => $aWissels[$nr]['M'],
- 'V' => $aWissels[$nr]['V'],
- 'K' => $aWissels[$nr]['K'],
- 'status' => $aWissels[$nr]['status']
- );
- $aTeams['K'] += $aWissels[$nr]['K'];
- unset($aWissels[$nr]);
- unset($aChanges[$nr]);
- break;
- }
- }
- }
- if ($aAantal['A'] < $aFormatie['A']) {
- for ( $i = 1; $i <= $aFormatie['A']; $i ++ ) {
- if (!isset($aPosities['A'.$i])) {
- foreach ( $aChanges as $nr => $pos ) {
- if ($pos == "A") {
- $aSpelers[] = array (
- 'naam' => $aWissels[$nr]['naam'],
- 'bpositie' => 'A'.$i,
- 'positie' => $aWissels[$nr]['positie'],
- 'A' => $aWissels[$nr]['A'],
- 'M' => $aWissels[$nr]['M'],
- 'V' => $aWissels[$nr]['V'],
- 'K' => $aWissels[$nr]['K'],
- 'status' => $aWissels[$nr]['status']
- );
- $aTeams['A'] += $aWissels[$nr]['A'];
- unset($aWissels[$nr]);
- unset($aChanges[$nr]);
- break;
- }
- }
- }
- }
- }
- if ($aAantal['M'] < $aFormatie['M']) {
- for ( $i = 1; $i <= $aFormatie['M']; $i ++ ) {
- if (!isset($aPosities['M'.$i])) {
- foreach ( $aChanges as $nr => $pos ) {
- if ($pos == "M") {
- $aSpelers[] = array (
- 'naam' => $aWissels[$nr]['naam'],
- 'bpositie' => 'M'.$i,
- 'positie' => $aWissels[$nr]['positie'],
- 'A' => $aWissels[$nr]['A'],
- 'M' => $aWissels[$nr]['M'],
- 'V' => $aWissels[$nr]['V'],
- 'K' => $aWissels[$nr]['K'],
- 'status' => $aWissels[$nr]['status']
- );
- $aTeams['M'] += $aWissels[$nr]['M'];
- unset($aWissels[$nr]);
- unset($aChanges[$nr]);
- break;
- }
- }
- }
- }
- }
- if ($aAantal['V'] < $aFormatie['V']) {
- for ( $i = 1; $i <= $aFormatie['V']; $i ++ ) {
- if (!isset($aPosities['V'.$i])) {
- foreach ( $aChanges as $nr => $pos ) {
- if ($pos == "V") {
- $aSpelers[] = array (
- 'naam' => $aWissels[$nr]['naam'],
- 'bpositie' => 'V'.$i,
- 'positie' => $aWissels[$nr]['positie'],
- 'A' => $aWissels[$nr]['A'],
- 'M' => $aWissels[$nr]['M'],
- 'V' => $aWissels[$nr]['V'],
- 'K' => $aWissels[$nr]['K'],
- 'status' => $aWissels[$nr]['status']
- );
- $aTeams['V'] += $aWissels[$nr]['V'];
- unset($aWissels[$nr]);
- unset($aChanges[$nr]);
- break;
- }
- }
- }
- }
- }
- $aArray = array ($aSpelers, $aWissels, $aTeams, $aFormatie);
- return $aArray;
- }
- function goal($iTeamID, $sSoort2) {
- global $aSpelers, $sSoort, $aTeamID, $aSpecialist, $aShots, $iWedstrijdLengte;
- if ($sSoort2 == 0) {
- $iRand = rand(1, 10);
- if ($iRand <= 5) $sPos = 'A';
- elseif ($iRand > 5 && $iRand <= 8) $sPos = 'M';
- else $sPos = 'V';
- $iRandom = rand(1, 11);
- while ( !isset($aSpelers[$iTeamID][$iRandom]) || $aSpelers[$iTeamID][$iRandom]['positie'] != $sPos ) {
- $iRandom = rand(1, 11);
- }
- $sSpeler = $aSpelers[$iTeamID][$iRandom]['naam'];
- }elseif ($sSoort2 == 1) {
- $sSpeler = $aSpelers[$iTeamID][$aSpecialist[$iTeamID]['penaltie']]['naam'];
- }elseif ($sSoort2 == 2) {
- $sSpeler = $aSpelers[$iTeamID][$aSpecialist[$iTeamID]['FK']]['naam'];
- }
- if ($sSoort == "L") {
- $sQuery9 = 'UPDATE players SET goals = goals + 1 WHERE name = "' . $sSpeler . '" AND teamID = ' . $aTeamID[$iTeamID];
- $iResult9 = mysql_query($sQuery9);
- }
- if ($iWedstrijdLengte < 95) $iWedstrijdLengte += 0.5;
- return $sSpeler;
- }
- function redCard ($iTeamID) {
- global $aSpelers, $aTeams, $sSoort, $aTeamID, $iWedstrijdLengte;
- $iRandom = rand(1, 11);
- while ( isset($aSpelers[$iTeamID][$iRandom]) == FALSE ) {
- $iRandom = rand(1, 11);
- }
- $sSpeler = $aSpelers[$iTeamID][$iRandom]['naam'];
- $aTeams[$iTeamID]['A'] -= $aSpelers[$iTeamID][$iRandom]['A'];
- $aTeams[$iTeamID]['M'] -= $aSpelers[$iTeamID][$iRandom]['M'];
- $aTeams[$iTeamID]['V'] -= $aSpelers[$iTeamID][$iRandom]['V'];
- $aTeams[$iTeamID]['K'] -= $aSpelers[$iTeamID][$iRandom]['K'];
- unset($aSpelers[$iTeamID][$iRandom]);
- $iLengte = rand(2, 6);
- $sQuery6 = 'UPDATE players SET status = "R' . $iLengte . '", basisposition="W" WHERE name = "' . $sSpeler . '" AND teamID = ' . $aTeamID[$iTeamID];
- $iResult6 = mysql_query($sQuery6);
- if ($iWedstrijdLengte < 95) $iWedstrijdLengte += 0.5;
- return $sSpeler;
- }
- function yellowCard ($iTeamID) {
- global $aSpelers, $sSoort, $aTeamID, $aTeams, $iWedstrijdLengte;
- $iRandom = rand(1, 11);
- while ( isset($aSpelers[$iTeamID][$iRandom]) == FALSE ) {
- $iRandom = rand(1, 11);
- }
- $sSpeler = $aSpelers[$iTeamID][$iRandom]['naam'];
- $sQuery7 = 'SELECT * FROM players WHERE name = "' . $sSpeler . '" AND teamID = ' . $aTeamID[$iTeamID];
- $iResult7 = mysql_query($sQuery7);
- $aObject7 = mysql_fetch_object($iResult7);
- if ($iWedstrijdLengte < 95) $iWedstrijdLengte += 0.5;
- if ($aObject7->status == "G") {
- $iLengte = rand(1, 4);
- $sQuery6 = 'UPDATE players SET status = "R' . $iLengte . '", basisposition="W" WHERE name = "' . $sSpeler . '" AND teamID = ' . $aTeamID[$iTeamID];
- $iResult6 = mysql_query($sQuery6);
- $aTeams[$iTeamID]['A'] -= $aSpelers[$iTeamID][$iRandom]['A'];
- $aTeams[$iTeamID]['M'] -= $aSpelers[$iTeamID][$iRandom]['M'];
- $aTeams[$iTeamID]['V'] -= $aSpelers[$iTeamID][$iRandom]['V'];
- $aTeams[$iTeamID]['K'] -= $aSpelers[$iTeamID][$iRandom]['K'];
- unset($aSpelers[$iTeamID][$iRandom]);
- return 'YR-' . $sSpeler;
- }else{
- $sQuery6 = 'UPDATE players SET status = "G" WHERE name = "' . $sSpeler . '" AND teamID = ' . $aTeamID[$iTeamID];
- $iResult6 = mysql_query($sQuery6);
- return $sSpeler;
- }
- }
- function injury ($iTeamID) {
- global $aSpelers, $aTeams, $sSoort, $aTeamID, $aWissels, $iWedstrijdLengte;
- $iRandom = rand(1, 11);
- while ( isset($aSpelers[$iTeamID][$iRandom]) == FALSE ) {
- $iRandom = rand(1, 11);
- }
- $sSpeler = $aSpelers[$iTeamID][$iRandom]['naam'];
- $sPos = substr($aSpelers[$iTeamID][$iRandom]['bpositie'], 0, 1);
- $aChanges = array();
- foreach ( $aWissels[$iTeamID] as $nr => $pos ) {
- if ($aWissels[$iTeamID][$nr]['positie'] == $sPos) $aChanges[] = $nr;
- }
- if (sizeof($aChanges) > 0) {
- $iRandom1 = $aChanges[0];
- $aTeams[$iTeamID]['A'] += $aWissels[$iTeamID][$iRandom1]['A'];
- $aTeams[$iTeamID]['M'] += $aWissels[$iTeamID][$iRandom1]['M'];
- $aTeams[$iTeamID]['V'] += $aWissels[$iTeamID][$iRandom1]['V'];
- $aTeams[$iTeamID]['K'] += $aWissels[$iTeamID][$iRandom1]['K'];
- $sWissel = ' > ' . $aWissels[$iTeamID][$iRandom1]['naam'];
- }else $sWissel = '';
- $aTeams[$iTeamID]['A'] -= $aSpelers[$iTeamID][$iRandom]['A'];
- $aTeams[$iTeamID]['M'] -= $aSpelers[$iTeamID][$iRandom]['M'];
- $aTeams[$iTeamID]['V'] -= $aSpelers[$iTeamID][$iRandom]['V'];
- $aTeams[$iTeamID]['K'] -= $aSpelers[$iTeamID][$iRandom]['K'];
- $aSpelers[$iTeamID][$iRandom] = $aWissels[$iTeamID][$iRandom1];
- unset($aWissels[$iTeamID][$iRandom1]);
- $iLengte = rand(1, 4);
- $sQuery11 = 'UPDATE players SET status = "B' . $iLengte . '" WHERE name = "' . $sSpeler . '" AND teamID = ' . $iTeamID;
- $iResult11 = mysql_query($sQuery11);
- if ($iWedstrijdLengte < 95) $iWedstrijdLengte += 0.5;
- return $sSpeler . $sWissel;
- }
- function shot($iTeamID, $iS = 0) {
- global $aSpelers, $sSoort, $aTeamID, $aSpecialist, $aShots, $aCorners;
- $sSpeler = '';
- if ($iS == 1) $aCorners[$iTeamID] ++;
- elseif ($iS == 2) $sSpeler = $aSpelers[$iTeamID][$aSpecialist[$iTeamID]['penaltie']]['naam'];
- elseif ($iS == 3) $sSpeler = $aSpelers[$iTeamID][$aSpecialist[$iTeamID]['FK']]['naam'];
- if ($sSpeler == '') {
- $iRand = rand(1, 10);
- if ($iRand <= 5) $sPos = 'A';
- elseif ($iRand > 5 && $iRand <= 8) $sPos = 'M';
- else $sPos = 'V';
- $iRandom = rand(1, 11);
- while ( !isset($aSpelers[$iTeamID][$iRandom]) || $aSpelers[$iTeamID][$iRandom]['positie'] != $sPos ) {
- $iRandom = rand(1, 11);
- }
- $sSpeler = $aSpelers[$iTeamID][$iRandom]['naam'];
- }
- return $sSpeler;
- }
- $sSql = 'SELECT * FROM competities WHERE divisie = 5';
- $iQuery = mysql_query($sSql);
- while ( $aResult = mysql_fetch_object($iQuery) ) {
- $sQueryH = 'UPDATE competities SET simuleren = 1 WHERE id = ' . $aResult->id;
- $iResultH = mysql_query($sQueryH);
- $sSql1 = 'SELECT * FROM kalender WHERE land = ' . $aResult->id . ' AND week = ' . $aResult->week;
- $iQuery1 = mysql_query($sSql1);
- if (mysql_num_rows($iQuery1) > 0) {
- $aResult1 = mysql_fetch_object($iQuery1);
- $sSoort = $aResult1->soort;
- if ($sSoort == "P" || $sSoort == "") {
- $sQuery6 = 'UPDATE competities SET week=week+1, simuleren = 0 WHERE id='. $aResult->id;
- $iResult6 = mysql_query($sQuery6);
- continue;
- }
- $sQuery1 = 'SELECT * FROM matches WHERE land=' . $aResult->id . ' AND week=' . $aResult->week;
- $iResult1 = mysql_query($sQuery1);
- $sQuery18 = 'SELECT * FROM players WHERE land = ' . $aResult->id . ' AND status != "G" AND status != ""';
- $iResult18 = mysql_query($sQuery18);
- while ( $aObject18 = mysql_fetch_object($iResult18) ) {
- $iOud = intval(substr($aObject18->status, 1, 1));
- if ($iOud > 1) $sNieuw = substr($aObject18->status, 0, 1) . ($iOud - 1);
- else $sNieuw = '';
- $sQuery19 = 'UPDATE players SET status = "' . $sNieuw . '" WHERE id = ' . $aObject18->id;
- $iResult19 = mysql_query($sQuery19);
- }
- setFinances($aResult->id, $aResult->week);
- while ( $aResult1 = mysql_fetch_object($iResult1) ) {
- echo $aResult1->team1 . ' - ' . $aResult1->team2 . '<br />';
- $sSql2 = 'SELECT * FROM teams WHERE land = ' . $aResult->id . ' AND name = "' . $aResult1->team1 . '"';
- $sSql3 = 'SELECT * FROM teams WHERE land = ' . $aResult->id . ' AND name = "' . $aResult1->team2 . '"';
- $iQuery2 = mysql_query($sSql2) or die($sSql1 . '<br />' . mysql_error());
- $iQuery3 = mysql_query($sSql3) or die($sSql3 . '<br />' . mysql_error());
- $aResult2 = mysql_fetch_object($iQuery2);
- $aResult3 = mysql_fetch_object($iQuery3);
- $aCoach[0] = $aResult2->trainer;
- $aCoach[1] = $aResult3->trainer;
- $aTeamID[0] = $aResult2->id;
- $aTeamID[1] = $aResult3->id;
- $aSpelers = array();
- $aWissels = array();
- $aTeams = array();
- $aTeams[0] = array('naam'=>'', 'A'=>0, 'M'=>0, 'V'=>0, 'K'=>0);
- $aTeams[1] = array('naam'=>'', 'A'=>0, 'M'=>0, 'V'=>0, 'K'=>0);
- $aTeams[0]['naam'] = $aResult1->team1;
- $aTeams[1]['naam'] = $aResult1->team2;
- $aStyles = array ('Rustig' => 240, 'Normaal' => 120, 'Hard' => 60, 'Aggressief' => 30);
- $aStyle[0] = $aStyles[$aResult2->style];
- $aStyle[1] = $aStyles[$aResult3->style];
- $aFormatie = array();
- $aFormation = explode('-', $aResult2->formation);
- $aFormatie[0]['V'] = $aFormation[0];
- $aFormatie[0]['M'] = $aFormation[1];
- $aFormatie[0]['A'] = $aFormation[2];
- $aFormation = explode('-', $aResult2->formation);
- $aFormatie[1]['V'] = $aFormation[0];
- $aFormatie[1]['M'] = $aFormation[1];
- $aFormatie[1]['A'] = $aFormation[2];
- $aSpecialist = array();
- for ( $i = 0; $i <= 1; $i ++ ) {
- $aSpelers[$i] = array();
- $aWissels[$i] = array();
- $sSql4 = 'SELECT * FROM players WHERE teamID = ' . $aTeamID[$i];
- $iQuery4 = mysql_query($sSql4) or die($sSql4 . '<br />' . mysql_error());
- $sQuery10 = 'UPDATE players SET status="" WHERE status="G" AND teamID = ' . $aTeamID[$i];
- $iResult10 = mysql_query($sQuery10);
- $ii = 1;
- $sQuery12 = 'SELECT * FROM specialisten WHERE team_id = ' . $aTeamID[$i];
- $iResult12 = mysql_query($sQuery12);
- $aObject12 = mysql_fetch_object($iResult12);
- $aSpecialist[$i] = array();
- while ( $aResult4 = mysql_fetch_object($iQuery4) ) {
- if ($aResult4->basisposition != "W" && ($aResult4->status == "" || $aResult4->status == "G")) {
- $aSpelers[$i][$ii]['naam'] = $aResult4->name;
- $aSpelers[$i][$ii]['bpositie'] = $aResult4->basisposition;
- $aSpelers[$i][$ii]['positie'] = $aResult4->position;
- $aSpelers[$i][$ii]['A'] = $aResult4->aanval;
- $aSpelers[$i][$ii]['M'] = $aResult4->middenveld;
- $aSpelers[$i][$ii]['V'] = $aResult4->verdediging;
- $aSpelers[$i][$ii]['K'] = $aResult4->keeper;
- $aSpelers[$i][$ii]['status'] = $aResult4->status;
- $aTeams[$i][$aResult4->position] += $aSpelers[$i][$ii][$aResult4->position];
- if ($aResult4->id == $aObject12->penaltie) $aSpecialist[$i]['penaltie'] = $ii;
- if ($aResult4->id == $aObject12->vrije_trap) $aSpecialist[$i]['FK'] = $ii;
- $ii ++;
- }
- }
- $iii = 1;
- $iQuery4 = mysql_query($sSql4);
- while ( $aResult4 = mysql_fetch_object($iQuery4) ) {
- if ($aResult4->basisposition == "W" && ($aResult4->status == "" || $aResult4->status == "G")) {
- $aWissels[$i][$iii]['naam'] = $aResult4->name;
- $aWissels[$i][$iii]['bpositie'] = $aResult4->basisposition;
- $aWissels[$i][$iii]['positie'] = $aResult4->position;
- $aWissels[$i][$iii]['A'] = $aResult4->aanval;
- $aWissels[$i][$iii]['M'] = $aResult4->middenveld;
- $aWissels[$i][$iii]['V'] = $aResult4->verdediging;
- $aWissels[$i][$iii]['K'] = $aResult4->keeper;
- $aWissels[$i][$iii]['status'] = $aResult4->status;
- $iii ++;
- }
- }
- if ($ii < 11) {
- $aArray = generateFormation ($aSpelers[$i], $aWissels[$i], $aTeams[$i], $aFormatie[$i]);
- $aSpelers[$i] = $aArray[0];
- $aWissels[$i] = $aArray[1];
- $aTeams[$i] = $aArray[2];
- $aFormatie[$i] = $aArray[3];
- }
- if ($aCoach[$i] == '') {
- $aTeams[$i]['A'] -= 20;
- $aTeams[$i]['M'] -= 20;
- $aTeams[$i]['V'] -= 20;
- $aTeams[$i]['K'] -= 20;
- }
- }
- $iVeld = 1000;
- $aBal = array(500);
- $iBal = 500;
- $aGoals = array(0=>array(), 1=>array());
- $aShots = array(0=>array(), 1=>array()); //0 = naast, 1 = keeper houdt tegen, 2 = keeper tikt corner, 3 = doelpunt, 4 = FK raak, 5 = FK mis, 6 = P raak, 7 = P mis
- $aCorners = array(0=>0, 1=>0);
- $aRedCards = array(0=>array(), 1=>array());
- $aYellowCards = array(0=>array(), 1=>array());
- $aFreeKicks = array(0=>array(), 1=>array());
- $aInjuries = array(0=>array(), 1=>array());
- $iWedstrijdLengte = 90;
- for ( $i = 1; $i <= $iWedstrijdLengte; $i ++ ) {
- if (rand(1, $aStyle[0]) < 3) {
- $iR = rand(1, 10);
- if ($iR < 2) {
- $aRedCards[0][$i] = redCard(0);
- $iNr = 3;
- }elseif ($iR >= 2 && $iR <= 6) {
- $aYellowCards[0][$i] = yellowCard(0);
- $iNr = 8;
- }else $iNr = 20;
- if (rand(0, $iNr) == 1) {
- $aInjuries[1][$i] = injury(1);
- }
- if (isset($aSpecialist[1]['penaltie']) && $iBal <= 100) {
- if (rand(1, 2) == 1) {
- $aGoals[1][$i] = goal(1, 1);
- $aShots[1][$i][6] = $aGoals[1][$i];
- $iBal = 500;
- }else{
- $aShots[1][$i][7] = shot(1, 2);
- }
- }elseif (isset($aSpecialist[1]['FK']) && $iBal > 100) {
- if (rand(1, $iBal/15) == 1) {
- $aGoals[1][$i] = goal(1, 2);
- $aShots[1][$i][4] = $aGoals[1][$i];
- $iBal = 500;
- }else{
- $aShots[1][$i][5] = shot(1, 3);
- }
- }
- }elseif (rand(1, $aStyle[1]) < 3) {
- $iR = rand(1, 10);
- if ($iR < 2) {
- $aRedCards[1][$i] = redCard(1);
- $iNr = 3;
- }elseif ($iR >= 2 && $iR <= 6) {
- $aYellowCards[1][$i] = yellowCard(1);
- $iNr = 8;
- }else $iNr = 20;
- if (rand(0, $iNr) == 1) $aInjuries[0][$i] = injury(0);
- if (isset($aSpecialist[0]['penaltie']) && $iBal >= 900) {
- if (rand(1, 2) == 1) {
- $aGoals[0][$i] = goal(0, 1);
- $aShots[0][$i][6] = $aGoals[0][$i];
- $iBal = 500;
- }else{
- $aShots[0][$i][7] = shot(0, 2);
- }
- }elseif (isset($aSpecialist[0]['FK']) && $iBal < 900) {
- if (rand(1, (1000-$iBal)/15) == 1) {
- $aGoals[0][$i] = goal(0, 2);
- $aShots[0][$i][4] = $aGoals[0][$i];
- $iBal = 500;
- }else{
- $aShots[0][$i][5] = shot(0, 3);
- }
- }
- }
- $iBal += rand(0, $aTeams[0]['M']);
- $iBal -= rand(0, $aTeams[1]['V']);
- if ($iBal >= 1000) {
- if (rand(0, 1) == 0) { //schot
- $iRand = rand(1, 10);
- if (rand(0, 1) == 0) { //schot tussen palen
- if ($iRand <= 1) { //doelpunt
- $aGoals[0][$i] = goal(0, 0);
- $aShots[0][$i][3] = $aGoals[0][$i];
- $iBal = 500;
- }elseif ($iRand >= 5 && $iRand <= 9) {
- $aShots[0][$i][1] = shot(0); //keeper houdt tegen
- if (rand(0, 1) == 0) $iBal -= 500;
- }else $aShots[0][$i][2] = shot(0, 1); //keeper tikt corner
- }else{ //schot naast
- if ($iRand <= 3) $aShots[0][$i][2] = shot(0, 1); //corner
- else $aShots[0][$i][0] = shot(0); //naast
- }
- }else { //actie
- $iBal += rand(0, $aTeams[0]['A']);
- $iBal -= rand(0, $aTeams[1]['K']);
- if ($iBal >= 1500) { //doelpunt
- $aGoals[0][$i] = goal(0, 0);
- $aShots[0][$i][3] = $aGoals[0][$i];
- $iBal = 500;
- }
- }
- }
- $iBal -= rand(0, $aTeams[1]['M']);
- $iBal += rand(0, $aTeams[0]['V']);
- if ($iBal <= 0) {
- if (rand(0, 1) == 0) { //schot
- $iRand = rand(1, 10);
- if (rand(0, 1) == 0) { //schot tussen palen
- if ($iRand <= 1) { //doelpunt
- $aGoals[1][$i] = goal(1, 0);
- $aShots[1][$i][3] = $aGoals[1][$i];
- $iBal = 500;
- }elseif ($iRand >= 5 && $iRand <= 9) {
- $aShots[1][$i][1] = shot(1); //keeper houdt tegen
- if (rand(0, 1) == 0) $iBal += 500;
- }else $aShots[1][$i][2] = shot(1, 1); //keeper tikt corner
- }else{ //schot naast
- if ($iRand <= 3) $aShots[1][$i][2] = shot(1, 1); //corner
- else $aShots[1][$i][0] = shot(1); //naast
- }
- }else { //actie
- $iBal += rand(0, $aTeams[1]['A']);
- $iBal -= rand(0, $aTeams[0]['K']);
- if ($iBal <= -500) { //doelpunt
- $aGoals[1][$i] = goal(1, 0);
- $aShots[1][$i][3] = $aGoals[1][$i];
- $iBal = 500;
- }
- }
- }
- $aBal[] = $iBal;
- if ($i == 45) $iBal = 500;
- }
- $aBalbezit[0] = 50;
- $aBalbezit[1] = 50;
- $iBAL = 0;
- foreach ( $aBal as $min => $bal ) {
- $iBAL += $bal;
- }
- $iBAL = round($iBAL/900);
- if ($iBAL < 30) $iBAL += 10;
- if ($iBAL > 70) $iBAL -= 10;
- if (sizeof($aGoals[0]) > sizeof($aGoals[1])) {
- if ($iBAL > 50) {
- $aBalbezit[0] = $iBAL;
- $aBalbezit[1] = 100-$iBAL;
- }else{
- $aBalbezit[0] = 100-$iBAL;
- $aBalbezit[1] = $iBAL;
- }
- }else{
- if ($iBAL > 50) {
- $aBalbezit[1] = $iBAL;
- $aBalbezit[0] = 100-$iBAL;
- }else{
- $aBalbezit[1] = 100-$iBAL;
- $aBalbezit[0] = $iBAL;
- }
- }
- if (sizeof($aGoals[0]) == sizeof($aGoals[1]) && $sSoort == "C") {
- $aPenalties = array( 0 => 0, 1 => 0 );
- for ( $i = 1; $i <= 5; $i ++ ) {
- if (rand(0, 1) == 1) $aPenalties[0] ++;
- else $aPenalties[1] ++;
- if ($i < 5) {
- if ($aPenalties[0] + 3 == $aPenalties[1] || $aPenalties[1] + 3 == $aPenalties[0]) break;
- }elseif ($aPenalties[0] != $aPenalties[1]) break;
- }
- if ($aPenalties[0] == $aPenalties[1]) {
- if (rand(0, 1) == 1) $aPenalties[0] ++;
- else $aPenalties[1] ++;
- }
- }
- $sVerslag = '';
- $aSoorten = array ( 0 => 'SN', 1 => 'SK', 2 => 'SC', 3 => 'SD', 4 => 'FK1', 5 => 'FK2', 6 => 'P1', 7 => 'P2' );
- $aSchoten = array (0 => 0, 1 => 0);
- $aSchotenOpDoel = array (0 => 0, 1 => 0);
- for ( $i = 0; $i <= 1; $i ++ ) {
- ksort($aGoals[$i]);
- ksort($aRedCards[$i]);
- ksort($aYellowCards[$i]);
- ksort($aInjuries[$i]);
- ksort($aShots[$i]);
- for ( $ii = 1; $ii <= $iWedstrijdLengte; $ii ++ ) {
- if ($aRedCards[$i][$ii] != '') {
- $sVerslag .= 'R-' . $ii . '-' . $aRedCards[$i][$ii] . '-' . rand(0, count($scoreboardRodeKaarten)-1) . ';';
- }
- if ($aYellowCards[$i][$ii] != '') {
- if (preg_match('/^YR-/', $aYellowCards[$i][$ii])) $sVerslag .= 'YR-' . $ii . '-' . substr($aYellowCards[$i][$ii], 3) . '-' . rand(0, count($scoreboardGeleRodeKaarten)-1) . ';';
- else $sVerslag .= 'Y-' . $ii . '-' . $aYellowCards[$i][$ii] . '-' . rand(0, count($scoreboardGeleKaarten)-1) . ';';
- }
- if ($aInjuries[$i][$ii] != '') {
- $sVerslag .= 'B-' . $ii . '-' . $aInjuries[$i][$ii] . '-' . rand(0, count($scoreboardBlessures)-1) . ';';
- }
- if ($aGoals[$i][$ii] != '' && $aShots[$i][$ii][4] == '' && $aShots[$i][$ii][6] == '') {
- $sVerslag .= 'D-' . $ii . '-' . $aGoals[$i][$ii] . '-' . rand(0, count($scoreboardDoelpunten)-1) . ';';
- }
- if ($aShots[$i][$ii][4] != '') {
- $sVerslag .= 'FK1-' . $ii . '-' . $aShots[$i][$ii][4] . '-' . rand(0, count($scoreboardVrijetrapRaak)-1) . ';';
- }
- if ($aShots[$i][$ii][6] != '') {
- $sVerslag .= 'P1-' . $ii . '-' . $aShots[$i][$ii][6] . '-' . rand(0, count($scoreboardPenaltieRaak)-1) . ';';
- }
- }
- foreach ( $aShots[$i] as $min => $naam ) {
- foreach ( $aShots[$i][$min] as $soort => $naam2 ) {
- if ($soort == 0) $aSchot = $scoreboardSchotenNaast;
- elseif ($soort == 1) $aSchot = $scoreboardSchotenKeeper;
- elseif ($soort == 2) $aSchot = $scoreboardSchotenCorner;
- elseif ($soort == 5) $aSchot = $scoreboardVrijetrapMis;
- elseif ($soort == 7) $aSchot = $scoreboardPenaltieMis;
- else continue;
- $sVerslag .= $aSoorten[$soort] . '-' . $min . '-' . $naam2 . '-' . rand(0, count($aSchot)-1) . ';';
- if ($soort > 0) $aSchotenOpDoel[$i] ++;
- else $aSchoten[$i] ++;
- }
- }
- if ($i == 0) $sVerslag .= '|';
- }
- if (sizeof($aGoals[0]) > sizeof($aGoals[1])) {
- $aPunten[0] = 3;
- $aPunten[1] = 0;
- $aSoort[0] = 'won';
- $aSoort[1] = 'lose';
- $aSoort1[0] = 'gewonnen';
- $aSoort1[1] = 'verloren';
- }elseif (sizeof($aGoals[0]) < sizeof($aGoals[1])) {
- $aPunten[1] = 3;
- $aPunten[0] = 0;
- $aSoort[0] = 'lose';
- $aSoort[1] = 'won';
- $aSoort1[1] = 'gewonnen';
- $aSoort1[0] = 'verloren';
- }else{
- $aPunten[0] = 1;
- $aPunten[1] = 1;
- $aSoort[0] = 'draw';
- $aSoort[1] = 'draw';
- $aSoort1[0] = 'gelijk';
- $aSoort1[1] = 'gelijk';
- }
- $sQuery18 = 'UPDATE users SET ' . $aSoort1[$i] . '=' . $aSoort1[$i] . '+1 WHERE teamID = ' . $aTeamID[$i];
- $iResult18 = mysql_query($sQuery18);
- if ($sSoort == "L") {
- $sQuery12 = '
- UPDATE
- matches
- SET
- score1=' . sizeof($aGoals[0]) . ',
- score2=' . sizeof($aGoals[1]) . ',
- balbezit1=' . $aBalbezit[0] . ',
- balbezit2=' . $aBalbezit[1] . ',
- schoten1="' . $aSchoten[0] . '/' . $aSchotenOpDoel[0] . '",
- schoten2="' . $aSchoten[1] . '/' . $aSchotenOpDoel[1] . '",
- corners1=' . $aCorners[0] . ',
- corners2=' . $aCorners[1] . ',
- gebeurtenissen="' . $sVerslag . '",
- lengte = ' . $iWedstrijdLengte . '
- WHERE
- id=' . $aResult1->id;
- $iResult12 = mysql_query($sQuery12) or die($sQuery12 . '<br />' . mysql_error());
- $aDoelpunten = array();
- $aDoelpunten[0] = sizeof($aGoals[0]) - sizeof($aGoals[1]);
- $aDoelpunten[1] = sizeof($aGoals[1]) - sizeof($aGoals[0]);
- for ( $i = 0; $i <= 1; $i ++ ) {
- $sQuery13 = '
- UPDATE
- teams
- SET
- points=points+' . $aPunten[$i] . ',
- ' . $aSoort[$i] . '=' . $aSoort[$i] . '+1,
- goals=goals+' . $aDoelpunten[$i] . ',
- matches=matches+1
- WHERE
- id=' . $aTeamID[$i] . '
- ';
- $iResult13 = mysql_query($sQuery13);
- }
- }elseif ($sSoort == "C") {
- $sQuery12 = '
- UPDATE
- matches
- SET
- score1=' . sizeof($aGoals[0]) . ',
- score2=' . sizeof($aGoals[1]) . ',
- balbezit1=' . $aBalbezit[0] . ',
- balbezit2=' . $aBalbezit[1] . ',
- schoten1="' . $aSchoten[0] . '/' . $aSchotenOpDoel[0] . '",
- schoten2="' . $aSchoten[1] . '/' . $aSchotenOpDoel[1] . '",
- corners1=' . $aCorners[0] . ',
- corners2=' . $aCorners[1] . ',
- ';
- if (sizeof($aGoals[0]) == sizeof($aGoals[1])) $sQuery12 .= 'penalties="' . $aPenalties[0] . '-' . $aPenalties[1] . '",';
- $sQuery12 .= '
- gebeurtenissen="' . $sVerslag . '",
- lengte = ' . $iWedstrijdLengte . '
- WHERE
- id=' . $aResult1->id;
- $iResult12 = mysql_query($sQuery12) or die($sQuery12 . '<br />' . mysql_error());
- }
- }
- if ($sSoort == "L") {
- $sQuery14 = 'SELECT * FROM teams WHERE land=' . $aResult->id . ' ORDER BY points DESC, goals DESC';
- $iResult14 = mysql_query($sQuery14);
- $P = 1;
- while ( $aObject14 = mysql_fetch_object($iResult14) ) {
- if ($aObject14->matches == 0) {
- $iBest = $P;
- }else{
- if ($P < $aObject14->best_position) {
- $iBest = $P;
- }else{
- $iBest = $aObject14->best_position;
- }
- }
- $sQuery15 = 'UPDATE teams SET position=' . $P . ', best_position = ' . $iBest . ' WHERE id=' . $aObject14->id . '';
- $iResult15 = mysql_query($sQuery15);
- $P ++;
- }
- $sQuery16 = 'UPDATE competities SET week=week+1 WHERE id='. $aResult->id;
- $iResult16 = mysql_query($sQuery16) or die($sQuery16 . '<br />' . mysql_error());
- }elseif ($sSoort == "C") {
- $aTeams2 = array();
- $sQuery14 = 'SELECT * FROM teams WHERE land=' . $aResult->id;
- $iResult14 = mysql_query($sQuery14);
- while ( $aObject14 = mysql_fetch_object($iResult14) ) {
- $aTeams2[$aObject14->name] = $aObject14->name;
- }
- $iTeams = count($aTeams2);
- $sQuery13 = 'SELECT * FROM matches WHERE soort="C" AND land=' . $aResult->id . ' ORDER BY week ASC';
- $iResult13 = mysql_query($sQuery13);
- while ( $aObject13 = mysql_fetch_object($iResult13) ) {
- if ($aObject13->ronde == 0 && $aResult->cup == 0 && $iTeams > 18) {
- unset($aTeams2[$aObject13->team2]);
- unset($aTeams2[$aObject13->team1]);
- continue;
- }
- if ($aObject13->score1 > $aObject13->score2) {
- unset($aTeams2[$aObject13->team2]);
- }elseif ($aObject13->score1 < $aObject13->score2) {
- unset($aTeams2[$aObject13->team1]);
- }else{
- $aPen = explode('-', $aObject13->penalties);
- if (intval($aPen[0]) > intval($aPen[1])) unset($aTeams2[$aObject13->team2]);
- else unset($aTeams2[$aObject13->team1]);
- }
- }
- shuffle($aTeams2);
- if (sizeof($aTeams2) > 1) {
- $aCupFixtures = generateCupFixtures($aTeams2);
- $sQuery15 = 'SELECT cup FROM competities WHERE id=' .$aResult->id;
- $iResult15 = mysql_query($sQuery15);
- $aObject15 = mysql_fetch_object($iResult15);
- $aWeken = array (5, 14, 23, 32, 41);
- for ( $i = 0; $i < sizeof($aCupFixtures); $i ++ ) {
- $sQuery16 = '
- INSERT INTO
- matches
- (
- land,
- soort,
- team1,
- team2,
- ronde,
- week
- )
- VALUES
- (
- ' . $aResult->id . ',
- "C",
- "' . $aCupFixtures[$i][0] . '",
- "' . $aCupFixtures[$i][1] . '",
- "' . ($aObject15->cup+1) . '",
- "' . $aWeken[$aObject15->cup+1] . '"
- )
- ';
- $iResult16 = mysql_query($sQuery16);
- }
- $sQuery17 = 'UPDATE competities SET week=week+1, cup=cup+1 WHERE id=' . $aResult->id;
- $iResult17 = mysql_query($sQuery17);
- }else{
- $sQuery17 = 'UPDATE competities SET week=week+1 WHERE id = ' . $aResult->id;
- $iResult17 = mysql_query($sQuery17);
- $sQuery18 = 'SELECT * FROM teams WHERE name = "' . $aTeams2[0] . '"';
- $iResult18 = mysql_query($sQuery18) or die($sQuery18 . '<br />' . mysql_error());
- $aObject18 = mysql_fetch_object($iResult18);
- if ($aObject18->trainer != '') {
- $sQuery19 = 'UPDATE users SET punten=punten+50 WHERE name = "' . $aObject18->trainer . '"';
- $iResult19 = mysql_query($sQuery19);
- $sBericht = '
- Beste ' . $aObject18->trainer . ',
- Gefeliciteerd! Je hebt de beker gewonnen. Hiervoor heb je 50 punten gekregen.
- MVG,
- Assistent manager.';
- sendPM($aObject18->trainer, 'Assistent Manager', 'Beker gewonnen!', $sBericht, 1);
- }
- }
- }
- }else{
- $sQuery2 = 'SELECT * FROM teams WHERE land = ' . $aResult->id . ' ORDER BY name ASC';
- $iResult2 = mysql_query($sQuery2) or die($sQuery2 . '<br />' . mysql_error());
- $p = 1;
- while ( $aObject2 = mysql_fetch_object($iResult2) ) {
- if ($aObject2->trainer != "") {
- $sQuery12 = 'SELECT * FROM users WHERE name = "' . $aObject2->trainer . '"';
- $iResult12 = mysql_query($sQuery12) or die($sQuery12 . '<br />' . mysql_error());
- $aObject12 = mysql_fetch_object($iResult12);
- $iPunten = $aObject2->points / $aObject2->position * 2;
- $sQuery11 = 'UPDATE users SET punten = punten + ' . $iPunten . ', teamID=0, competitie=0, divisie=0 WHERE name = "' . $aObject2->trainer . '"';
- $sQuery13 = 'INSERT INTO historie (user_id, seizoen, land, club, positie, punten) VALUES ("' . $aObject12->id . '", "' . gmdate("d-m-y") . '", ' . $aObject2->land . ', "' . $aObject2->name . '", ' . $aObject2->position . ', ' . $aObject2->points . ')';
- $iResult11 = mysql_query($sQuery11) or die($sQuery11 . '<br />' . mysql_error());
- $iResult13 = mysql_query($sQuery13) or die($sQuery13 . '<br />' . mysql_error());
- }
- }
- resetServer($aObject2->land);
- }
- $sQueryG = 'UPDATE competities SET simuleren = 0 WHERE id = ' . $aResult->id;
- $iResultG = mysql_query($sQueryG);
- }
- include 'training_cron.php';
- $sQueryA = 'DELETE FROM sponsors WHERE weken = 1';
- $sQueryB = 'UPDATE sponsors SET weken = weken - 1 WHERE weken > 1';
- $sQueryC = 'UPDATE users SET premiumdagen = premiumdagen - 1 WHERE teamID != 0 AND premiumdagen > 1 AND rank = "user"';
- $sQueryD = 'UPDATE users SET premium = 0, premiumdagen = 0 WHERE premiumdagen = 1';
- $iResultA = mysql_query($sQueryA);
- $iResultB = mysql_query($sQueryB);
- $iResultC = mysql_query($sQueryC);
- $iResultD = mysql_query($sQueryD);
- $sQueryQ = 'SELECT * FROM users WHERE verwijderd < 6';
- $iResultQ = mysql_query($sQueryQ);
- while ( $aObjectQ = mysql_fetch_object($iResultQ) ) {
- if ($aObjectQ->verwijderd == 0) {
- $sQueryR = 'UPDATE teams SET trainer = "" WHERE trainer = "' . $aObjectQ->name . '"';
- $iResultR = mysql_query($sQueryR);
- $sQueryT = 'DELETE FROM users WHERE id = ' . $aObjectQ->id;
- $iResultT = mysql_query($sQueryT);
- }else{
- $sQueryR = 'UPDATE users SET verwijderd = verwijderd - 1 WHERE id = ' . $aObjectQ->id;
- $iResultR = mysql_query($sQueryR);
- }
- }
- $sQueryI = 'UPDATE users SET ban = ban - 1 WHERE ban > 0 AND ban < 100';
- $iResultI = mysql_query($sQueryI);
- $sQueryX = 'SELECT * FROM scouts';
- $iResultX = mysql_query($sQueryX);
- $aPos = array ( 1 => 'A', 'M', 'V', 'K');
- while ( $aObjectX = mysql_fetch_object($iResultX) ) {
- $sQueryZ = 'SELECT land, trainer FROM teams WHERE id = ' . $aObjectX->team_id;
- $iResultZ = mysql_query($sQueryZ);
- $aObjectZ = mysql_fetch_object($iResultZ);
- $aNaam = explode('-', generateName());
- $sNaam = $aNaam[0];
- $sLand = $aNaam[1];
- $iLeeftijd = rand(17, 19);
- $sPos = $aPos[rand(1, 4)];
- if ($sPos == 'A') {
- $iAanval = rand(50, 65);
- $iMiddenveld = rand(30, 50);
- $iVerdediging = rand(10, 30);
- $iKeeper = rand(0, 10);
- }elseif ($sPos == 'M') {
- $iAanval = rand(30, 50);
- $iMiddenveld = rand(50, 65);
- $iVerdediging = rand(30, 50);
- $iKeeper = rand(0, 10);
- }elseif ($sPos == 'V') {
- $iAanval = rand(10, 30);
- $iMiddenveld = rand(30, 50);
- $iVerdediging = rand(50, 65);
- $iKeeper = rand(5, 15);
- }elseif ($sPos == 'K') {
- $iAanval = rand(0, 10);
- $iMiddenveld = rand(0, 10);
- $iVerdediging = rand(0, 15);
- $iKeeper = rand(50, 65);
- }
- $aSkills = array ( 'A' => $iAanval, 'M' => $iMiddenveld, 'V' => $iVerdediging, 'K' => $iKeeper );
- $iWaarde = (pow($aSkills[$sPos], 5) / ($iLeeftijd * 10)) / 2.5;
- $sQueryP = 'INSERT INTO players (name,land,teamID,position,age,aanval,middenveld,verdediging,keeper,country,waarde) VALUES ("'.$sNaam.'", "' . $aObjectZ->land . '", "'.$aObjectX->team_id.'", "' . $sPos . '", ' . $iLeeftijd . ', "' . $iAanval . '", "' . $iMiddenveld . '", "' . $iVerdediging . '", "' . $iKeeper . '", "'.$sLand.'", "'.$iWaarde.'")';
- $iResultP = mysql_query($sQueryP);
- $iPlayerID = mysql_insert_id();
- $sBericht = '
- Beste ' . $aObjectZ->trainer . ',
- De scout is terug gekomen en heeft een speler aan je selectie toegevoegd.
- De speler heet <a href="player.php?id=' . $iPlayerID . '">' . $sNaam . '</a> en hij is ' . $iLeeftijd . ' jaar oud.
- Met vriendelijke groet,
- Assistent Manager';
- sendPM($aObjectZ->trainer, 'Assistent Manager', 'Scout is terug', $sBericht, 1);
- $sQueryE = 'UPDATE teams SET scout = scout + 1 WHERE id = ' . $aObjectX->team_id;
- $iResultE = mysql_query($sQueryE);
- $sQueryF = 'DELETE FROM scouts WHERE team_id = ' . $aObjectX->team_id;
- $iResultF = mysql_query($sQueryF);
- }
- echo 'Wedstrijden gespeeld.';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment