MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / LoadWeaponsDescription

Function LoadWeaponsDescription

PanzerChasm/game_resources.cpp:190–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190static void LoadWeaponsDescription(
191 const Vfs::FileContent& inf_file,
192 GameResources& game_resources )
193{
194 const char* const weapons_start=
195 std::strstr( reinterpret_cast<const char*>(inf_file.data()), "[WEAPONS]" );
196 const char* const weapons_end= reinterpret_cast<const char*>(inf_file.data()) + inf_file.size() - 1u;
197
198 std::istringstream stream( std::string( weapons_start, weapons_end ) );
199
200 char line[ 512 ];
201 stream.getline( line, sizeof(line), '\n' );
202
203 unsigned int weapon_count= 0u;
204 stream >> weapon_count;
205 stream.getline( line, sizeof(line), '\n' );
206
207 game_resources.weapons_description.resize( weapon_count );
208
209 for( unsigned int i= 0u; i < weapon_count; i++ )
210 {
211 GameResources::WeaponDescription& weapon_description= game_resources.weapons_description[i];
212
213 for( unsigned int j= 0u; j < 3u; j++ )
214 {
215 stream.getline( line, sizeof(line), '\n' );
216
217 const char* param_start= line;
218 while( std::isspace( *param_start ) ) param_start++;
219
220 const char* param_end= param_start;
221 while( std::isalpha( *param_end ) ) param_end++;
222
223 const char* value_start= param_end;
224 while( std::isspace( *value_start ) ) value_start++;
225 value_start++;
226 while( std::isspace( *value_start ) ) value_start++;
227
228 const char* value_end= value_start;
229 while( !std::isspace( *value_end ) ) value_end++;
230
231 const unsigned int param_length= param_end - param_start;
232 const unsigned int value_length= value_end - value_start;
233
234 if( std::strncmp( param_start, "MODEL", param_length ) == 0 )
235 std::strncpy( weapon_description.model_file_name, value_start, value_length );
236 else if( std::strncmp( param_start, "STAT", param_length ) == 0 )
237 std::strncpy( weapon_description.animation_file_name, value_start, value_length );
238 else if( std::strncmp( param_start, "SHOOT", param_length ) == 0 )
239 std::strncpy( weapon_description.reloading_animation_file_name, value_start, value_length );
240 }
241
242 stream.getline( line, sizeof(line), '\n' );
243 std::istringstream line_stream{ std::string( line ) };
244
245 line_stream >> weapon_description.r_type;
246 line_stream >> weapon_description.reloading_time;
247 line_stream >> weapon_description.y_sh;

Callers 1

LoadGameResourcesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected