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

WeaponForm.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 "WeaponForm.h"
00033 
00034 
00035 namespace cgi
00036 {
00037 
00038 
00039 WeaponForm::WeaponForm(Web *web)
00040 :BaseForm(web, "weaponform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 {
00044         Query q(GetDatabase());
00045         
00046         q.get_result("select * from skill");
00047         while (q.fetch_row())
00048         {
00049                 db::Skill *tmp = new db::Skill(GetDatabase(),&q);
00050                 m_skill[tmp -> num] = tmp;
00051         }
00052         q.free_result();
00053 }
00054 
00055 
00056 WeaponForm::~WeaponForm()
00057 {
00058         for (skills_t::iterator it = m_skill.begin(); it != m_skill.end(); it++)
00059         {
00060                 delete (*it).second;
00061         }
00062 }
00063 
00064 
00065 void WeaponForm::Process()
00066 {
00067         char action[200];
00068         
00069         if (GetForm() -> getvalue("weaponform",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                         long weapflags = 0;
00081                         char slask[100];
00082                         char value[256];
00083                         GetForm() -> getvalue("num",slask,100);
00084                         long num = atol(slask);
00085                         GetForm() -> getvalue("onum",slask,100);
00086                         long onum = atol(slask);
00087                         db::Weapon weap(GetDatabase(),num);
00088 
00089                         if (num != onum && weap.num)
00090                         {
00091                                 m_error = true;
00092                         }
00093                         else
00094                         {
00095 // alias, name, dpd, descr, longdescr
00096                                 GetForm() -> EnableRaw( true );
00097                                 weap.num = num;
00098                                 GetForm() -> getvalue("name",weap.name,255);
00099                                 // loop to get multiple checkbox values
00100                                 GetForm() -> getfirst(slask,100,value,256);
00101                                 while (*slask)
00102                                 {
00103                                         if (!strcmp(slask,"weapflags"))
00104                                                 weapflags |= atol(value);
00105                                         //
00106                                         GetForm() -> getnext(slask,100,value,256);
00107                                 }
00108 //                              sprintf(weap.weapflags,"%ld",weapflags);
00109                                 GetForm() -> getvalue("twohand",slask,100);
00110                                 weap.twohand = atol(slask);
00111                                 GetForm() -> getvalue("str",slask,100);
00112                                 weap.str = atol(slask);
00113                                 GetForm() -> getvalue("dam1",slask,100);
00114                                 weap.dam1 = atol(slask);
00115                                 GetForm() -> getvalue("dam2",slask,100);
00116                                 weap.dam2 = atol(slask);
00117                                 GetForm() -> getvalue("speed",slask,100);
00118                                 weap.speed = atol(slask);
00119                                 GetForm() -> getvalue("skill",slask,100);
00120                                 weap.skill = atol(slask);
00121                                 //
00122                                 weap.save();
00123 //                              m_edit = num;
00124                         }
00125                 }
00126         }
00127 }
00128 
00129 
00130 void WeaponForm::Select(const string &)
00131 {
00132 }
00133 
00134 
00135 void WeaponForm::List()
00136 {
00137 }
00138 
00139 
00140 void WeaponForm::Display(long)
00141 {
00142         WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00143         Database *db = GetDatabase();
00144         Query q(db);
00145         long zonesize = 0;
00146         char sql[200];
00147 
00148         zonesize = EditingZone();
00149 
00150         if (!m_edit)
00151                 web -> DisplayStartAntalForm();
00152 
00153         if (m_error)
00154         {
00155                 printf("<h3>New Weapon# is already taken</h3>");
00156         }
00157 
00158         {
00159                 if (m_edit)
00160                         sprintf(sql,"select * from weapon where num=%ld",m_edit);
00161                 else
00162                 {
00163                         sprintf(sql,"select * from weapon where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00164                 }
00165                 q.get_result(sql);
00166                 char header[100];
00167                 
00168                 if (m_edit)
00169                         sprintf(header,"&nbsp;Editing Weapon#%ld",m_edit);
00170                 else
00171                         sprintf(header,"&nbsp;Weapons (%ld weaps displayed)",q.num_rows());
00172                 Table tbl("#000000", 3, header);
00173                 printf("<tr bgcolor=#ffffff>");
00174                 printf("<th align=left>&nbsp;Weapon Type</th>");
00175                 printf("<th align=left>&nbsp;StrReq</th>");
00176                 printf("<th align=left>&nbsp;Damage</th>");
00177                 printf("<th align=left>&nbsp;Speed</th>");
00178                 printf("<th align=left>&nbsp;Skill</th>");
00179                 printf("</tr>");
00180 
00181                 while (q.fetch_row())
00182                 {
00183                         db::Weapon weap(db,&q);
00184                         db::Skill *tmp = m_skill[weap.skill];
00185 
00186                         printf("<tr bgcolor=#808080>");
00187                         printf("<td bgcolor=#808080>");
00188                         ShowWeapon(weap,true);
00189                         printf("</td>");
00190                         printf("<td align=right>&nbsp;%ld&nbsp;</td>",weap.str);
00191                         printf("<td align=middle>&nbsp;%ld&nbsp;D&nbsp;%ld&nbsp;</td>",weap.dam1,weap.dam2);
00192                         printf("<td align=right>&nbsp;%ld&nbsp;</td>",weap.speed);
00193                         if (tmp)
00194                                 ShowSkill(*tmp,true,true);
00195                         else
00196                                 printf("<td align=middle>-</td>");
00197                         printf("</tr>");
00198                 }
00199                 q.free_result();
00200         }
00201         printf("<br>");
00202 
00203         if (m_edit)
00204         {
00205                 db::Weapon weap(db,m_edit);
00206 
00207                 // references to this weap
00208                 {
00209                 } // end of references
00210 
00211                 // edit
00212                 {
00213                         Table tbl("#000000", 3);
00214 //                      long weapflags = asciiconvert(weap.weapflags);
00215 //                      long loadpos = asciiconvert(weap.loadpos);
00216 //                      long defpos = asciiconvert(weap.defaultpos);
00217 
00218                         printf("<form action=%s method=post>",GetCgiName().c_str());
00219                         printf("<input type=hidden name=onum value=%ld>",weap.num);
00220 
00221                         inputnum("Num","num",weap.num);
00222                         inputstr("WeaponName","name",60,weap.name,true);
00223 //                      inputbit(q,"WeaponFlags","weapflags","select num,name from weapon_action order by name",weapflags,4);
00224                         inputdie("Damage","dam",weap.dam1,weap.dam2);
00225                         inputnum("Speed","speed",weap.speed);
00226                         inputnum("TwoHanded", "twohand", weap.twohand);
00227                         inputnum("StrReq", "str", weap.str);
00228                         inputselect(q,"Skill","skill","select num,name from skill order by name",weap.skill);
00229                         inputsubmit(" Save ");
00230 
00231                         printf("</form>");
00232                 }
00233                 printf("<br>");
00234         }
00235 }
00236 
00237 
00238 } // namespace cgi
00239 
00240 
00241 

Generated for Wolfshade by doxygen 1.3.6

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