/* $Csoft: phare.c,v 1.19 2004/01/03 04:25:01 vedge Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 CubeSoft Communications, Inc. * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "phare.h" enum { PHARE_MAXHP = 5000, PHARE_MAXMP = 100 }; const struct version phare_ver = { "agar cave phare", 1, 0 }; const struct object_ops phare_ops = { phare_init, NULL, /* reinit */ NULL, /* destroy */ phare_load, phare_save, NULL /* edit */ }; struct phare * phare_new(void *parent, const char *name) { struct phare *pha; pha = Malloc(sizeof(struct phare)); phare_init(pha, name); object_attach(parent, pha); return (pha); } void phare_init(void *obj, const char *name) { struct phare *phare = obj; object_init(phare, "phare", name, &phare_ops); object_wire_gfx(phare, "/cave/phare"); phare->maxhp = phare->hp = PHARE_MAXHP; phare->maxmp = phare->mp = PHARE_MAXMP; } int phare_load(void *p, struct netbuf *buf) { struct phare *phare = p; if (version_read(buf, &phare_ver, NULL) == -1) { return (-1); } phare->maxhp = (int)read_uint32(buf); phare->hp = (int)read_uint32(buf); phare->maxmp = (int)read_uint32(buf); phare->mp = (int)read_uint32(buf); return (0); } int phare_save(void *p, struct netbuf *buf) { struct phare *phare = p; version_write(buf, &phare_ver); write_uint32(buf, (Uint32)phare->maxhp); write_uint32(buf, (Uint32)phare->hp); write_uint32(buf, (Uint32)phare->maxmp); write_uint32(buf, (Uint32)phare->mp); return (0); }