project_files/frontlib/model/weapon.h
author Medo <smaxein@googlemail.com>
Wed, 27 Jun 2012 22:52:19 +0200
changeset 7314 6171f0bad318
parent 7275 15f722e0b96f
child 7320 e704706008d4
permissions -rw-r--r--
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib files that did not have their license fixed already.

/*
 * Hedgewars, a free turn based strategy game
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef MODEL_WEAPON_H_
#define MODEL_WEAPON_H_

#include "../hwconsts.h"

/**
 * These values are all in the range 0..9
 *
 * For loadout, 9 means inifinite ammo.
 * For the other setting, 9 is invalid.
 */
typedef struct {
	int _referenceCount;
	char loadout[WEAPONS_COUNT+1];
	char crateprob[WEAPONS_COUNT+1];
	char crateammo[WEAPONS_COUNT+1];
	char delay[WEAPONS_COUNT+1];
	char *name;
} flib_weaponset;

typedef struct {
	int _referenceCount;
	int weaponsetCount;
	flib_weaponset **weaponsets;
} flib_weaponsetlist;

/**
 * Returns a new weapon set, or NULL on error.
 * name must not be NULL.
 *
 * The new weapon set is pre-filled with default
 * settings (see hwconsts.h)
 */
flib_weaponset *flib_weaponset_create(const char *name);

/**
 * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
 * Returns the parameter.
 */
flib_weaponset *flib_weaponset_retain(flib_weaponset *weaponset);

/**
 * Decrease the reference count of the object and free it if this was the last reference.
 */
void flib_weaponset_release(flib_weaponset *weaponset);

flib_weaponset *flib_weaponset_copy(const flib_weaponset *weaponset);

/**
 * Create a weaponset from an ammostring. This format is used both in the ini files
 * and in the net protocol.
 */
flib_weaponset *flib_weaponset_from_ammostring(const char *name, const char *ammostring);

/**
 * Load a list of weaponsets from the ini file.
 * Returns NULL on error.
 */
flib_weaponsetlist *flib_weaponsetlist_from_ini(const char *filename);

/**
 * Store the list of weaponsets to an ini file.
 * Returns NULL on error.
 */
int flib_weaponsetlist_to_ini(const char *filename, const flib_weaponsetlist *weaponsets);

/**
 * Create an empty weaponset list. Returns NULL on error.
 */
flib_weaponsetlist *flib_weaponsetlist_create();

/**
 * Insert a new weaponset into the list at position pos, moving all higher weaponsets to make place.
 * pos must be at least 0 (insert at the start) and at most list->weaponsetCount (insert at the end).
 * The weaponset is retained automatically.
 * Returns 0 on success.
 */
int flib_weaponsetlist_insert(flib_weaponsetlist *list, flib_weaponset *weaponset, int pos);

/**
 * Delete a weaponset from the list at position pos, moving down all higher weaponsets.
 * The weaponset is released automatically.
 * Returns 0 on success.
 */
int flib_weaponsetlist_delete(flib_weaponsetlist *list, int pos);

/**
 * Increase the reference count of the object. Call this if you store a pointer to it somewhere.
 * Returns the parameter.
 */
flib_weaponsetlist *flib_weaponsetlist_retain(flib_weaponsetlist *list);

/**
 * Decrease the reference count of the object and free it if this was the last reference.
 */
void flib_weaponsetlist_release(flib_weaponsetlist *list);

#endif