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 "MobForm.h"
00033
00034
00035 namespace cgi
00036 {
00037
00038
00039 MobForm::MobForm(Web *web)
00040 :BaseForm(web, "mobform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 {
00044 Query q(GetDatabase());
00045
00046 q.get_result("select * from classes");
00047 while (q.fetch_row())
00048 {
00049 db::Classes *tmp = new db::Classes(GetDatabase(),&q);
00050 m_class[tmp -> num] = tmp;
00051 }
00052 q.free_result();
00053
00054 q.get_result("select * from race");
00055 while (q.fetch_row())
00056 {
00057 db::Race *tmp = new db::Race(GetDatabase(),&q);
00058 m_race[tmp -> num] = tmp;
00059 }
00060 q.free_result();
00061 }
00062
00063
00064 MobForm::~MobForm()
00065 {
00066 for (classes_t::iterator it = m_class.begin(); it != m_class.end(); it++)
00067 {
00068 delete (*it).second;
00069 }
00070 for (races_t::iterator it = m_race.begin(); it != m_race.end(); it++)
00071 {
00072 delete (*it).second;
00073 }
00074 }
00075
00076
00077 void MobForm::Process()
00078 {
00079 char action[200];
00080
00081 if (GetForm() -> getvalue("mobform",action,200))
00082 {
00083 if (!strcmp(action,"edit"))
00084 {
00085 char slask[100];
00086 GetForm() -> getvalue("edit",slask,100);
00087 m_edit = atol(slask);
00088 }
00089 else
00090 if (!strcmp(action," Save "))
00091 {
00092 long mobflags = 0;
00093 long loadpos = 0;
00094 long defpos = 0;
00095 char slask[100];
00096 char value[256];
00097 GetForm() -> getvalue("num",slask,100);
00098 long num = atol(slask);
00099 GetForm() -> getvalue("onum",slask,100);
00100 long onum = atol(slask);
00101 db::Mob mob(GetDatabase(),num);
00102
00103 if (num != onum && mob.num)
00104 {
00105 m_error = true;
00106 }
00107 else
00108 {
00109
00110 GetForm() -> EnableRaw( true );
00111 mob.num = num;
00112 GetForm() -> getvalue("alias",mob.alias,255);
00113 GetForm() -> getvalue("name",mob.name,255);
00114 GetForm() -> getvalue("dpd",mob.default_pos_description,255);
00115 GetForm() -> getvalue("descr",mob.description,255);
00116 GetForm() -> getvalue("longdescr",mob.long_description,255);
00117
00118 GetForm() -> getfirst(slask,100,value,256);
00119 while (*slask)
00120 {
00121 if (!strcmp(slask,"mobflags"))
00122 mobflags |= atol(value);
00123 if (!strcmp(slask,"loadpos"))
00124 loadpos |= atol(value);
00125 if (!strcmp(slask,"defpos"))
00126 defpos |= atol(value);
00127
00128 GetForm() -> getnext(slask,100,value,256);
00129 }
00130 sprintf(mob.mobflags,"%ld",mobflags);
00131 GetForm() -> getvalue("prof",mob.proficiencysphere,255);
00132 GetForm() -> getvalue("alignment",slask,100);
00133 mob.alignment = atol(slask);
00134 GetForm() -> getvalue("race",slask,100);
00135 mob.race = atol(slask);
00136 GetForm() -> getvalue("classtype",slask,100);
00137 mob.classtype = atol(slask);
00138 GetForm() -> getvalue("level",slask,100);
00139 mob.level = atol(slask);
00140
00141 GetForm() -> getvalue("thaco",slask,100);
00142 mob.thaco = atol(slask);
00143 GetForm() -> getvalue("ac",slask,100);
00144 mob.ac = atol(slask);
00145 GetForm() -> getvalue("minhits",slask,100);
00146 mob.minhits = atol(slask);
00147 GetForm() -> getvalue("numofdice",slask,100);
00148 mob.numofdice = atol(slask);
00149 GetForm() -> getvalue("dicetype",slask,100);
00150 mob.dicetype = atol(slask);
00151 GetForm() -> getvalue("copper",slask,100);
00152 mob.copper = atol(slask);
00153 GetForm() -> getvalue("exp",slask,100);
00154 mob.experience = atol(slask);
00155 sprintf(mob.loadpos, "%ld", loadpos);
00156 sprintf(mob.defaultpos, "%ld", defpos);
00157 GetForm() -> getvalue("sex",slask,100);
00158 mob.sex = atol(slask);
00159
00160 mob.save();
00161 m_edit = num;
00162 }
00163 }
00164 }
00165 }
00166
00167
00168 void MobForm::Select(const string &)
00169 {
00170 }
00171
00172
00173 void MobForm::List()
00174 {
00175 }
00176
00177
00178 void MobForm::Display(long)
00179 {
00180 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00181 Database *db = GetDatabase();
00182 Query q(db);
00183 long zonesize = 0;
00184 char sql[200];
00185
00186 zonesize = EditingZone();
00187
00188 if (!m_edit)
00189 web -> DisplayStartAntalForm();
00190
00191 if (m_error)
00192 {
00193 printf("<h3>New Mob# is already taken</h3>");
00194 }
00195
00196 {
00197 if (m_edit)
00198 sprintf(sql,"select * from mob where num=%ld",m_edit);
00199 else
00200 {
00201 if (GetRace() || GetClass())
00202 {
00203 char slask[100];
00204
00205 sprintf(sql,"select * from mob");
00206 strcpy(slask," where");
00207 if (GetRace())
00208 {
00209 sprintf(sql + strlen(sql),"%s race=%ld",slask,GetRace());
00210 strcpy(slask," and");
00211 }
00212 if (GetClass())
00213 {
00214 sprintf(sql + strlen(sql),"%s classtype=%ld",slask,GetClass());
00215 strcpy(slask," and");
00216 }
00217 if (GetZone())
00218 {
00219 sprintf(sql + strlen(sql),"%s num>=%ld and num<%ld",
00220 slask,
00221 GetZone() * 100,GetZone() * 100 + zonesize);
00222 strcpy(slask," and");
00223 }
00224 strcat(sql," order by num");
00225 }
00226 else
00227 if (GetZone())
00228 {
00229 sprintf(sql,"select * from mob where num>=%ld and num<%ld order by num",
00230 GetZone() * 100,GetZone() * 100 + zonesize);
00231 }
00232 else
00233 {
00234 sprintf(sql,"select * from mob where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00235 }
00236 }
00237 q.get_result(sql);
00238 char header[100];
00239
00240 if (m_edit)
00241 sprintf(header," Editing Mob#%ld",m_edit);
00242 else
00243 sprintf(header," Mobs (%ld mobs displayed)",q.num_rows());
00244 Table tbl("#000000", 3, header);
00245 printf("<tr bgcolor=#ffffff>");
00246 printf("<th align=left> Mob | Vnum</th>");
00247 printf("<th align=left> Race</th>");
00248 printf("<th align=left> Class</th>");
00249 printf("</tr>");
00250
00251 while (q.fetch_row())
00252 {
00253 db::Mob mob(db,&q);
00254
00255 printf("<tr bgcolor=#808080>");
00256 printf("<td bgcolor=#808080>");
00257 ShowMob(mob,true);
00258 printf("</td>");
00259 printf("<td> %s </td>",htmlcolor(m_race[mob.race] -> name));
00260 printf("<td> %s </td>",htmlcolor(m_class[mob.classtype] -> name));
00261 printf("</tr>");
00262 }
00263 q.free_result();
00264 }
00265 printf("<br>");
00266
00267 if (m_edit)
00268 {
00269 db::Mob mob(db,m_edit);
00270
00271
00272 {
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 sprintf(sql,"select * from zone_m where mobvnum=%ld",mob.num);
00285 q.get_result(sql);
00286 if (q.num_rows())
00287 {
00288 Table tbl("#000000", 3, " Zone references to this Mob");
00289 printf("<tr bgcolor=#ffffff>");
00290 printf("<th>Zone</th>");
00291 printf("<th>Room</th>");
00292 printf("<th>Max</th>");
00293 printf("</tr>");
00294 while (q.fetch_row())
00295 {
00296 db::Zone_m x(db,&q);
00297 db::Zone zone(db,x.zone);
00298 db::Room room(db,x.roomvnum);
00299 printf("<tr bgcolor=#808080>");
00300
00301 ShowZone(zone,true,true);
00302
00303 ShowRoom(room,true,true);
00304 printf("<td align=right> %ld </td>",x.max);
00305 printf("</tr>");
00306 }
00307 }
00308 if (q.num_rows())
00309 {
00310 printf("<br>");
00311 }
00312 q.free_result();
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 sprintf(sql,"select * from shop where shopkeeper=%ld",mob.num);
00324 q.get_result(sql);
00325 if (q.num_rows())
00326 {
00327 Table tbl("#000000", 3, " Shopkeeper");
00328 printf("<tr bgcolor=#ffffff>");
00329 printf("<th>Zone</th>");
00330 printf("<th>Room</th>");
00331 printf("</tr>");
00332 while (q.fetch_row())
00333 {
00334 db::Shop shop(db,&q);
00335 db::Room room(db,shop.num);
00336 db::Zone zone(db,room.zone);
00337 printf("<tr bgcolor=#808080>");
00338
00339 ShowZone(zone,true,true);
00340
00341 ShowRoom(room,true,true);
00342 printf("</tr>");
00343 }
00344 }
00345 if (q.num_rows())
00346 {
00347 printf("<br>");
00348 }
00349 q.free_result();
00350 }
00351
00352
00353 {
00354 Table tbl("#000000", 3);
00355 long mobflags = asciiconvert(mob.mobflags);
00356 long loadpos = asciiconvert(mob.loadpos);
00357 long defpos = asciiconvert(mob.defaultpos);
00358
00359 printf("<form action=%s method=post>",GetCgiName().c_str());
00360 printf("<input type=hidden name=onum value=%ld>",mob.num);
00361
00362 inputnum("Vnum", "num", mob.num);
00363 inputstr("Alias","alias",40,mob.alias);
00364 inputstr("MobName","name",60,mob.name,true);
00365 textarea("Default Pos Description","dpd",mob.default_pos_description,true);
00366 textarea("Description","descr",mob.description,true);
00367 textarea("Long Description","longdescr",mob.long_description,true);
00368 inputbit(q,"MobFlags","mobflags","select num,name from mob_action order by name",mobflags,4);
00369
00370 printf("<tr bgcolor=#ffffc0>");
00371 printf("<td>Proficiencies</td>");
00372 printf("<td><input type=text size=20 name=prof value=\"%s\">",mob.proficiencysphere);
00373 printf(" (Class specific)");
00374 printf("</td>");
00375 printf("</tr>");
00376
00377
00378 inputnum("Alignment", "alignment", mob.alignment);
00379 inputselect(q,"Race","race","select num,alias from race where num>0 order by alias",mob.race);
00380 inputselect(q,"ClassType","classtype","select num,alias from classes where num>0 order by alias",mob.classtype);
00381 inputnum("Level", "level", mob.level);
00382 inputnum("Thaco", "thaco", mob.thaco);
00383 inputnum("AC", "ac", mob.ac);
00384 inputnum("MinHits", "minhits", mob.minhits);
00385 inputnum("NumOfDice", "numofdice", mob.numofdice);
00386 inputnum("DiceType", "dicetype", mob.dicetype);
00387 inputnum("Copper", "copper", mob.copper);
00388 inputnum("Experience", "exp", mob.experience);
00389 inputbit(q,"LoadPos","loadpos","select num,name from mob_pos order by name",loadpos,4);
00390 inputbit(q,"DefaultPos","defpos","select num,name from mob_pos order by name",defpos,4);
00391 inputselect(q,"Sex","sex","select num,name from mob_sex order by num",mob.sex);
00392 inputsubmit(" Save ");
00393
00394 printf("</form>");
00395 }
00396 printf("<br>");
00397 }
00398 }
00399
00400
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433