00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00031
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
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
00125
00126
00127
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," Editing Race#%ld",m_edit);
00182 else
00183 sprintf(header," Races (%ld races displayed)",q.num_rows());
00184 Table tbl("#000000", 3, header);
00185 printf("<tr bgcolor=#ffffff>");
00186 printf("<th align=left> Race | Vnum</th>");
00187 printf("<th align=left> Start Room</th>");
00188 printf("<th align=left> Size</th>");
00189 printf("<th align=left colspan=2> Height</th>");
00190 printf("<th align=left colspan=2> Weight</th>");
00191 printf("<th align=left colspan=2> 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
00211 printf("<td bgcolor=#c0c0c0 align=middle>%s</td>",
00212 tmp ? tmp -> name : "");
00213 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",race.height_min);
00214 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",race.height_max);
00215 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",race.weight_min);
00216 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",race.weight_max);
00217 printf("<td bgcolor=#c0c0c0 align=right> %ld </td>",race.age_min);
00218 printf("<td bgcolor=#c0c0c0 align=right> %ld </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
00230 {
00231 }
00232
00233
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
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
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 printf("</form>");
00286 }
00287 printf("<br>");
00288 }
00289 }
00290
00291
00292 }
00293
00294
00295