/** * @brief Dumps ship data to csv. */ void dship_csv( const char *path ) { Ship *s, *s_all; int i, n, l; SDL_RWops *rw; char buf[ 1024 ]; /* File to output to. */ rw = SDL_RWFromFile( path, "w" ); if (rw == NULL) { WARN("Unable to open '%s' for writing: %s", path, SDL_GetError()); return; } /* Write "header" */ l = nsnprintf( buf, sizeof(buf), "name,class,base_type,price,license,fabricator," "thrust,turn,speed," "crew,mass,cpu,fuel,cargo," "absorb," "armour,armour_regen," "shield,shield_regen," "energy,energy_regen," "slot weapon,slot utility,slot structure\n" ); SDL_RWwrite( rw, buf, l, 1 ); s_all = ship_getAll( &n ); for (i=0; i<n; i++) { s = &s_all[i]; l = nsnprintf( buf, sizeof(buf), "%s,%s,%s,%"CREDITS_PRI",%s,%s," "%f,%f,%f," "%d,%f,%f,%d,%f," "%f," "%f,%f," "%f,%f," "%f,%f," "%d,%d,%d\n", s->name, ship_class(s), s->base_type, s->price, s->license, s->fabricator, s->thrust, s->turn*180./M_PI, s->speed, s->crew, s->mass, s->cpu, s->fuel, s->cap_cargo, s->dmg_absorb*100, s->armour, s->armour_regen, s->shield, s->shield_regen, s->energy, s->energy_regen, s->outfit_nweapon, s->outfit_nutility, s->outfit_nstructure ); SDL_RWwrite( rw, buf, l, 1 ); } /* Close file. */ SDL_RWclose( rw ); }
/** * @brief Updates the ship stuff. */ static void ship_update( unsigned int wid ) { char buf[1024], *hyp_delay; int cargo, len; cargo = pilot_cargoUsed( player.p ) + pilot_cargoFree( player.p ); hyp_delay = ntime_pretty( pilot_hyperspaceDelay( player.p ), 2 ); len = nsnprintf( buf, sizeof(buf), _("%s\n" "%s\n" "%s\n" "%d\n" "\n" "%d teraflops\n" "%.0f tonnes\n" "%s average\n" "%.0f kN/tonne\n" "%.0f m/s (max %.0f m/s)\n" "%.0f deg/s\n" "\n" "%.0f%%\n" /* Absorbption */ "%.0f / %.0f MJ (%.1f MW)\n" /* Shield */ "%.0f / %.0f MJ (%.1f MW)\n" /* Armour */ "%.0f / %.0f MJ (%.1f MW)\n" /* Energy */ "%d / %d tonnes\n" "%.0f / %.0f units (%d jumps)\n" "\n"), /* Generic */ player.p->name, player.p->ship->name, ship_class(player.p->ship), (int)floor(player.p->crew), player.p->cpu_max, /* Movement. */ player.p->solid->mass, hyp_delay, player.p->thrust / player.p->solid->mass, player.p->speed, solid_maxspeed( player.p->solid, player.p->speed, player.p->thrust ), player.p->turn*180./M_PI, /* Health. */ player.p->dmg_absorb * 100., player.p->shield, player.p->shield_max, player.p->shield_regen, player.p->armour, player.p->armour_max, player.p->armour_regen, player.p->energy, player.p->energy_max, player.p->energy_regen, pilot_cargoUsed( player.p ), cargo, player.p->fuel, player.p->fuel_max, pilot_getJumps(player.p)); equipment_shipStats( &buf[len], sizeof(buf)-len, player.p, 1 ); window_modifyText( wid, "txtDDesc", buf ); free( hyp_delay ); }
/** * @brief Updates the ship stuff. */ static void ship_update( unsigned int wid ) { char buf[1024]; int cargo; cargo = pilot_cargoUsed( player.p ) + pilot_cargoFree( player.p ); snprintf( buf, sizeof(buf), "%s\n" "%s\n" "%s\n" "%d\n" "\n" "%.0f teraflops\n" "%.0f tonnes\n" "%s average\n" "%.0f kN/tonne\n" "%.0f m/s (max %.0f m/s)\n" "%.0f deg/s\n" "\n" "%.0f / %.0f MJ (%.1f MW)\n" /* Shield */ "%.0f / %.0f MJ (%.1f MW)\n" /* Armour */ "%.0f / %.0f MJ (%.1f MW)\n" /* Energy */ "%d / %d tonnes\n" "%.0f / %.0f units (%d jumps)", /* Generic */ player.p->name, player.p->ship->name, ship_class(player.p->ship), (int)floor(player.p->crew), player.p->cpu_max, /* Movement. */ player.p->solid->mass, ntime_pretty( pilot_hyperspaceDelay( player.p ), 2 ), player.p->thrust / player.p->solid->mass, player.p->speed, solid_maxspeed( player.p->solid, player.p->speed, player.p->thrust ), player.p->turn*180./M_PI, /* Health. */ player.p->shield, player.p->shield_max, player.p->shield_regen, player.p->armour, player.p->armour_max, player.p->armour_regen, player.p->energy, player.p->energy_max, player.p->energy_regen, pilot_cargoUsed( player.p ), cargo, player.p->fuel, player.p->fuel_max, pilot_getJumps(player.p)); window_modifyText( wid, "txtDDesc", buf ); }
/** * @brief Updates the ships in the shipyard window. * @param wid Window to update the ships in. * @param str Unused. */ void shipyard_update( unsigned int wid, char* str ) { (void)str; char *shipname, *license_text; Ship* ship; char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN]; size_t len; shipname = toolkit_getImageArray( wid, "iarShipyard" ); /* No ships */ if (strcmp(shipname,"None")==0) { window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_disableButton( wid, "btnBuyShip"); window_disableButton( wid, "btnTradeShip"); nsnprintf( buf, PATH_MAX, "None\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" ); window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_modifyText( wid, "txtStats", NULL ); window_modifyText( wid, "txtDescription", NULL ); window_modifyText( wid, "txtDDesc", buf ); return; } ship = ship_get( shipname ); shipyard_selected = ship; /* update image */ window_modifyImage( wid, "imgTarget", ship->gfx_store, 0, 0 ); /* update text */ window_modifyText( wid, "txtStats", ship->desc_stats ); window_modifyText( wid, "txtDescription", ship->description ); price2str( buf2, ship_buyPrice(ship), player.p->credits, 2 ); credits2str( buf3, player.p->credits, 2 ); /* Remove the word " License". It's redundant and makes the text overflow into another text box */ license_text = ship->license; if (license_text) { len = strlen(ship->license); if (strcmp(" License", ship->license + len - 8) == 0) { license_text = malloc(len - 7); assert(license_text); memcpy(license_text, ship->license, len - 8); license_text[len - 8] = '\0'; } } nsnprintf( buf, PATH_MAX, "%s\n" "%s\n" "%s\n" "%d\n" "\n" "%.0f teraflops\n" "%.0f tons\n" "%.0f kN/ton\n" "%.0f m/s\n" "%.0f deg/s\n" "\n" "%.0f%% damage\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f tons\n" "%d units\n" "%.0f units\n" "%s credits\n" "%s credits\n" "%s\n", ship->name, ship_class(ship), ship->fabricator, ship->crew, /* Weapons & Manoeuvrability */ ship->cpu, ship->mass, ship->thrust, ship->speed, ship->turn*180/M_PI, /* Misc */ ship->dmg_absorb*100., ship->shield, ship->shield_regen, ship->armour, ship->armour_regen, ship->energy, ship->energy_regen, ship->cap_cargo, ship->fuel, ship->fuel_consumption, buf2, buf3, (license_text != NULL) ? license_text : "None" ); window_modifyText( wid, "txtDDesc", buf ); if (license_text != ship->license) free(license_text); if (!shipyard_canBuy( shipname, land_planet )) window_disableButtonSoft( wid, "btnBuyShip"); else window_enableButton( wid, "btnBuyShip"); if (!shipyard_canTrade( shipname )) window_disableButtonSoft( wid, "btnTradeShip"); else window_enableButton( wid, "btnTradeShip"); }
/** * @brief Updates the ships in the shipyard window. * @param wid Window to update the ships in. * @param str Unused. */ void shipyard_update( unsigned int wid, char* str ) { (void)str; char *shipname; Ship* ship; char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN]; shipname = toolkit_getImageArray( wid, "iarShipyard" ); /* No ships */ if (strcmp(shipname,"None")==0) { window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_disableButton( wid, "btnBuyShip"); window_disableButton( wid, "btnTradeShip"); snprintf( buf, PATH_MAX, "None\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" "NA\n" ); window_modifyImage( wid, "imgTarget", NULL, 0, 0 ); window_modifyText( wid, "txtStats", NULL ); window_modifyText( wid, "txtDescription", NULL ); window_modifyText( wid, "txtDDesc", buf ); return; } ship = ship_get( shipname ); shipyard_selected = ship; /* update image */ window_modifyImage( wid, "imgTarget", ship->gfx_store, 0, 0 ); /* update text */ window_modifyText( wid, "txtStats", ship->desc_stats ); window_modifyText( wid, "txtDescription", ship->description ); credits2str( buf2, ship->price, 2 ); credits2str( buf3, player.p->credits, 2 ); snprintf( buf, PATH_MAX, "%s\n" "%s\n" "%s\n" "%d\n" "\n" "%.0f teraflops\n" "%.0f tons\n" "%.1f STU average\n" "%.0f kN/ton\n" "%.0f m/s\n" "%.0f deg/s\n" "\n" "%.0f%% damage\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f MJ (%.1f MW)\n" "%.0f tons\n" "%d units\n" "%s credits\n" "%s credits\n" "%s\n", ship->name, ship_class(ship), ship->fabricator, ship->crew, /* Weapons & Manoeuvrability */ ship->cpu, ship->mass, pow( ship->mass, 1./2.5 ) / 5. * (ship->stats_array.jump_delay/100.+1.), /**< @todo make this more portable. */ ship->thrust / ship->mass, ship->speed, ship->turn*180/M_PI, /* Misc */ ship->dmg_absorb*100., ship->shield, ship->shield_regen, ship->armour, ship->armour_regen, ship->energy, ship->energy_regen, ship->cap_cargo, ship->fuel, buf2, buf3, (ship->license != NULL) ? ship->license : "None" ); window_modifyText( wid, "txtDDesc", buf ); if (!shipyard_canBuy( shipname )) window_disableButton( wid, "btnBuyShip"); else window_enableButton( wid, "btnBuyShip"); if (!shipyard_canTrade( shipname )) window_disableButton( wid, "btnTradeShip"); else window_enableButton( wid, "btnTradeShip"); }