Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

RaceForm.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003  Anders Hedstrom
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <mysql/mysql.h>
00022 #include <libsql++.h>
00023 #include <string>
00024 using std::string;
00025 #include <libcgi++.h>
00026 #include <libwolfshade.h>
00027 
00028 #include "BaseForm.h"
00029 #include "WolfshadeWeb.h"
00030 //#include "CMemoryAllocator.h"
00031 //#include "MyString.h"
00032 #include "RaceForm.h"
00033 
00034 
00035 namespace cgi
00036 {
00037 
00038 
00039 RaceForm::RaceForm(Web *web)
00040 :BaseForm(web, "raceform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 {
00044         Query q(GetDatabase());
00045 
00046         q.get_result("select * from race_size");
00047         while (q.fetch_row())
00048         {
00049                 db::Race_size *tmp = new db::Race_size(GetDatabase(),&q);
00050                 m_size[tmp -> num] = tmp;
00051         }
00052         q.free_result();
00053 }
00054 
00055 
00056 RaceForm::~RaceForm()
00057 {
00058         for (racesizes_t::iterator it = m_size.begin(); it != m_size.end(); it++)
00059         {
00060                 delete (*it).second;
00061         }
00062 }
00063 
00064 
00065 void RaceForm::Process()
00066 {
00067         char action[200];
00068         
00069         if (GetForm() -> getvalue("raceform",action,200))
00070         {
00071                 if (!strcmp(action,"edit"))
00072                 {
00073                         char slask[100];
00074                         GetForm() -> getvalue("edit",slask,100);
00075                         m_edit = atol(slask);
00076                 }
00077                 else
00078                 if (!strcmp(action," Save "))
00079                 {
00080                         char slask[100];
00081                         GetForm() -> getvalue("num",slask,100);
00082                         long num = atol(slask);
00083                         GetForm() -> getvalue("onum",slask,100);
00084                         long onum = atol(slask);
00085                         db::Race race(GetDatabase(),num);
00086 
00087                         if (num != onum && race.num)
00088                         {
00089                                 m_error = true;
00090                         }
00091                         else
00092                         {
00093                                 long innatebits = 0;
00094                                 char value[256];
00095                                 GetForm() -> getfirst(slask,100,value,256);
00096                                 while (*slask)
00097                                 {
00098                                         if (!strcmp(slask,"abilities"))
00099                                                 innatebits |= atol(value);
00100                                         //
00101                                         GetForm() -> getnext(slask,100,value,256);
00102                                 }
00103 // alias, name, dpd, descr, longdescr
00104                                 GetForm() -> EnableRaw( true );
00105                                 race.num = num;
00106                                 GetForm() -> getvalue("alias",race.alias,255);
00107                                 GetForm() -> getvalue("name",race.name,255);
00108 #define GET(x,y) \
00109         GetForm() -> getvalue(x,slask,100); \
00110         y = atol(slask);
00111                                 GET("start_room",race.start_room);
00112                                 GET("size",race.size);
00113                                 //
00114                                 race.abilities = innatebits;
00115                                 GET("height_min",race.height_min);
00116                                 GET("height_max",race.height_max);
00117                                 GET("weight_min",race.weight_min);
00118                                 GET("weight_max",race.weight_max);
00119                                 GET("age_min",race.age_min);
00120                                 GET("age_max",race.age_max);
00121                                 GET("starting_alignment",race.starting_alignment);
00122                                 GET("race_war",race.race_war);
00123 /*
00124 const short CAttributes::SAVE_BREATH = 0;
00125 const short CAttributes::SAVE_PARA = 1;
00126 const short CAttributes::SAVE_SPELL = 2;
00127 const short CAttributes::SAVE_POISON = 3;
00128 */
00129                                 GET("save_breath",race.save_breath);
00130                                 GET("save_para",race.save_para);
00131                                 GET("save_spell",race.save_spell);
00132                                 GET("save_poison",race.save_poison);
00133                                 //
00134                                 race.save();
00135                                 m_edit = num;
00136                         }
00137                 }
00138         }
00139 }
00140 
00141 
00142 void RaceForm::Select(const string &)
00143 {
00144 }
00145 
00146 
00147 void RaceForm::List()
00148 {
00149 }
00150 
00151 
00152 void RaceForm::Display(long)
00153 {
00154         WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00155         Database *db = GetDatabase();
00156         Query q(db);
00157         long zonesize = 0;
00158         char sql[200];
00159 
00160         zonesize = EditingZone();
00161 
00162         if (!m_edit)
00163                 web -> DisplayStartAntalForm();
00164 
00165         if (m_error)
00166         {
00167                 printf("<h3>New Race# is already taken</h3>");
00168         }
00169 
00170         {
00171                 if (m_edit)
00172                         sprintf(sql,"select * from race where num=%ld",m_edit);
00173                 else
00174                 {
00175                         sprintf(sql,"select * from race where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00176                 }
00177                 q.get_result(sql);
00178                 char header[100];
00179                 
00180                 if (m_edit)
00181                         sprintf(header,"&nbsp;Editing Race#%ld",m_edit);
00182                 else
00183                         sprintf(header,"&nbsp;Races (%ld races displayed)",q.num_rows());
00184                 Table tbl("#000000", 3, header);
00185                 printf("<tr bgcolor=#ffffff>");
00186                 printf("<th align=left>&nbsp;Race | Vnum</th>");
00187                 printf("<th align=left>&nbsp;Start Room</th>");
00188                 printf("<th align=left>&nbsp;Size</th>");
00189                 printf("<th align=left colspan=2>&nbsp;Height</th>");
00190                 printf("<th align=left colspan=2>&nbsp;Weight</th>");
00191                 printf("<th align=left colspan=2>&nbsp;Age</th>");
00192                 printf("</tr>");
00193 
00194                 while (q.fetch_row())
00195                 {
00196                         db::Race race(db,&q);
00197                         db::Room room(db,race.start_room);
00198                         db::Race_size *tmp = m_size[race.size];
00199 
00200                         printf("<tr bgcolor=#808080>");
00201                         ShowRace(race,true,true);
00202                         if (room.num)
00203                         {
00204                                 ShowRoom(room,true,true);
00205                         }
00206                         else
00207                         {
00208                                 printf("<td align=middle>-</td>");
00209                         }
00210                         // race size
00211                         printf("<td bgcolor=#c0c0c0 align=middle>%s</td>",
00212                                 tmp ? tmp -> name : "");
00213                         printf("<td bgcolor=#c0c0c0 align=right>&nbsp;%ld&nbsp;</td>",race.height_min);
00214                         printf("<td bgcolor=#c0c0c0 align=right>&nbsp;%ld&nbsp;</td>",race.height_max);
00215                         printf("<td bgcolor=#c0c0c0 align=right>&nbsp;%ld&nbsp;</td>",race.weight_min);
00216                         printf("<td bgcolor=#c0c0c0 align=right>&nbsp;%ld&nbsp;</td>",race.weight_max);
00217                         printf("<td bgcolor=#c0c0c0 align=right>&nbsp;%ld&nbsp;</td>",race.age_min);
00218                         printf("<td bgcolor=#c0c0c0 align=right>&nbsp;%ld&nbsp;</td>",race.age_max);
00219                         printf("</tr>");
00220                 }
00221                 q.free_result();
00222         }
00223         printf("<br>");
00224 
00225         if (m_edit)
00226         {
00227                 db::Race race(db,m_edit);
00228 
00229                 // references to this race
00230                 {
00231                 }
00232 
00233                 // edit
00234                 {
00235                         Table tbl("#000000", 3);
00236 
00237                         printf("<form action=%s method=post>",GetCgiName().c_str());
00238                         printf("<input type=hidden name=onum value=%ld>",race.num);
00239 
00240                         inputnum("Vnum", "num", race.num);
00241                         inputstr("Alias","alias",40,race.alias);
00242                         inputstr("RaceName","name",60,race.name,true);
00243                         inputnum("StartRoom","start_room",race.start_room,VALUE_IS_ROOM);
00244                         inputselect(q,"Size","size","select num,name from race_size order by num",race.size);
00245                         // abilities inputbit
00246                         inputbit(q,"Abilities","abilities","select num,name from innate order by name",race.abilities,3);
00247                         inputnum("Min Height","height_min",race.height_min);
00248                         inputnum("Max Height","height_max",race.height_max);
00249                         inputnum("Min Weight","weight_min",race.weight_min);
00250                         inputnum("Max Weight","weight_max",race.weight_max);
00251                         inputnum("Min Age","age_min",race.age_min);
00252                         inputnum("Max Age","age_max",race.age_max);
00253                         inputnum("StartingAlignment","starting_alignment",race.starting_alignment);
00254                         inputnum("RaceWar","race_war",race.race_war);
00255                         inputnum("Save Breath","save_breath",race.save_breath);
00256                         inputnum("Save Para","save_para",race.save_para);
00257                         inputnum("Save Spell","save_spell",race.save_spell);
00258                         inputnum("Save Poison","save_poison",race.save_poison);
00259                         inputsubmit(" Save ");
00260 /*
00261 const short CAttributes::SAVE_BREATH = 0;
00262 const short CAttributes::SAVE_PARA = 1;
00263 const short CAttributes::SAVE_SPELL = 2;
00264 const short CAttributes::SAVE_POISON = 3;
00265 */
00266 /*
00267 CREATE TABLE race (
00268   num int(11) NOT NULL default '0',
00269   alias varchar(255) NOT NULL default '',
00270   name varchar(255) NOT NULL default '',
00271   start_room int(11) NOT NULL default '0',
00272   size int(11) NOT NULL default '0',
00273   abilities int(11) NOT NULL default '0',
00274   height_min int(11) NOT NULL default '0',
00275   height_max int(11) NOT NULL default '0',
00276   weight_min int(11) NOT NULL default '0',
00277   weight_max int(11) NOT NULL default '0',
00278   age_min int(11) NOT NULL default '0',
00279   age_max int(11) NOT NULL default '0',
00280   starting_alignment int(11) NOT NULL default '0',
00281   race_war int(11) NOT NULL default '0',
00282   PRIMARY KEY  (num)
00283 ) TYPE=MyISAM;
00284 */
00285                         printf("</form>");
00286                 }
00287                 printf("<br>");
00288         }
00289 }
00290 
00291 
00292 } // namespace cgi
00293 
00294 
00295 

Generated for Wolfshade by doxygen 1.3.6

Page, code, and content Copyright (C) 2004 by Anders Hedström