int cmdUserNewsAdd( int id, int64_t *data, int64_t flags ) { int a; dbUserMainDef maind; a = dbUserNewsAdd( id, data, flags ); if( ( dbUserMainRetrieve( id, &maind ) >= 0 ) && ( maind.empire != -1 ) ) cmdEmpireNewsAdd( maind.empire, id, data ); return a; }
void cmdTickGenRanks() { int a, b, c, d, first, num, artmax; FILE *file, *filep; dbUserMainDef maind; dbMainEmpirePtr empirep; dbUserMainPtr mainp; dbUserPtr user; int *stats; int artefacts[ARTEFACT_NUMUSED], artsnum; artmax = 0; memset( artefacts, 0, ARTEFACT_NUMUSED*sizeof(int) ); if( !( file = fopen( DB_DIRECTORY "/famranks.txt", "wb" ) ) ) return; if( !( filep =fopen( DB_DIRECTORY "/famranksplain.txt", "wb" ) ) ) { fclose( file ); return; } if( !( stats = malloc( 6*dbMapBInfoStatic[4]*sizeof(int) + sizeof(dbMainEmpireDef)*dbMapBInfoStatic[4] ) ) ) { fclose( file ); return; } empirep = (void *)&stats[6*dbMapBInfoStatic[4]]; memset( stats, 0, 6*dbMapBInfoStatic[4]*sizeof(int) ); for( b = c = num = 0 ; b < dbMapBInfoStatic[4] ; b++ ) { if( dbMapRetrieveEmpire( b, &empirep[b] ) < 0 ) continue; if( !( empirep[b].numplayers ) ) continue; stats[c+0] = b; // calc NW, planets and empire artefacts for( a = 0 ; a < empirep[b].numplayers ; a++ ) { if( dbUserMainRetrieve( empirep[b].player[a], &maind ) < 0 ) continue; stats[c+1] += maind.planets; stats[c+2]++; stats[c+3] += (int)maind.networth; } empirep[b].planets = stats[c+1]; empirep[b].networth = stats[c+3]; dbMapSetEmpire( b, &empirep[b] ); num++; // set artefacts for empire members for( a = 0 ; a < empirep[b].numplayers ; a++ ) { if( dbUserMainRetrieve( empirep[b].player[a], &maind ) < 0 ) continue; maind.artefacts = empirep[b].artefacts; dbUserMainSet( empirep[b].player[a], &maind ); } c += 6; } // empire rankings first = 0; stats[4] = -1; stats[5] = -1; for( b = 1, c = 6 ; b < num ; b++, c += 6 ) { if( ( stats[c+1] > stats[first+1] ) || ( ( stats[c+1] == stats[first+1] ) && ( stats[c+3] > stats[first+3] ) ) ) { stats[first+4] = c; stats[c+5] = first; stats[c+4] = -1; first = c; continue; } a = stats[first+5]; d = first; for( ; ; ) { if( a == -1 ) { stats[d+5] = c; stats[c+4] = d; stats[c+5] = -1; break; } if( ( stats[c+1] > stats[a+1] ) || ( ( stats[c+1] == stats[a+1] ) && ( stats[c+3] > stats[a+3] ) ) ) { stats[c+4] = d; stats[c+5] = a; stats[d+5] = c; stats[a+4] = c; break; } d = a; a = stats[a+5]; } } if( !( num ) ) first = -1; fprintf( file, "<table cellspacing=\"4\"><tr><td align=\"right\">Rank</td><td>Name</td><td>Planets</td><td>Players</td><td>Networth</td></tr>" ); for( a = first, b = 1 ; a != -1 ; b++ ) { fprintf( file, "<tr><td align=\"right\" nowrap>" ); /* for( c = 0, d = 1 ; c < ARTEFACT_NUMUSED ; c++, d <<= 1 ) { if( empirep[stats[a+0]].artefacts & d ) fprintf( file, "<img src=\"%s\">", artefactImage[c] ); } */ artsnum = 0; for( c = 0, d = 1 ; c < ARTEFACT_NUMUSED ; c++, d <<= 1 ) { if( empirep[stats[a+0]].artefacts & d ) { artsnum++; artefacts[c] = 1; } } if( artsnum > artmax ) artmax = artsnum; if( ( 3*artsnum >= ARTEFACT_NUMUSED ) || ( (3*dbArtefactMax)/2 >= ARTEFACT_NUMUSED ) ) { for( c = 0, d = 1 ; c < ARTEFACT_NUMUSED ; c++, d <<= 1 ) { if( empirep[stats[a+0]].artefacts & d ) fprintf( file, "<img src=\"%s\">", artefactImage[c] ); } } fprintf( file, " %d</td><td><a href=\"empire?id=%d\">", b, stats[a+0] ); if( empirep[stats[a+0]].name[0] ) fprintf( file, "%s #%d", empirep[stats[a+0]].name, stats[a+0] ); else fprintf( file, "Empire #%d", stats[a+0] ); fprintf( file, "</a></td><td align=\"center\">%d</td><td align=\"center\">%d</td><td align=\"center\">%d</td></tr>\n", stats[a+1], stats[a+2], stats[a+3] ); /* Plain Text */ fprintf( filep, "%d:%d:%d:%d:%d:", b, stats[a+0], stats[a+1], stats[a+2], stats[a+3] ); if( empirep[stats[a+0]].name[0] ) fprintf( filep, "%s #%d", empirep[stats[a+0]].name, stats[a+0] ); else fprintf( filep, "Empire #%d", stats[a+0] ); fprintf( filep, "\n" ); // moo empirep[stats[a+0]].rank = b; dbMapSetEmpire( stats[a+0], &empirep[stats[a+0]] ); a = stats[a+5]; } fprintf( file, "</table>" ); fprintf( file, "<br>" ); artsnum = 0; for( c = 0 ; c < ARTEFACT_NUMUSED ; c++ ) artsnum |= artefacts[c]; if( artsnum ) { fprintf( file, "<br><br><b>Artefacts found</b><br>" ); fprintf( file, "<table><tr><td>" ); for( c = 0 ; c < ARTEFACT_NUMUSED ; c++ ) { if( artefacts[c] ) fprintf( file, "<img src=\"%s\"> %s<br>", artefactImage[c], artefactDescription[c] ); } fprintf( file, "</td></tr></table><br>" ); } dbArtefactMax = artmax; free( stats ); fclose( file ); fclose( filep ); // player rankings if( !( file = fopen( DB_DIRECTORY "/ranks.txt", "wb" ) ) ) return; if( !( filep = fopen( DB_DIRECTORY "/ranksplain.txt", "wb" ) ) ) { fclose( file ); return; } for( user = dbUserList, num = 0 ; user ; user = user->next ) num++; if( !( num ) || !( stats = malloc( 6*num*sizeof(int) + sizeof(dbUserMainDef)*num ) ) ) { fclose( file ); return; } mainp = (void *)&stats[6*num]; memset( stats, 0, 6*num*sizeof(int) ); for( b = c = 0, user = dbUserList ; user ; user = user->next ) { if( !( user->flags & CMD_USER_FLAGS_ACTIVATED ) ) { //printf("user %d not activated\n", user->id ); continue; } if( dbUserMainRetrieve( user->id, &mainp[b] ) < 0 ) { printf("error retreiving maind id: %d\n", user->id ); continue; } stats[c+0] = user->id; stats[c+1] = mainp[b].planets; stats[c+2] = mainp[b].networth; stats[c+3] = b; b++; c += 6; } num = b; first = 0; stats[4] = -1; stats[5] = -1; for( b = 1, c = 6 ; b < num ; b++, c += 6 ) { if( ( stats[c+1] > stats[first+1] ) || ( ( stats[c+1] == stats[first+1] ) && ( stats[c+2] > stats[first+2] ) ) ) { stats[first+4] = c; stats[c+5] = first; stats[c+4] = -1; first = c; continue; } a = stats[first+5]; d = first; for( ; ; ) { if( a == -1 ) { stats[d+5] = c; stats[c+4] = d; stats[c+5] = -1; break; } if( ( stats[c+1] > stats[a+1] ) || ( ( stats[c+1] == stats[a+1] ) && ( stats[c+2] > stats[a+2] ) ) ) { stats[c+4] = d; stats[c+5] = a; stats[d+5] = c; stats[a+4] = c; break; } d = a; a = stats[a+5]; } } if( !( num ) ) first = -1; fprintf( file, "<table cellspacing=\"4\"><tr><td>Rank</td><td>Faction</td><td>Empire</td><td>Planets</td><td>Networth</td></tr>" ); for( a = first, b = 1 ; a != -1 ; b++ ) { fprintf( file, "<tr><td align=\"right\">%d</td><td><a href=\"player?id=%d\">%s</a></td><td><a href=\"empire?id=%d\">empire #%d</a></td><td align=\"center\">%d</td><td align=\"center\">%lld</td></tr>", b, stats[a+0], mainp[stats[a+3]].faction, mainp[stats[a+3]].empire, mainp[stats[a+3]].empire, mainp[stats[a+3]].planets, mainp[stats[a+3]].networth ); fprintf( filep, "%d:%d:%d:%d:%lld:%s\n", b, stats[a+0], mainp[stats[a+3]].empire, mainp[stats[a+3]].planets, mainp[stats[a+3]].networth, mainp[stats[a+3]].faction ); // moo mainp[stats[a+3]].rank = b; dbUserMainSet( stats[a+0], &mainp[stats[a+3]] ); a = stats[a+5]; } fprintf( file, "</table>" ); free( stats ); fclose( file ); fclose( filep ); return; }
int cmdTick() { int a, c, d, e, num, specopnum, opvirus /*,cmd[3]*/, i; float fb, phdecay; double fa; long long int newd[DB_USER_NEWS_BASE], nIllusion, b; int nChicks = 0, penalty; int marketbid[DB_MARKETBID_NUMUSED]; int bidresult[2]; int *plist; int nArti = 0, nNum; dbUserPtr user; dbUserMainDef maind; dbUserBuildPtr build; dbMainPlanetDef planetd; dbUserFleetDef fleetd; dbUserFleetPtr fleetp; dbUserSpecOpPtr specopd; dbMainEmpireDef empired; svDebugTickPass = 0; svDebugTickId = 0; //Maybe useless but can t cause trouble only set the news buffer to 0 memset(&newd, 0, sizeof(long long int)*DB_USER_NEWS_BASE); for( a = 0 ; a < dbMapBInfoStatic[4] ; a++ ) { if( dbMapRetrieveEmpire( a, &empired ) < 0 ) continue; svDebugTickId = a; nArti |= empired.artefacts; //Will have all discovered arti in here empired.artefacts = 0; dbMapSetEmpire( a, &empired ); } svDebugTickPass = 1; //ARTI CODE Ticking Time Bomb /*if(!(svTickNum % 52)) //New year { //Nuke ARTI Planet fleetd.unit[CMD_UNIT_AGENT] = 1; fleetd.destid = 2134; printf("clear\n"); specopAgentsPerformOp(0,0,&fleetd,NULL); }*/ if( ( dbMapRetrieveMain( dbMapBInfoStatic ) < 0 ) ) printf( "Tick error #1\n" ); for( user = dbUserList ; user ; user = user->next ) { /* this is for all galaxy arti //ARTI CODE if(nArti & ARTEFACT_WILL_BIT) { //do things like open all fleet and remove 0.5% chicks in all fleetd nNum = dbUserFleetList(user->id, &fleetp); for(i=0;i<nNum;i++) { fleetp[i].unit[CMD_UNIT_WIZARD] *= 100; fleetp[i].unit[CMD_UNIT_WIZARD] /= 100.5; dbUserFleetSet(user->id, i, &fleetp[i]); } }*/ if( !( user->flags & CMD_USER_FLAGS_ACTIVATED ) ) continue; svDebugTickId = user->id; if( dbUserMainRetrieve( user->id, &maind ) < 0 ) { printf( "Tick error #2 : %d\n", user->id ); continue; } svDebugTickPass = 2; if( ( specopnum = dbUserSpecOpList( user->id, &specopd ) ) < 0 ) { printf( "Tick error #3 : %d\n", user->id ); continue; } opvirus = 0; //WAR ILLUSION we recalcul each tick for(i=0; i<specopnum; i++) { if (specopd[i].type == (CMD_SPELL_WARILLUSIONS | 0x1000)) { fa = 0.4 + (1.2/255.0) * (float)( rand() & 255 ); nChicks = maind.totalunit[CMD_UNIT_WIZARD]; nIllusion = ( fa * cmdRace[maind.raceid].unit[CMD_UNIT_WIZARD] * (float)nChicks * ( 1.0 + 0.005*maind.totalresearch[CMD_RESEARCH_WELFARE] ) / cmdPsychicopDifficulty[CMD_SPELL_WARILLUSIONS] ); penalty = cmdGetOpPenalty( maind.totalresearch[CMD_RESEARCH_WELFARE], cmdPsychicopTech[CMD_SPELL_WARILLUSIONS] ); if( penalty ) nIllusion = (float)nIllusion / ( 1.0 + 0.01*(float)penalty ); fa = 100.0 * (float)nIllusion / (float)maind.networth; a = (int)( fa * 4.5 ); a += a * rand()%20; if (a<0) a = 0; specopd[i].vars[0] = a; } } for( a = specopnum-1 ; a >= 0 ; a-- ) { if( specopd[a].type == ( CMD_OPER_NETWORKVIRUS | 0x10000 ) ) opvirus++; } svDebugTickPass = 3; num = dbUserBuildListReduceTime( user->id, &build ); newd[0] = svTickNum; newd[1] = CMD_NEWS_FLAGS_NEW; for( a = num-1 ; a >= 0 ; a-- ) { if( build[a].time > 0 ) continue; if( !( build[a].type >> 16 ) ) { dbMapRetrievePlanet( build[a].plnid, &planetd ); if( build[a].type == CMD_BLDG_NUMUSED ) { // portal planetd.flags &= 0xFFFFFFFF - CMD_PLANET_FLAGS_PORTAL_BUILD; planetd.flags |= CMD_PLANET_FLAGS_PORTAL; dbUserPlanetSetFlags( user->id, build[a].plnid, planetd.flags ); planetd.construction--; } else { planetd.building[ build[a].type ] += build[a].quantity; planetd.construction -= build[a].quantity; } dbMapSetPlanet( build[a].plnid, &planetd ); newd[2] = CMD_NEWS_BUILDING; newd[5] = build[a].plnid; newd[6] = build[a].plnpos; } else { if( !( dbUserFleetRetrieve( user->id, 0, &fleetd ) ) ) continue; fleetd.unit[ build[a].type & 0xFFFF ] += build[a].quantity; if( !( dbUserFleetSet( user->id, 0, &fleetd ) ) ) continue; newd[2] = CMD_NEWS_UNIT; } dbUserBuildRemove( user->id, a ); newd[3] = build[a].type; newd[4] = build[a].quantity; cmdUserNewsAdd( user->id, newd, CMD_NEWS_FLAGS_BUILD ); } free( build ); svDebugTickPass = 4; // calc total of buildings, units, artefacts cmdTickPlanets( user->id, &maind ); svDebugTickPass = 5; // add research for( a = 0 ; a < CMD_RESEARCH_NUMUSED ; a++ ) { fa = ( (double)(maind.allocresearch[a]) * (double)( 500*cmdTickProduction[CMD_BUILDING_RESEARCH] + maind.fundresearch ) ) / 10000.0; if( cmdRace[maind.raceid].special & CMD_RACE_SPECIAL_POPRESEARCH ) fa += ( (double)(maind.allocresearch[a]) * (double)maind.ressource[CMD_RESSOURCE_POPULATION] ) / ( 400.0 * 100.0 ); //ARTI CODE Foohon Ancestry if(maind.artefacts & ARTEFACT_4_BIT) fa += ( (double)(maind.allocresearch[a]) * (double)maind.ressource[CMD_RESSOURCE_POPULATION] ) / ( 400.0 * 100.0 ); maind.research[a] += cmdRace[maind.raceid].researchpoints[a] * fa; if( maind.research[a] < 0 ) maind.research[a] = 0x7FFFFFFF; } maind.fundresearch = (long long int)( 0.9 * (double)maind.fundresearch ); svDebugTickPass = 6; // SK: because of the network backbone arti, we need to calculate Tech research first int addedFromTech = 0; // calculate total research for tech //research maximum fa = cmdRace[maind.raceid].researchmax[CMD_RESEARCH_TECH]; printf("max TECH research percentage: %c \n", fa); // ARTI CODE Divine Stone if(maind.artefacts & ARTEFACT_32_BIT) fa -= 25; printf("modified TECH research percentage: %c \n", fa); b = fa * ( 1.0 - exp( (double)maind.research[CMD_RESEARCH_TECH] / ( -10.0 * (double)maind.networth ) ) ); printf("total tech research percentage: %d \n", b); if( b > maind.totalresearch[CMD_RESEARCH_TECH] ) maind.totalresearch[CMD_RESEARCH_TECH]++; else if( b < maind.totalresearch[CMD_RESEARCH_TECH] ) maind.totalresearch[CMD_RESEARCH_TECH]--; addedFromTech = b/10; printf("added from tech: %c \n", addedFromTech); // calculate total research for( a = 0 ; a < CMD_RESEARCH_NUMUSED ; a++ ) { if(a == CMD_RESEARCH_TECH) continue; //research maximum fa = cmdRace[maind.raceid].researchmax[a]; printf("reasearchtype: %c \n",a); printf("researchmax by race: %c \n", fa); //ARTI CODE Divine Stone if((maind.artefacts & ARTEFACT_32_BIT)&&(a == CMD_RESEARCH_WELFARE)) fa += 50; //// ARTI CODE book of revelation // if((maind.artefacts & ARTEFACT_32_BIT)&&(a == CMD_RESEARCH_TECH)) // fa -= 25; // put this arti last, you need the other ones calculated before this one. //ARTI CODE network backbone if(maind.artefacts & ARTEFACT_1_BIT) { // exclude tech research from having this bonus (otherwise there is no cap) if( a != CMD_RESEARCH_TECH) { fa += addedFromTech; printf("total with addition: %c \n", fa); } } //ARTI CODE Cystal summoner //if((maind.artefacts & ARTEFACT_32_BIT)&&(a == CMD_RESEARCH_WELFARE)) // fa += 70; //ARTI CODE Elit strategist //if((maind.artefacts & ARTEFACT_128_BIT)&&(a == CMD_RESEARCH_MILITARY)) // fa += 20; //ARTI CODE Elit strategist //if((maind.artefacts & ARTEFACT_ELIT_BIT)&&(a == CMD_RESEARCH_TECH)) // fa -= 20; b = fa * ( 1.0 - exp( (double)maind.research[a] / ( -10.0 * (double)maind.networth ) ) ); printf("total research percentage: %d \n", b); if( b > maind.totalresearch[a] ) maind.totalresearch[a]++; else if( b < maind.totalresearch[a] ) maind.totalresearch[a]--; } svDebugTickPass = 7; // calc infos fa = ( 12.0 * (double)(cmdTickProduction[CMD_BUILDING_SOLAR]) / specopSolarCalc( user->id ) ); if( cmdRace[maind.raceid].special & CMD_RACE_SPECIAL_SOLARP15 ) fa *= 1.15; fb = ( 40.0 * (double)(cmdTickProduction[CMD_BUILDING_FISSION]) ); fa += fb; //ARTI CODE Ticking Time Bomb //if(maind.artefacts & ARTEFACT_2_BIT) // fa *= 1.10; //ARTI CODE Ether Garden if(maind.artefacts & ARTEFACT_ETHER_BIT) fa *= 1.10; //ARTI CODE Ether Garden + Delayed Artefact //if((maind.artefacts & ARTEFACT_ETHER_BIT)&&(maind.articount >= 144)) // fa *= 1.10; //ARTI CODE Romulan Military outpost if(maind.artefacts & ARTEFACT_8_BIT) fa *= 0.88; fb = cmdRace[maind.raceid].resource[CMD_RESSOURCE_ENERGY] * ( 1.00 + 0.01 * (float)maind.totalresearch[CMD_RESEARCH_ENERGY] ); //ARTI CODE Vulcan Fission Theory if(maind.artefacts & ARTEFACT_128_BIT) fb *= 1.2; if((maind.artefacts & ARTEFACT_128_BIT)&&(maind.articount >= 144)) fb *= 1.2; maind.infos[4] = (long long int)( fa * fb ); /* This block is for the automated funding from energy production if used add the funding into the council with maind.infos dbUserMainSet(user->id, &maind); cmd[0] = CMD_FUND_RESEARCH; cmd[1] = user->id; cmd[2] = maind.infos[4]*0.08; cmdExecute( (svConnectionPtr)NULL, cmd, 0, 0 ); dbUserMainRetrieve( cmd[1], &maind ); //maind.infos[4] -= maind.infos[4]*0.08; //This line remove the actual funding from the production */ fa = CMD_ENERGY_DECAY; //ARTI CODE Grand Silo if(maind.artefacts & ARTEFACT_64_BIT) fa /= 2; //ARTI CODE Granary + delayed //if((maind.artefacts & ARTEFACT_64_BIT)&&(maind.articount >= 144)) //fa /= 2; maind.infos[5] = fa * (double)maind.ressource[CMD_RESSOURCE_ENERGY]; // meh! building upkeep maind.infos[6] = 0; for( a = 0 ; a < CMD_BLDG_NUMUSED ; a++ ) { if( ( a == CMD_BUILDING_SOLAR ) || ( a == CMD_BUILDING_FISSION ) ) { //ARTI CODE Vulcan Fission Theory if((maind.artefacts & ARTEFACT_128_BIT)&&(maind.articount >= 144)&&( a == CMD_BUILDING_FISSION )) maind.infos[6] += ((float)cmdTickProduction[a])*cmdBuildingUpkeep[a] * fb *0.7; else if((maind.artefacts & ARTEFACT_128_BIT)&&( a == CMD_BUILDING_FISSION )) maind.infos[6] += ((float)cmdTickProduction[a])*cmdBuildingUpkeep[a] * fb * 0.85; else maind.infos[6] += ((float)cmdTickProduction[a])*cmdBuildingUpkeep[a] * fb; } else maind.infos[6] += ((float)cmdTickProduction[a])*cmdBuildingUpkeep[a]; } svDebugTickPass = 8; for( a = 0 ; a < CMD_UNIT_NUMUSED ; a++ ) { if( maind.totalunit[a] < 0 ) maind.totalunit[a] = 0; } maind.infos[7] = 0; for( a = 0 ; a < CMD_UNIT_NUMUSED ; a++ ) { maind.infos[7] += ((float)maind.totalunit[a])*cmdUnitUpkeep[a]; } //ARTI CODE Romulan Military Outpost //if(maind.artefacts & ARTEFACT_8_BIT) maind.infos[7] *= 0.5; maind.infos[8] = (1.0/35.0) * (float)maind.ressource[CMD_RESSOURCE_POPULATION]* ( 1.00 + 0.01 * (float)maind.totalresearch[CMD_RESEARCH_WELFARE] ) * (cmdRace[maind.raceid].growth); //ARTI CODE Lunar Tesseract //if(maind.artefacts & ARTEFACT_LUN_BIT) // maind.infos[8] += 0.3 * ((1.0/35.0) * (float)maind.ressource[CMD_RESSOURCE_POPULATION]* ( 1.00 + 0.01 * (float)maind.totalresearch[CMD_RESEARCH_WELFARE] ) * (cmdRace[maind.raceid].growth)); if( maind.infos[8] >= maind.infos[6] ) maind.infos[8] = maind.infos[6]; //virus network mean more upkeep Based on the upkeep of a building with after pop reduction for( a = 0 ; a < opvirus ; a++ ) maind.infos[6] += (long long int)( (float)(maind.infos[6]-maind.infos[8]) * 0.15 ); maind.infos[9] = cmdRace[maind.raceid].resource[CMD_RESSOURCE_CRYSTAL] * (float)(cmdTickProduction[CMD_BUILDING_CRYSTAL]); fa = CMD_CRYSTAL_DECAY; //ARTI CODE Granary if(maind.artefacts & ARTEFACT_64_BIT) fa /= 2; maind.infos[10] = fa * (double)maind.ressource[CMD_RESSOURCE_CRYSTAL]; maind.infos[11] = pow( (maind.totalbuilding[CMD_BLDG_NUMUSED]-1), 1.2736 ) * 10000.0; //ARTI CODE Mana Gate //if(maind.artefacts & ARTEFACT_MANA_BIT) // maind.infos[11] /= 2; if( maind.infos[11] < 0 ) maind.infos[11] = 0; maind.infos[CMD_RESSOURCE_ENERGY] = maind.infos[4] - maind.infos[5] - maind.infos[6] - maind.infos[7] + maind.infos[8] - maind.infos[11]; maind.infos[CMD_RESSOURCE_MINERAL] = cmdRace[maind.raceid].resource[CMD_RESSOURCE_MINERAL] * (float)(cmdTickProduction[CMD_BUILDING_MINING]); //ARTI CODE Ticking Time Bomb //if(maind.artefacts & ARTEFACT_2_BIT) // maind.infos[CMD_RESSOURCE_MINERAL] *= 1.10; //ARTI CODE Ticking Time Bomb //if(maind.artefacts & ARTEFACT_2_BIT) // maind.infos[9] *= 1.10; maind.infos[CMD_RESSOURCE_CRYSTAL] = (maind.infos[9] - maind.infos[10]); maind.infos[CMD_RESSOURCE_ECTROLIUM] = cmdRace[maind.raceid].resource[CMD_RESSOURCE_ECTROLIUM] * (float)(cmdTickProduction[CMD_BUILDING_REFINEMENT]); //ARTI CODE Ticking Time Bomb //if(maind.artefacts & ARTEFACT_2_BIT) // maind.infos[CMD_RESSOURCE_ECTROLIUM] *= 1.10; //ARTI CODE Mineral mine if(maind.artefacts & ARTEFACT_16_BIT) { maind.infos[CMD_RESSOURCE_MINERAL] *= 1.20; maind.infos[CMD_RESSOURCE_ECTROLIUM] *= 0.90; } svDebugTickPass = 9; // fleets decay? a = 65536*2; b = -1; if( ( maind.ressource[CMD_RESSOURCE_ENERGY] + maind.infos[CMD_RESSOURCE_ENERGY] ) < 0 ) { a = -65536*3; b = CMD_UNIT_GHOST; } // readiness for( c = 0 ; c < 3 ; c++ ) { if( a < 0 ) { if( maind.readiness[c] > ( -65536*200 - a ) ) maind.readiness[c] += a; else if( maind.readiness[c] > -65536*200 ) maind.readiness[c] = -65536*200; } else maind.readiness[c] += a; if( maind.readiness[c] > 65536*100 ) maind.readiness[c] = 65536*100; /* if( maind.readiness[c] < -65536*500 ) maind.readiness[c] = -65536*500; */ } svDebugTickPass = 10; // calculate phantoms decay rate phdecay = 0.20; if( maind.totalunit[CMD_UNIT_WIZARD] ) { fa = (double)maind.totalunit[CMD_UNIT_PHANTOM] / (double)maind.totalunit[CMD_UNIT_WIZARD]; if( fa < 0.05 ) phdecay = 0.01; else { fa = (double)pow( (double)( (1.0/0.05) * fa ), 2.4 ); phdecay = 0.01*fa; if( phdecay > 0.20 ) phdecay = 0.20; } } // fleets dbUserMainSet( user->id, &maind ); fleetp = 0; num = dbUserFleetList( user->id, &fleetp ); for( a = num-1 ; a >= 0 ; a-- ) { e = 0; if( a == 0 ) { if( !( dbUserFleetRetrieve( user->id, 0, &fleetp[0] ) ) ) return 1; } for( c = b ; c >= 0 ; c-- ) { d = (int)ceil( (float)fleetp[a].unit[c] * 0.02 ); fleetp[a].unit[c] -= d; maind.totalunit[c] -= d; e |= d; } if( fleetp[a].unit[CMD_UNIT_PHANTOM] ) { d = (int)ceil( (float)fleetp[a].unit[CMD_UNIT_PHANTOM] * phdecay ); fleetp[a].unit[CMD_UNIT_PHANTOM] -= d; maind.totalunit[CMD_UNIT_PHANTOM] -= d; e |= d; } if( ( a ) && !( fleetp[a].unit[CMD_UNIT_EXPLORATION] ) && !( fleetp[a].unit[CMD_UNIT_CRUISER] ) && !( fleetp[a].unit[CMD_UNIT_CARRIER] ) && !( fleetp[a].unit[CMD_UNIT_PHANTOM] ) && !( fleetp[a].unit[CMD_UNIT_AGENT] ) && !( fleetp[a].unit[CMD_UNIT_GHOST] ) ) { dbUserFleetRemove( user->id, a ); continue; } fleetd.flags &= 0xFFFFFFFF - CMD_FLEET_FLAGS_MOVED; if( fleetp[a].time > 0 ) { fleetd.flags |= CMD_FLEET_FLAGS_MOVED; fleetp[a].time--; dbUserFleetSet( user->id, a, &fleetp[a] ); } else if( e ) dbUserFleetSet( user->id, a, &fleetp[a] ); if( ( a != 0 ) && ( fleetp[a].time == 0 ) ) cmdFleetAction( &fleetp[a], user->id, a, 1 ); } if( fleetp ) free( fleetp ); dbUserMainRetrieve( user->id, &maind ); svDebugTickPass = 11; // units decay on planets plist = 0; num = dbUserPlanetListIndices( user->id, &plist ); for( a = 0 ; a < num ; a++ ) { dbMapRetrievePlanet( plist[a], &planetd ); e = 0; if( planetd.unit[CMD_UNIT_PHANTOM] ) { planetd.unit[CMD_UNIT_PHANTOM] -= (int)ceil( phdecay * (float)(planetd.unit[CMD_UNIT_PHANTOM]) ); e |= 1; } for( c = b ; c >= 0 ; c-- ) { d = (int)ceil( (float)planetd.unit[c] * 0.02 ); planetd.unit[c] -= d; maind.totalunit[c] -= d; e |= d; } if( e ) dbMapSetPlanet( plist[a], &planetd ); } if( plist ) free( plist ); svDebugTickPass = 12; // income for( a = 0 ; a < CMD_RESSOURCE_NUMUSED ; a++ ) { maind.ressource[a] += maind.infos[a]; if( maind.ressource[a] < 0 ) maind.ressource[a] = 0; } // networth a = dbUserPlanetNumber( user->id ); maind.networth = ( 800 * a ); for( a = 0 ; a < CMD_UNIT_NUMUSED ; a++ ) maind.networth += maind.totalunit[a] * cmdUnitStats[a][CMD_UNIT_STATS_NETWORTH]; for( a = 0 ; a < CMD_BLDG_NUMUSED ; a++ ) { maind.networth += 8 * maind.totalbuilding[a]; } maind.networth += (long long int)(0.004 * maind.ressource[CMD_RESSOURCE_POPULATION]); for( a = 0 ; a < CMD_RESEARCH_NUMUSED ; a++ ) maind.networth += (0.001 * maind.research[a]); // spec ops for( a = specopnum-1 ; a >= 0 ; a-- ) { specopd[a].time--; if( specopd[a].time <= 0 ) { //remove planet beacon flag on the planet if(specopd[a].type == CMD_OPER_PLANETBEACON) { dbMapRetrievePlanet(specopd[a].plnid, &planetd); planetd.flags ^= CMD_PLANET_FLAGS_BEACON; dbMapSetPlanet(specopd[a].plnid, &planetd); } dbUserSpecOpRemove( user->id, a ); continue; } dbUserSpecOpSet( user->id, a, &specopd[a] ); } if( specopd ) free( specopd ); svDebugTickPass = 13; dbUserMainSet( user->id, &maind ); }
//Ok, so here goes nothing... void iohtmlFunc_ajax( ReplyDataPtr cnt ) { #if IRCBOT_SUPPORT ConfigArrayPtr settings[2]; #endif int a, c, id, numbuild; int64_t b; int64_t bsums[CMD_BLDG_NUMUSED+1]; int64_t usums[CMD_UNIT_NUMUSED]; const char *typestring, *idstring, *refer; char CHECKER[256]; char timebuf[512]; dbMainEmpireDef empired; dbBuildPtr build; dbUserMainDef maind; proginfoDef pinfod; urlinfoPtr urlp; cpuInfo cpuinfo; time_t tint; struct sysinfo sysinfod; refer = idstring = typestring = NULL; cpuGetInfo( &cpuinfo ); getsys_infos( &pinfod ); if( sysinfo(&sysinfod) != 0 ) { critical( "Failure getting system infomation... Critical failure." ); sysconfig.shutdown = true; return; } idstring = iohtmlVarsFind( cnt, "id" ); typestring = iohtmlVarsFind( cnt, "typ" ); refer = iohtmlHeaderFind(cnt, "Referer"); if( ( id = iohtmlIdentify( cnt, 2 ) ) >= 0 ) { if( dbUserMainRetrieve( id, &maind ) < 0 ) goto BAILAJAX; else if( dbEmpireGetInfo( maind.empire, &empired ) < 0 ) goto BAILAJAX; } if( ( typestring ) && ( refer ) ) { urlp = parse_url(refer); refer = urlp->path; httpString( cnt, "<?xml version=\"1.0\"?>" ); httpPrintf( cnt, "<xml>" ); //Begin XML generation, we only make one request now... so we have to structure carefully! if( !strcmp(typestring,"ticker") ) { //Send basic tick info, and check if user is loged in. httpPrintf( cnt, "<pass>%d</pass>", ( id != -1 ) ? ( ( bitflag( ((cnt->session)->dbuser)->flags, CMD_USER_FLAGS_ACTIVATED ) ) ? true : false ) : false ); if( refer ) httpPrintf( cnt, "<page>%s</page>", refer ); httpPrintf( cnt, "<u_online>%d</u_online><u_activated>%d</u_activated>", dbRegisteredInfo[DB_TOTALS_USERS_ONLINE], dbRegisteredInfo[DB_TOTALS_USERS_ACTIVATED] ); httpPrintf( cnt, "<time><next>%d</next><week>%d</week><year>%d</year></time>", (int)fmax( 0.0, ( ticks.next - time(0) ) ), ticks.number % 52, ticks.number / 52 ); if( !strcmp(refer,"status") ) { snprintf( CHECKER, sizeof(CHECKER), "%lu bytes ( %5.1f mb )", pinfod.stvsize, pinfod.stvsize / megabyte ); httpString( cnt, "<general>" ); httpPrintf( cnt, "<servpriority>%ld</servpriority>", pinfod.stpriority ); httpPrintf( cnt, "<servthreads>%ld</servthreads>", pinfod.threads ); httpString( cnt, "</general>" ); httpString( cnt, "<memory>" ); httpPrintf( cnt, "<memused>%s</memused>", CHECKER ); httpPrintf( cnt, "<memavbytes>%ld bytes</memavbytes>", sysinfod.freeram ); httpPrintf( cnt, "<memavmeg>( %4.1f mb )</memavmeg>", (sysinfod.freeram / megabyte ) ); httpPrintf( cnt, "<totalswapbytes>%ld bytes</totalswapbytes>", sysinfod.totalswap ); httpPrintf( cnt, "<totalswapmeg>( %5.1f mb )</totalswapmeg>", (sysinfod.totalswap / megabyte ) ); httpPrintf( cnt, "<freeswapbytes>%ld bytes</freeswapbytes>", sysinfod.freeswap ); httpPrintf( cnt, "<freeswapmeg>( %5.1f mb )</freeswapmeg>", (sysinfod.freeswap / megabyte ) ); httpPrintf( cnt, "<bufferbytes>%ld bytes</bufferbytes>", sysinfod.bufferram ); httpPrintf( cnt, "<bufermeg>( %5.1f mb )</bufermeg>", (sysinfod.bufferram / megabyte ) ); httpPrintf( cnt, "<sharedbytes>%ld bytes</sharedbytes>", sysinfod.sharedram ); httpPrintf( cnt, "<sharedmeg>( %5.1f mb )</sharedmeg>", (sysinfod.sharedram / megabyte ) ); time( &tint ); strftime(timebuf,512,"%a, %d %b %G %T %Z", localtime( &tint ) ); httpPrintf( cnt, "<timeserver>%s</timeserver>", timebuf ); strftime(timebuf,512,"%a, %d %b %G %T %Z", gmtime( &tint ) ); httpPrintf( cnt, "<timegmt>%s</timegmt>", timebuf ); httpPrintf( cnt, "<strss>%lu pages</strss>", pinfod.strss ); httpPrintf( cnt, "</memory>" ); httpString( cnt, "<cpu>" ); httpPrintf( cnt, "<cpuprocs>%d</cpuprocs>", sysinfod.procs ); httpPrintf( cnt, "<cpuloads>%f (1 min) - %f (5 mins) - %f (15 mins)</cpuloads>",pinfod.loadavg[0],pinfod.loadavg[1],pinfod.loadavg[2]); httpPrintf( cnt, "<cputotal>%.3f %%</cputotal>", pinfod.userload + pinfod.kernelload ); httpPrintf( cnt, "<cpukernel>%.3f %%</cpukernel>", pinfod.kernelload ); httpPrintf( cnt, "<cpuuser>%.3f %%</cpuuser>", pinfod.userload ); httpString( cnt, "</cpu>" ); #if IRCBOT_SUPPORT if( sysconfig.irc_enabled ) { if( irc_is_connected(sysconfig.irc_session) ) { settings[0] = GetSetting( "IRC Host" ); settings[1] = GetSetting( "IRC Channel" ); snprintf( CHECKER, sizeof(CHECKER), "Enabled (Host:%s, Channel:%s)", settings[0]->string_value, settings[1]->string_value ); } else { snprintf( CHECKER, sizeof(CHECKER), "%s", "Enabled but not connected" ); } } else { snprintf( CHECKER, sizeof(CHECKER), "%s", "Disabled"); } httpPrintf( cnt, "<botstatus>%s</botstatus>", CHECKER ); #endif //End Status block -- Start user block } if( id < 0 ) goto ENDXML; a = dbUserNewsGetFlags( id ); //OK, so they are loged in... time to send some info. Lets start with the header. =) httpString( cnt, "<header>" ); httpPrintf( cnt, "<networth>%lld</networth>", (long long)maind.networth ); httpString( cnt, "<notification>" ); httpPrintf( cnt, "<mail>%d</mail>", ( a & CMD_NEWS_FLAGS_MAIL ) ? true : false ); httpPrintf( cnt, "<build>%d</build>", ( a & CMD_NEWS_FLAGS_BUILD ) ? true : false ); httpPrintf( cnt, "<aid>%d</aid>", ( a & CMD_NEWS_FLAGS_AID ) ? true : false ); httpPrintf( cnt, "<fleet>%d</fleet>", ( a & CMD_NEWS_FLAGS_ATTACK ) ? 1 : ( ( a & CMD_NEWS_FLAGS_FLEET ) ? 2 : false ) ); httpString( cnt, "</notification>" ); httpString( cnt, "<ressources>" ); for( a = 0 ; a < CMD_RESSOURCE_NUMUSED ; a++ ) { snprintf( CHECKER, sizeof(CHECKER),"%s",cmdRessourceName[a]); for(b = 0; CHECKER[b]; b++){ CHECKER[b] = tolower(CHECKER[b]); } httpPrintf( cnt, "<%s>%lld</%s>", CHECKER, (long long)maind.ressource[a], CHECKER ); } httpPrintf( cnt, "<population>%lld</population>", (long long)maind.ressource[CMD_RESSOURCE_POPULATION] ); httpString( cnt, "</ressources>" ); httpString( cnt, "</header>" ); httpPrintf( cnt, "<%s>", refer ); //End Header block -- Start HQ block if( !strcmp(refer,"hq") ) { httpString( cnt, "<readiness>" ); for( a = 0 ; a < CMD_READY_NUMUSED ; a++ ) { httpPrintf( cnt, "<%sready>%d</%sready>", cmdReadyName[a], maind.readiness[a] >> 16, cmdReadyName[a] ); } httpString( cnt, "</readiness>" ); httpPrintf( cnt, "<planets>%d</planets>", maind.planets ); //End HQ block -- Start Council block } else if( !strcmp(refer,"council") ) {