00001 /* 00002 * Empire - A multi-player, client/server Internet based war game. 00003 * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak, 00004 * Ken Stevens, Steve McClure 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 * 00020 * --- 00021 * 00022 * See files README, COPYING and CREDITS in the root of the source 00023 * tree for related information and legal notices. It is expected 00024 * that future projects/authors will amend these files as needed. 00025 * 00026 * --- 00027 * 00028 * natarg.c: Return countr # given country name or country # 00029 * 00030 * Known contributors to this file: 00031 * Markus Armbruster, 2006 00032 */ 00033 00034 #include <config.h> 00035 00036 #include <ctype.h> 00037 #include <stdlib.h> 00038 #include "file.h" 00039 #include "match.h" 00040 #include "misc.h" 00041 #include "nat.h" 00042 #include "optlist.h" 00043 #include "player.h" 00044 #include "prototypes.h" 00045 00046 /* 00047 * Get nation argument. 00048 * If ARG is not empty, use it, else prompt for input using PROMPT. 00049 * If no input is provided, return NULL. 00050 * If the argument identifies a country, return its getnatp() value. 00051 * Else complain and return NULL. 00052 * Caution: this function doesn't care for lack of contact. 00053 */ 00054 struct natstr * 00055 natargp(char *arg, char *prompt) 00056 { 00057 char buf[1024]; 00058 int n; 00059 struct natstr *np; 00060 00061 arg = getstarg(arg, prompt, buf); 00062 if (arg == 0 || *arg == 0) 00063 return NULL; 00064 if (isdigit(*arg)) 00065 n = atoi(arg); 00066 else { 00067 n = cnumb(arg); 00068 if (n == M_NOTUNIQUE) { 00069 pr("Country '%s' is ambiguous\n", arg); 00070 return NULL; 00071 } 00072 } 00073 np = getnatp(n); 00074 if (!np || np->nat_stat == STAT_UNUSED) { 00075 pr("Country '%s' doesn't exist.\n", arg); 00076 return NULL; 00077 } 00078 return np; 00079 } 00080 00081 /* 00082 * Get nation argument. 00083 * If ARG is not empty, use it, else prompt for input using PROMPT. 00084 * If no input is provided, return -1. 00085 * If the argument identifies a country, return its number. getnatp() 00086 * can be assumed to succeed for this number. 00087 * Else complain and return -1. 00088 * If HIDDEN is enabled, countries not contacted are not eligible 00089 * unless the player is a deity. 00090 */ 00091 int 00092 natarg(char *arg, char *prompt) 00093 { 00094 struct natstr *np = natargp(arg, prompt); 00095 if (!np) 00096 return -1; 00097 if (opt_HIDDEN) { 00098 if (!player->god && !getcontact(getnatp(player->cnum), np->nat_cnum)) { 00099 if (np->nat_stat != STAT_GOD) { 00100 pr("Country '%s' has not been contacted.\n", arg); 00101 return -1; 00102 } 00103 } 00104 } 00105 return np->nat_cnum; 00106 }
1.5.2