Skip to content

Commit

Permalink
* You can now generate ship csv too.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Jul 8, 2010
1 parent 532f060 commit e190dcf
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Expand Up @@ -21,6 +21,7 @@ naev_SOURCES = \
dev.c \
dev_outfit.c \
dev_planet.c \
dev_ship.c \
dev_system.c \
dev_sysedit.c \
dev_uniedit.c \
Expand Down Expand Up @@ -123,6 +124,7 @@ naev_SOURCES = \
dev.h \
dev_outfit.h \
dev_planet.h \
dev_ship.h \
dev_system.h \
dev_sysedit.h \
dev_uniedit.h \
Expand Down
12 changes: 9 additions & 3 deletions src/dev.c
Expand Up @@ -14,18 +14,24 @@

#include "SDL.h"

#include "log.h"
#include "dev_outfit.h"
#include "dev_ship.h"


/**
*/
void dev_csv (void)
{
printf("Generating CSV data...\n");
DEBUG("Generating CSV data...");

printf(" bolt.csv...");
DEBUG(" bolt.csv...");
dout_csvBolt( "bolt.csv" );
printf("done!\n");
DEBUG("\b done!");

DEBUG(" ship.csv...");
dship_csv( "ship.csv" );
DEBUG("\b done!");
}


65 changes: 65 additions & 0 deletions src/dev_ship.c
@@ -0,0 +1,65 @@
/*
* See Licensing and Copyright notice in naev.h
*/

/**
* @file dev_ship.c
*
* @brief Handles the ship developement routines.
*/

#include "dev_ship.h"

#include "naev.h"

#include "SDL.h"

#include "ship.h"


/**
* @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" );

/* Write "header" */
l = snprintf( buf, sizeof(buf),
"name,base_type,price,license,fabricator,"
"thrust,turn,speed,"
"crew,mass,cpu,fuel,cargo,"
"armour,armour_regen,shield,shield_regen,energy,energy_regen,"
"slot high,slot med,slow low\n"
);
SDL_RWwrite( rw, buf, l, 1 );

s_all = ship_getAll( &n );
for (i=0; i<n; i++) {
s = &s_all[i];

l = snprintf( buf, sizeof(buf),
"%s,%s,%d,%s,%s,"
"%f,%f,%f,"
"%d,%f,%f,%d,%f,"
"%f,%f,%f,%f,%f,%f,"
"%d,%d,%d\n",
s->name, s->base_type, s->price, s->license, s->fabricator,
s->thrust, s->turn, s->speed,
s->crew, s->mass, s->cpu, s->fuel, s->cap_cargo,
s->armour, s->armour_regen, s->shield, s->shield_regen, s->energy, s->energy_regen,
s->outfit_nhigh, s->outfit_nmedium, s->outfit_nlow
);
SDL_RWwrite( rw, buf, l, 1 );
}

/* Close file. */
SDL_RWclose( rw );
}

14 changes: 14 additions & 0 deletions src/dev_ship.h
@@ -0,0 +1,14 @@
/*
* See Licensing and Copyright notice in naev.h
*/



#ifndef DEV_SHIP_H
# define DEV_SHIP_H


void dship_csv( const char *path );


#endif /* DEV_SHIP_H */
10 changes: 10 additions & 0 deletions src/ship.c
Expand Up @@ -99,6 +99,16 @@ Ship* ship_getW( const char* name )
}


/**
* @brief Gets all the ships.
*/
Ship* ship_getAll( int *n )
{
*n = array_size(ship_stack);
return ship_stack;
}


/**
* @brief Comparison function for qsort().
*/
Expand Down
1 change: 1 addition & 0 deletions src/ship.h
Expand Up @@ -154,6 +154,7 @@ int ship_statsDesc( ShipStats *s, char *buf, int len, int newline, int pilot );
*/
Ship* ship_get( const char* name );
Ship* ship_getW( const char* name );
Ship* ship_getAll( int *n );
Ship** ship_getTech( int *n, const int* tech, const int techmax );
char* ship_class( Ship* s );
ShipClass ship_classFromString( char* str );
Expand Down

0 comments on commit e190dcf

Please sign in to comment.