iregobjs.cc

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 1998  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 "contain.h"
00030 #include "gamewin.h"
00031 #include "gamemap.h"
00032 #include "chunks.h"
00033 #include "cheat.h"
00034 #include "databuf.h"
00035 #include "ucsched.h"
00036 #include "Gump_manager.h"
00037 
00038 using std::ostream;
00039 
00040 /*
00041  *  Paint at given spot in world.
00042  */
00043 
00044 void Ireg_game_object::paint
00045   (
00046   )
00047   {
00048   int x, y;
00049   gwin->get_shape_location(this, x, y);
00050   if (flags & (1L << Obj_flags::invisible))
00051     paint_invisible(x, y);
00052   else
00053     paint_shape(x, y);
00054   }
00055 
00056 /*
00057  *  Move to a new absolute location.  This should work even if the old
00058  *  location is invalid (cx=cy=255).
00059  */
00060 
00061 void Ireg_game_object::move
00062   (
00063   int newtx, 
00064   int newty, 
00065   int newlift
00066   )
00067   {
00068   if (owner)      // Watch for this.
00069     {
00070     owner->remove(this);
00071     set_invalid();    // So we can safely move it back.
00072     }
00073   Game_object::move(newtx, newty, newlift);
00074   }
00075 
00076 /*
00077  *  Remove an object from its container, or from the world.
00078  *  The object is deleted.
00079  */
00080 
00081 void Ireg_game_object::remove_this
00082   (
00083   int nodel     // 1 to not delete.
00084   )
00085   {
00086   if (owner)      // In a bag, box, or person.
00087     owner->remove(this);
00088   else        // In the outside world.
00089     {
00090     Map_chunk *chunk = gmap->get_chunk_safely(cx, cy);
00091     if (chunk)
00092       chunk->remove(this);
00093     }
00094   if (!nodel)
00095   {
00096     cheat.clear_this_grabbed_actor((Actor*)this); // Could be an actor
00097     gwin->delete_object(this);
00098   }
00099   }
00100 
00101 /*
00102  *  Can this be dragged?
00103  */
00104 
00105 int Ireg_game_object::is_dragable
00106   (
00107   ) const
00108   {
00109           // 0 weight means 'too heavy'.
00110   return get_info().get_weight() > 0;
00111   }
00112 
00113 /*
00114  *  Write out.
00115  */
00116 
00117 void Ireg_game_object::write_ireg
00118   (
00119   DataSource *out
00120   )
00121   {
00122   unsigned char buf[11];    // 10-byte entry + length-byte.
00123   buf[0] = 10;
00124   write_common_ireg(&buf[1]);
00125   buf[5] = (get_lift()&15)<<4;
00126   buf[6] = get_quality();
00127   Shape_info& info = get_info();
00128   if (info.has_quality_flags())
00129     {     // Store 'quality_flags'.
00130     buf[6] = get_flag((Obj_flags::invisible) != 0) +
00131       ((get_flag(Obj_flags::okay_to_take) != 0) << 3);
00132     }
00133           // Special case for 'quantity' items:
00134   else if (get_flag(Obj_flags::okay_to_take) && info.has_quantity())
00135     buf[6] |= 0x80;
00136 
00137   buf[7] = (get_flag(Obj_flags::is_temporary) != 0);
00138   out->write((char*)buf, sizeof(buf));
00139           // Write scheduled usecode.
00140   Game_map::write_scheduled(out, this); 
00141   }
00142 
00143 // Get size of IREG. Returns -1 if can't write to buffer
00144 int Ireg_game_object::get_ireg_size()
00145 {
00146   // These shouldn't ever happen, but you never know
00147   if (gumpman->find_gump(this) || Usecode_script::find(this))
00148     return -1;
00149 
00150   return 11;
00151 }

Generated on Mon Jul 9 14:42:49 2007 for ExultEngine by  doxygen 1.5.1