cl_tip.c

Go to the documentation of this file.
00001 
00006 /*
00007 All original material Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 Copyright (C) 1997-2001 Id Software, Inc.
00010 
00011 This program is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00019 
00020 See the GNU General Public License for more details.
00021 
00022 You should have received a copy of the GNU General Public License
00023 along with this program; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00025 
00026 */
00027 
00028 #include "client.h"
00029 #include "cl_tip.h"
00030 #include "ui/ui_main.h"
00031 #include "../shared/parse.h"
00032 
00033 typedef struct tipOfTheDay_s {
00034     const char *tipString;  
00035     struct tipOfTheDay_s* next;
00036 } tipOfTheDay_t;
00037 
00038 static tipOfTheDay_t *tipList;  
00039 static int tipCount; 
00041 static cvar_t* cl_showTipOfTheDay;  
00048 static void CL_GetTipOfTheDay_f (void)
00049 {
00050     static int lastOne = 0;
00051     int rnd;
00052     tipOfTheDay_t* tip;
00053 
00055     if (!tipCount) {
00056         UI_CloseWindow("popup_tipoftheday");
00057         Com_Printf("No tips parsed\n");
00058         return;
00059     }
00060 
00061     if (Cmd_Argc() == 2) {
00062         rnd = rand() % tipCount;
00063         lastOne = rnd;
00064     } else {
00065         lastOne = (lastOne + 1) % tipCount;
00066         rnd = lastOne;
00067     }
00068 
00069     tip = tipList;
00070     while (rnd) {
00071         tip = tip->next;
00072         rnd--;
00073     }
00074 
00075     UI_RegisterText(TEXT_TIPOFTHEDAY, tip->tipString);
00076 }
00077 
00081 void CL_ParseTipsOfTheDay (const char *name, const char **text)
00082 {
00083     const char *errhead = "CL_ParseTipsOfTheDay: unexpected end of file (tips ";
00084     const char  *token;
00085     tipOfTheDay_t *tip;
00086 
00087     /* get it's body */
00088     token = Com_Parse(text);
00089 
00090     if (!*text || *token != '{') {
00091         Com_Printf("CL_ParseTipsOfTheDay: tips without body ignored\n");
00092         return;
00093     }
00094 
00095     do {
00096         /* get the name type */
00097         token = Com_EParse(text, errhead, name);
00098         if (!*text)
00099             break;
00100         if (*token == '}')
00101             break;
00102         if (*token != '_') {
00103             Com_Printf("Ignore tip: '%s' - not marked translatable\n", token);
00104             continue;
00105         }
00106         tip = Mem_PoolAlloc(sizeof(*tip), cl_genericPool, 0);
00107         tip->tipString = Mem_PoolStrDup(token, cl_genericPool, 0);
00108         tip->next = tipList;
00109         tipList = tip;
00110         tipCount++;
00111     } while (*text);
00112 }
00113 
00117 void TOTD_InitStartup (void)
00118 {
00119     cl_showTipOfTheDay = Cvar_Get("cl_showTipOfTheDay", "1", CVAR_ARCHIVE, "Show the tip of the day for singleplayer campaigns");
00120 
00121     /* commands */
00122     Cmd_AddCommand("tipoftheday", CL_GetTipOfTheDay_f, "Get the next tip of the day from the script files - called from tip of the day menu");
00123 }

Generated by  doxygen 1.6.2