cp_mission_triggers.c

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 */
00025 
00026 #include "../cl_shared.h"
00027 #include "../ui/ui_main.h" /* TEXT_STANDARD */
00028 #include "cp_campaign.h"
00029 #include "cp_map.h"
00030 #include "cp_missions.h"
00031 #include "cp_mission_triggers.h"
00032 
00038 static void CP_AddTechAsResearchable_f (void)
00039 {
00040     const char *techID;
00041     technology_t *tech;
00042 
00043     if (Cmd_Argc() < 2) {
00044         Com_Printf("Usage: %s <tech>\n", Cmd_Argv(0));
00045         return;
00046     }
00047 
00048     techID = Cmd_Argv(1);
00049     tech = RS_GetTechByID(techID);
00050     RS_MarkOneResearchable(tech);
00051 }
00052 
00060 static void CP_AddItemAsCollected_f (void)
00061 {
00062     int i, baseID;
00063     const char* id;
00064 
00065     if (Cmd_Argc() < 2) {
00066         Com_Printf("Usage: %s <item>\n", Cmd_Argv(0));
00067         return;
00068     }
00069 
00070     id = Cmd_Argv(1);
00071     baseID = atoi(Cmd_Argv(2));
00072 
00073     /* i = item index */
00074     for (i = 0; i < csi.numODs; i++) {
00075         const objDef_t *item = INVSH_GetItemByIDX(i);
00076         if (!strcmp(id, item->id)) {
00077             technology_t *tech = RS_GetTechForItem(item);
00078             base_t *base = B_GetBaseByIDX(baseID);
00079             base->storage.numItems[i]++;
00080             Com_DPrintf(DEBUG_CLIENT, "add item: '%s'\n", item->id);
00081             RS_MarkCollected(tech);
00082         }
00083     }
00084 }
00085 
00090 static void CP_ChangeNationHappiness_f (void)
00091 {
00092     float change;
00093     nation_t *nation;
00094 
00095     if (Cmd_Argc() < 2) {
00096         Com_Printf("Usage: %s <absolute change value>\n", Cmd_Argv(0));
00097         return;
00098     }
00099     change = atof(Cmd_Argv(1));
00100 
00101     if (!ccs.selectedMission) {
00102         Com_Printf("No mission selected - could not determine nation to use\n");
00103         return;
00104     }
00105 
00106     /* we can use an assert here - because this script function will only
00107      * be available as trigger command - selectedMission must be set at that stage */
00108     assert(ccs.selectedMission);
00109     nation = MAP_GetNation(ccs.selectedMission->pos);
00110     assert(nation);
00111 
00112     NAT_SetHappiness(nation, nation->stats[0].happiness + change);
00113 }
00114 
00120 static void CP_EndGame_f (void)
00121 {
00122     UI_RegisterText(TEXT_STANDARD, _("Congratulations! You have reached the end of the UFO:AI campaign.\n"
00123         "However, this is not the end of the road. The game remains in development.\n"
00124         "The campaign will be expanded with new missions, new enemies, "
00125         "new UFOs, new player controllable craft and more research.\n\n"
00126         "And YOU can help make it happen! Visit our forums or IRC channel to find\n"
00127         "out what you can do to help finish this game. Alternatively, you can just\n"
00128         "come by and talk about the game, or find other players for a multiplayer game.\n\n"
00129         "Thank you for playing, and we hope to see you around.\n\n"
00130         "   - The UFO:AI development team"));
00131     CP_EndCampaign(qtrue);
00132 }
00133 
00135 static const cmdList_t cp_commands[] = {
00136     {"cp_add_researchable", CP_AddTechAsResearchable_f, "Add a tech as researchable"},
00137     {"cp_add_item", CP_AddItemAsCollected_f, "Add an item as collected"},
00138     {"cp_changehappiness", CP_ChangeNationHappiness_f, "Function to raise or lower nation happiness."},
00139     {"cp_endgame", CP_EndGame_f, "This command will end the current campaign"},
00140 
00141     {NULL, NULL, NULL}
00142 };
00143 
00149 static void CP_MissionTriggerFunctions (qboolean add)
00150 {
00151     const cmdList_t *commands;
00152 
00153     for (commands = cp_commands; commands->name; commands++)
00154         if (add)
00155             Cmd_AddCommand(commands->name, commands->function, commands->description);
00156         else
00157             Cmd_RemoveCommand(commands->name);
00158 }
00159 
00168 void CP_ExecuteMissionTrigger (mission_t *m, qboolean won)
00169 {
00170     Com_DPrintf(DEBUG_CLIENT, "Execute mission triggers\n");
00171 
00172     if (m == NULL) {
00173         Com_Printf("CL_ParseResults: Error - no mission triggers, because ccs.selectedMission is not set\n");
00174         return;
00175     }
00176 
00177     /* we add them only here - and remove them afterwards to prevent cheating */
00178     CP_MissionTriggerFunctions(qtrue);
00179 
00180     if (won) {
00181         if (m->onwin[0] != '\0') {
00182             Com_DPrintf(DEBUG_CLIENT, "...won - executing '%s'\n", m->onwin);
00183             Cmd_ExecuteString(m->onwin);
00184         }
00185         if (m->mapDef && m->mapDef->onwin != NULL) {
00186             Com_DPrintf(DEBUG_CLIENT, "...won - executing '%s'\n", m->mapDef->onwin);
00187             Cmd_ExecuteString(m->mapDef->onwin);
00188         }
00189     } else {
00190         if (m->onlose[0] != '\0') {
00191             Com_DPrintf(DEBUG_CLIENT, "...lost - executing '%s'\n", m->onlose);
00192             Cmd_ExecuteString(m->onlose);
00193         }
00194         if (m->mapDef && m->mapDef->onlose != NULL) {
00195             Com_DPrintf(DEBUG_CLIENT, "...lost - executing '%s'\n", m->mapDef->onlose);
00196             Cmd_ExecuteString(m->mapDef->onlose);
00197         }
00198     }
00199     CP_MissionTriggerFunctions(qfalse);
00200 }

Generated by  doxygen 1.6.2