Crossfire Server, Branch 1.12  R12190
duplicator.c
Go to the documentation of this file.
00001 /*
00002     CrossFire, A Multiplayer game for X-windows
00003 
00004     Copyright (C) 2008 Crossfire Development Team
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 
00020     The authors can be reached via e-mail at crossfire-devel@real-time.com
00021 */
00022 
00028 #include <global.h>
00029 #include <ob_methods.h>
00030 #include <ob_types.h>
00031 #include <sounds.h>
00032 #include <sproto.h>
00033 
00034 static method_ret duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state);
00035 
00039 void init_type_duplicator(void) {
00040     register_trigger(DUPLICATOR, duplicator_type_trigger);
00041 }
00042 
00054 void move_duplicator(object *op) {
00055     object *tmp;
00056 
00057     if (!op->other_arch) {
00058         LOG(llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap");
00059         return;
00060     }
00061 
00062     if (op->above == NULL)
00063         return;
00064     for (tmp = op->above; tmp != NULL; tmp = tmp->above) {
00065         if (strcmp(op->other_arch->name, tmp->arch->name) == 0) {
00066             if (op->level <= 0) {
00067                 remove_ob(tmp);
00068                 free_object(tmp);
00069             } else {
00070                 uint64 new_nrof = (uint64)tmp->nrof*op->level;
00071 
00072                 if (new_nrof >= 1UL<<31)
00073                     new_nrof = 1UL<<31;
00074                 tmp->nrof = new_nrof;
00075             }
00076             break;
00077         }
00078     }
00079 }
00080 
00089 static method_ret duplicator_type_trigger(ob_methods *context, object *op, object *cause, int state) {
00090     move_duplicator(op);
00091     return METHOD_OK;
00092 }