00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <string.h>
00037 #include <tpia_depot.h>
00038
00039 #if defined __cplusplus
00040 namespace GIDI{
00041 using namespace GIDI;
00042 #endif
00043
00044
00045
00046
00047 tpia_depot *tpia_depot_create( statusMessageReporting *smr, const char *projectileName ) {
00048
00049 tpia_depot *depot;
00050
00051
00052 if( ( depot = (tpia_depot*) xData_malloc2( smr, sizeof( tpia_depot ), 0, "map" ) ) == NULL ) return( NULL );
00053 if( tpia_depot_initialize( smr, depot, projectileName ) ) depot = tpia_depot_free( depot, 0 );
00054 return( depot );
00055 }
00056
00057
00058
00059 int tpia_depot_initialize( statusMessageReporting *smr, tpia_depot *depot, const char *projectileName ) {
00060
00061 memset( depot, 0, sizeof( tpia_depot ) );
00062 depot->status = 0;
00063 depot->projectileName = NULL;
00064 depot->numberOfTargets = 0;
00065 depot->targets = NULL;
00066 depot->map = NULL;
00067
00068 if( ( depot->projectileName = (char*) xData_malloc2( smr, strlen( projectileName ) + 1, 0, "projectile" ) ) == NULL ) return( 1 );
00069 return( 0 );
00070 }
00071
00072
00073
00074 tpia_depot *tpia_depot_free( tpia_depot *depot, int freeMap ) {
00075
00076 tpia_depot_release( depot, freeMap );
00077 xData_free( NULL, depot );
00078 return( NULL );
00079 }
00080
00081
00082
00083 int tpia_depot_release( tpia_depot *depot, int freeMap ) {
00084
00085 tpia_targetEntry *next, *targetEntry;
00086
00087 if( depot->projectileName != NULL ) xData_free( NULL, depot->projectileName );
00088 for( targetEntry = depot->targets; targetEntry != NULL; targetEntry = next ) {
00089 next = targetEntry->next;
00090 tpia_target_free( NULL, targetEntry->target );
00091 xData_free( NULL, targetEntry );
00092 }
00093 depot->numberOfTargets = 0;
00094 depot->targets = NULL;
00095
00096 if( freeMap && ( depot->map != NULL ) ) depot->map = (tpia_map*) tpia_map_free( NULL, depot->map );
00097 return( depot->status = 0 );
00098 }
00099
00100
00101
00102
00103 int tpia_depot_setMap( statusMessageReporting *, tpia_depot *depot, tpia_map *map ) {
00104
00105 depot->map = map;
00106 return( 0 );
00107 }
00108
00109
00110
00111 int tpia_depot_setMapFromFilename( statusMessageReporting *smr, tpia_depot *depot, const char *basePath, const char *mapFileName ) {
00112
00113 if( ( depot->map = tpia_map_readFile( smr, basePath, mapFileName ) ) == NULL ) return( 1 );
00114 return( 0 );
00115 }
00116
00117
00118
00119 tpia_map *tpia_depot_releaseMap( tpia_depot *depot ) {
00120
00121 tpia_map *map = depot->map;
00122
00123 depot->map = NULL;
00124 return( map );
00125 }
00126
00127
00128
00129 int tpia_depot_freeMap( tpia_depot *depot ) {
00130
00131 tpia_map *map = tpia_depot_releaseMap( depot );
00132
00133 if( map != NULL ) tpia_map_free( NULL, map );
00134 return( 0 );
00135 }
00136
00137
00138
00139 tpia_targetEntry *tpia_depot_getFirstTargetEntry( tpia_depot *depot ) {
00140
00141 return( depot->targets );
00142 }
00143
00144
00145
00146 tpia_targetEntry *tpia_depot_getNextTargetEntry( tpia_targetEntry *targetEntry ) {
00147
00148 return( targetEntry->next );
00149 }
00150
00151
00152
00153 tpia_target *tpia_depot_addTarget( statusMessageReporting *smr, tpia_depot *depot, const char *evaluation, const char *targetName ) {
00154
00155 return( tpia_depot_addTargetFromMap( smr, depot, depot->map, evaluation, targetName ) );
00156 }
00157
00158
00159
00160 tpia_target *tpia_depot_addTargetFromMap( statusMessageReporting *smr, tpia_depot *depot, tpia_map *map, const char *evaluation, const char *targetName ) {
00161
00162 tpia_targetEntry *targetEntry;
00163 tpia_target *target;
00164
00165 for( targetEntry = tpia_depot_getFirstTargetEntry( depot ); targetEntry != NULL; targetEntry = tpia_depot_getNextTargetEntry( targetEntry ) ) {
00166 if( !strcmp( targetEntry->target->targetID->name, targetName ) ) {
00167 smr_setMessageError( smr, NULL, __FILE__, __LINE__, 1, "depot already contains target = %s ", targetName );
00168 return( NULL );
00169 }
00170 }
00171 target = tpia_target_createReadFromMap( smr, map, evaluation, depot->projectileName, targetName );
00172 return( target );
00173 }
00174
00175 #if defined __cplusplus
00176 }
00177 #endif