project_files/frontlib/model/gamesetup.c
changeset 7316 f7b49b2c5d84
parent 7314 6171f0bad318
child 7320 e704706008d4
equal deleted inserted replaced
7314:6171f0bad318 7316:f7b49b2c5d84
    16  * along with this program; if not, write to the Free Software
    16  * along with this program; if not, write to the Free Software
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    18  */
    18  */
    19 
    19 
    20 #include "gamesetup.h"
    20 #include "gamesetup.h"
       
    21 #include "../util/util.h"
    21 
    22 
    22 #include <stdlib.h>
    23 #include <stdlib.h>
    23 
    24 
    24 void flib_gamesetup_destroy(flib_gamesetup *gamesetup) {
    25 void flib_gamesetup_destroy(flib_gamesetup *gamesetup) {
    25 	if(gamesetup) {
    26 	if(gamesetup) {
    28 		flib_map_release(gamesetup->map);
    29 		flib_map_release(gamesetup->map);
    29 		flib_teamlist_destroy(gamesetup->teamlist);
    30 		flib_teamlist_destroy(gamesetup->teamlist);
    30 		free(gamesetup);
    31 		free(gamesetup);
    31 	}
    32 	}
    32 }
    33 }
       
    34 
       
    35 flib_gamesetup *flib_gamesetup_copy(flib_gamesetup *setup) {
       
    36 	if(!setup) {
       
    37 		return NULL;
       
    38 	}
       
    39 
       
    40 	flib_gamesetup *result = flib_calloc(1, sizeof(flib_gamesetup));
       
    41 	if(result) {
       
    42 		result->script = flib_strdupnull(setup->script);
       
    43 		result->gamescheme = flib_cfg_copy(setup->gamescheme);
       
    44 		result->map = flib_map_copy(setup->map);
       
    45 		result->teamlist = flib_teamlist_copy(setup->teamlist);
       
    46 		if((setup->script && !result->script)
       
    47 				|| (setup->gamescheme && !result->gamescheme)
       
    48 				|| (setup->map && !result->map)
       
    49 				|| (setup->teamlist && !result->teamlist)) {
       
    50 			flib_gamesetup_destroy(result);
       
    51 			result = NULL;
       
    52 		}
       
    53 	}
       
    54 	return result;
       
    55 }