00001 00007 /* 00008 Copyright (C) 2000 Jeffrey S. Freedman 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 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 #ifdef HAVE_CONFIG_H 00026 # include <config.h> 00027 #endif 00028 00029 #include "virstone.h" 00030 #include <iostream> 00031 #include "databuf.h" 00032 #include "gamewin.h" 00033 #include "ucsched.h" 00034 #include "Gump_manager.h" 00035 00036 using std::ostream; 00037 00038 00039 /* 00040 * Set position from IREG data. 00041 */ 00042 00043 void Virtue_stone_object::set_pos 00044 ( 00045 unsigned char tilex, // Tx within superchunk. 00046 unsigned char tiley, // Ty within superchunk, 00047 unsigned char schunk, // Superchunk 00048 unsigned char lift 00049 ) 00050 { 00051 pos.tx = (schunk%12)*c_tiles_per_schunk + tilex; 00052 pos.ty = (schunk/12)*c_tiles_per_schunk + tiley; 00053 pos.tz = lift; 00054 } 00055 00056 /* 00057 * Write out container and its members. 00058 */ 00059 00060 void Virtue_stone_object::write_ireg 00061 ( 00062 DataSource *out 00063 ) 00064 { 00065 unsigned char buf[13]; // 13-byte entry + length-byte. 00066 buf[0] = 12; 00067 unsigned char *ptr = &buf[1]; // To avoid confusion about offsets. 00068 write_common_ireg(ptr); // Fill in bytes 1-4. 00069 ptr += 4; 00070 // Write tilex, tiley. 00071 *ptr++ = pos.tx%c_tiles_per_schunk; 00072 *ptr++ = pos.ty%c_tiles_per_schunk; 00073 // Get superchunk index. 00074 int sx = pos.tx/c_tiles_per_schunk, 00075 sy = pos.ty/c_tiles_per_schunk; 00076 *ptr++ = sy*12 + sx; // Write superchunk #. 00077 *ptr++ = pos.tz; // Finally, lift in entry[7].??Guess+++ 00078 *ptr++ = 0; // Entry[8] unknown. 00079 *ptr++ = (get_lift()&15)<<4; // Stone's lift in entry[9]. 00080 *ptr++ = 0; // Entry[10]. Unknown. 00081 *ptr++ = 0; // Entry[11]. Unknown. 00082 out->write((char*)buf, sizeof(buf)); 00083 } 00084 00085 00086 // Get size of IREG. Returns -1 if can't write to buffer 00087 int Virtue_stone_object::get_ireg_size() 00088 { 00089 // These shouldn't ever happen, but you never know 00090 if (gumpman->find_gump(this) || Usecode_script::find(this)) 00091 return -1; 00092 00093 return 13; 00094 }