int cmdTotalsCalculate( int usrid, dbUserMainPtr mainp ) { int a, b, num, population; int *buffer; dbMainPlanetDef planetd; dbMainEmpireDef empired; dbUserFleetPtr fleetd; memset( mainp->totalbuilding, 0, CMD_BLDG_NUMUSED*sizeof(int64_t) ); memset( mainp->totalunit, 0, CMD_UNIT_NUMUSED*sizeof(int64_t) ); if( ( num = dbUserPlanetListIndices( usrid, &buffer ) ) < 0 ) return 0; population = 0; for( a = 0 ; a < num ; a++ ) { dbMapRetrievePlanet( buffer[a], &planetd ); population += planetd.population; for( b = 0 ; b < CMD_BLDG_NUMUSED ; b++ ) mainp->totalbuilding[b] += planetd.building[b]; for( b = 0 ; b < CMD_UNIT_NUMUSED ; b++ ) mainp->totalunit[b] += planetd.unit[b]; if( ( planetd.flags & CMD_PLANET_FLAGS_PORTAL ) ) mainp->totalbuilding[CMD_BLDG_NUMUSED]++; if( ( b = artefactPrecense( &planetd ) ) < 0 ) continue; if( dbEmpireGetInfo( mainp->empire, &empired ) < 0 ) continue; empired.artefacts |= 1 << b; dbEmpireSetInfo( mainp->empire, &empired ); } mainp->planets = num; mainp->ressource[CMD_RESSOURCE_POPULATION] = (int64_t)population; free( buffer ); if( ( num = dbUserFleetList( usrid, &fleetd ) ) < 0 ) return 0; for( a = 0 ; a < num ; a++ ) { for( b = 0 ; b < CMD_UNIT_NUMUSED ; b++ ) mainp->totalunit[b] += fleetd[a].unit[b]; } free( fleetd ); return 1; }
int cmdTickPlanets( int usrid, dbUserMainPtr mainp ) { int a, b, num, nump, population, nInfection; int *buffer; int *portals; dbMainPlanetDef planetd; dbMainEmpireDef empired; dbUserFleetPtr fleetd; dbUserSpecOpPtr specopd; svDebugTickPass = 0 + 10000; memset( mainp->totalbuilding, 0, 16*sizeof(long long int) ); memset( mainp->totalunit, 0, 16*sizeof(long long int) ); memset( cmdTickProduction, 0, CMD_BLDG_NUMUSED*sizeof(int) ); nInfection = 0; if( ( b = dbUserSpecOpList( usrid, &specopd ) ) >= 0 ) { for(a = 0; a < b; a++) { if (specopd[a].type == (CMD_OPER_BIOINFECTION|0x10000)) { nInfection++; } } } if( ( num = dbUserPlanetListIndices( usrid, &buffer ) ) < 0 ) return 0; portals = 0; nump = 0; if( ( nump = dbUserPortalsListCoords( usrid, &portals ) ) < 0 ) { free( buffer ); return 0; } svDebugTickPass = 1 + 10000; population = 0; for( a = 0 ; a < num ; a++ ) { dbMapRetrievePlanet( buffer[a], &planetd ); planetd.maxpopulation = (float)( ( planetd.size * CMD_POPULATION_SIZE_FACTOR ) + ( planetd.building[CMD_BUILDING_CITIES] * CMD_POPULATION_CITIES ) ); //ARTI CODE Super Stacker if(mainp->artefacts & ARTEFACT_2_BIT) planetd.maxpopulation = (float)( ( planetd.size * CMD_POPULATION_SIZE_FACTOR ) + ( planetd.building[CMD_BUILDING_CITIES] * (CMD_POPULATION_CITIES+1000) ) ); svDebugTickPass = 2 + 10000; //No more pop grow bonus it will count as upkeep reducer multiplier //Planet grow pop is 2% each tick planetd.population += ceil(planetd.maxpopulation * 0.02 * pow(0.75, (float)nInfection)); //ARTI CODE Cloning Facilities //if(mainp->artefacts & ARTEFACT_CLON_BIT) // planetd.population += ceil((planetd.maxpopulation * 0.02 * pow(0.75, (float)nInfection)) * 0.5); if( planetd.population > planetd.maxpopulation ) planetd.population = planetd.maxpopulation; if( ( planetd.flags & CMD_PLANET_FLAGS_PORTAL ) ) planetd.protection = 100; else { planetd.protection = (int)( 100.0 * battlePortalCalc( ( planetd.position >> 8 ) & 0xFFF, planetd.position >> 20, portals, nump, mainp->totalresearch[CMD_RESEARCH_PORTALS] ) ); } if( planetd.construction < 0 ) { printf( "Warning : negative construction count : %d\n", planetd.construction ); planetd.construction = 0; } svDebugTickPass = 3 + 10000; /* CRAP */ for( b = 0 ; b < CMD_BLDG_NUMUSED ; b++ ) { if( planetd.building[b] < 0 ) planetd.building[b] = 0; } dbMapSetPlanet( buffer[a], &planetd ); svDebugTickPass = 4 + 10000; population += planetd.population; for( b = 0 ; b < CMD_BLDG_NUMUSED ; b++ ) { mainp->totalbuilding[b] += planetd.building[b]; cmdTickProduction[b] += planetd.building[b]; } for( b = 0 ; b < CMD_UNIT_NUMUSED ; b++ ) mainp->totalunit[b] += planetd.unit[b]; if( ( planetd.flags & CMD_PLANET_FLAGS_PORTAL ) ) mainp->totalbuilding[CMD_BLDG_NUMUSED]++; svDebugTickPass = 5 + 10000; if( planetd.special[1] ) { if( planetd.special[0] == 0 ) cmdTickProduction[CMD_BUILDING_SOLAR] += ( planetd.special[1] * planetd.building[CMD_BUILDING_SOLAR] ) / 100; else if( planetd.special[0] == 1 ) cmdTickProduction[CMD_BUILDING_MINING] += ( planetd.special[1] * planetd.building[CMD_BUILDING_MINING] ) / 100; else if( planetd.special[0] == 2 ) cmdTickProduction[CMD_BUILDING_CRYSTAL] += ( planetd.special[1] * planetd.building[CMD_BUILDING_CRYSTAL] ) / 100; else if( planetd.special[0] == 3 ) cmdTickProduction[CMD_BUILDING_REFINEMENT] += ( planetd.special[1] * planetd.building[CMD_BUILDING_REFINEMENT] ) / 100; } svDebugTickPass = 6 + 10000; if( ( b = (int)artefactPrecense( &planetd ) ) < 0 ) continue; if( dbMapRetrieveEmpire( mainp->empire, &empired ) < 0 ) continue; empired.artefacts |= 1 << b; dbMapSetEmpire( mainp->empire, &empired ); svDebugTickPass = 7 + 10000; } mainp->planets = num; mainp->ressource[CMD_RESSOURCE_POPULATION] = (long long int)population; svDebugTickPass = 8 + 10000; free( buffer ); svDebugTickPass = 9 + 10000; if( portals ) free( portals ); svDebugTickPass = 10 + 10000; if( ( num = dbUserFleetList( usrid, &fleetd ) ) < 0 ) return 0; svDebugTickPass = 11 + 10000; for( a = 0 ; a < num ; a++ ) { for( b = 0 ; b < 16 ; b++ ) mainp->totalunit[b] += fleetd[a].unit[b]; } svDebugTickPass = 12 + 10000; free( fleetd ); svDebugTickPass = 13 + 10000; return 1; }