/* * Copyright (C) 2005 Benjamin Otte * * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Id$ */ #include "game-private.h" #include "game-info.h" #include guint game_info_key_get_size (const GameInfoKey *keys) { guint size = 0; while (keys[size].name) size++; return size; } /** * game_info_key_find: * @keys: a #GameInfoKey * @name: name of the key to find * * Tries to find the key with the given @name in @keys. * * Returns: id of the key or -1 if not found **/ int game_info_key_find (const GameInfoKey *keys, const gchar *name) { int i = 0; while (keys[i].name) { if (!strcmp (keys[i].name, name)) return i; i++; } return -1; } guint game_info_score_get_size (const GameInfoScore *score) { guint size = 0; while (score[size].name) size++; return size; } /** * game_info_score_find: * @score: a #GameInfoScore * @name: name of the score to find * * Tries to find the score with the given @name in @score. * * Returns: id of the score or -1 if not found **/ int game_info_score_find (const GameInfoScore *score, const gchar *name) { int i = 0; while (score[i].name) { if (!strcmp (score[i].name, name)) return i; i++; } return -1; } /** * game_info_score_compare: * @score: a #GameInfoScore * @a: first unsigned integer array the size of @score * @b: second unsigned integer array the size of @score * * Compares the two scores @a and @b. The scores must be provided as integer * arrays containing the scores listed in @score in the same order. * Imagine this function like strcmp () for scores. * * Returns: 0 if the scores are equal, a positive number if @a is better than @b * and a negative number otherwise. **/ int game_info_score_compare (const GameInfoScore *score, const int *a, const int *b) { guint i; g_return_val_if_fail (score != NULL, 0); g_return_val_if_fail (a != NULL, 0); g_return_val_if_fail (b != NULL, 0); for (i = 0; score[i].name != NULL; i++) { if (a[i] > b[i]) return score[i].lower_is_better ? -1 : 1; if (a[i] < b[i]) return score[i].lower_is_better ? 1 : -1; } return 0; }