ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/plugins.C
(Generate patch)

Comparing deliantra/server/server/plugins.C (file contents):
Revision 1.14 by root, Thu Sep 14 21:16:12 2006 UTC vs.
Revision 1.38 by root, Sun Dec 31 18:10:41 2006 UTC

1
2/*
3 * static char *rcsid_plugins_c =
4 * "$Id: plugins.C,v 1.14 2006/09/14 21:16:12 root Exp $";
5 */
6
7/*****************************************************************************/ 1/*****************************************************************************/
8
9/* CrossFire, A Multiplayer game for X-windows */ 2/* CrossFire, A Multiplayer game for X-windows */
10
11/* */ 3/* */
12
13/* Copyright (C) 2000 Mark Wedel */ 4/* Copyright (C) 2000 Mark Wedel */
14
15/* Copyright (C) 1992 Frank Tore Johansen */ 5/* Copyright (C) 1992 Frank Tore Johansen */
16
17/* */ 6/* */
18
19/* This program is free software; you can redistribute it and/or modify */ 7/* This program is free software; you can redistribute it and/or modify */
20
21/* it under the terms of the GNU General Public License as published by */ 8/* it under the terms of the GNU General Public License as published by */
22
23/* the Free Software Foundation; either version 2 of the License, or */ 9/* the Free Software Foundation; either version 2 of the License, or */
24
25/* (at your option) any later version. */ 10/* (at your option) any later version. */
26
27/* */ 11/* */
28
29/* This program is distributed in the hope that it will be useful, */ 12/* This program is distributed in the hope that it will be useful, */
30
31/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
32
33/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
34
35/* GNU General Public License for more details. */ 15/* GNU General Public License for more details. */
36
37/* */ 16/* */
38
39/* You should have received a copy of the GNU General Public License */ 17/* You should have received a copy of the GNU General Public License */
40
41/* along with this program; if not, write to the Free Software */ 18/* along with this program; if not, write to the Free Software */
42
43/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 19/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
44
45/* */ 20/* */
46
47/*****************************************************************************/ 21/*****************************************************************************/
48
49/* This is the server-side plugin management part. */ 22/* This is the server-side plugin management part. */
50
51/*****************************************************************************/ 23/*****************************************************************************/
52
53/* Original code by Yann Chachkoff (yann.chachkoff@mailandnews.com). */ 24/* Original code by Yann Chachkoff (yann.chachkoff@mailandnews.com). */
54
55/* Special thanks to: */ 25/* Special thanks to: */
56
57/* David Delbecq (david.delbecq@mailandnews.com); */ 26/* David Delbecq (david.delbecq@mailandnews.com); */
58
59/* Joris Bontje (jbontje@suespammers.org); */ 27/* Joris Bontje (jbontje@suespammers.org); */
60
61/* Philip Currlin (?); */ 28/* Philip Currlin (?); */
62
63/*****************************************************************************/ 29/*****************************************************************************/
64
65/*****************************************************************************/ 30/*****************************************************************************/
66
67/* First, the headers. We only include plugin.h, because all other includes */ 31/* First, the headers. We only include plugin.h, because all other includes */
68
69/* are done into it, and plugproto.h (which is used only by this file). */ 32/* are done into it, and plugproto.h (which is used only by this file). */
70
71/*****************************************************************************/ 33/*****************************************************************************/
34
72#include <plugin.h> 35#include <plugin.h>
73 36
74#ifndef __CEXTRACT__ 37#ifndef __CEXTRACT__
75# include <sproto.h> 38# include <sproto.h>
76#endif 39#endif
79 42
80static const hook_entry plug_hooks[NR_OF_HOOKS] = { 43static const hook_entry plug_hooks[NR_OF_HOOKS] = {
81 {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"}, 44 {cfapi_system_register_global_event, 1, "cfapi_system_register_global_event"},
82 {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"}, 45 {cfapi_system_unregister_global_event, 3, "cfapi_system_unregister_global_event"},
83 {cfapi_system_check_path, 4, "cfapi_system_check_path"}, 46 {cfapi_system_check_path, 4, "cfapi_system_check_path"},
84 {cfapi_system_re_cmp, 5, "cfapi_system_re_cmp"}, 47 {NULL, 5, "cfapi_system_re_cmp"},
85 {cfapi_system_strdup_local, 6, "cfapi_system_strdup_local"}, 48 {cfapi_system_strdup, 6, "cfapi_system_strdup"},
86 {cfapi_system_directory, 7, "cfapi_system_directory"}, 49 {cfapi_system_directory, 7, "cfapi_system_directory"},
87 {cfapi_system_find_animation, 8, "cfapi_system_find_animation"}, 50 {cfapi_system_find_animation, 8, "cfapi_system_find_animation"},
88 {cfapi_object_clean_object, 9, "cfapi_object_clean_object"}, 51 {cfapi_object_clean_object, 9, "cfapi_object_clean_object"},
89 {cfapi_object_on_same_map, 10, "cfapi_object_on_same_map"}, 52 {cfapi_object_on_same_map, 10, "cfapi_object_on_same_map"},
90 {cfapi_object_get_key, 11, "cfapi_object_get_key"}, 53 {cfapi_object_get_key, 11, "cfapi_object_get_key"},
158 121
159/* NEW PLUGIN STUFF STARTS HERE */ 122/* NEW PLUGIN STUFF STARTS HERE */
160 123
161/*****************************************************************************/ 124/*****************************************************************************/
162 125
163#ifdef WIN32
164static const char *
165plugins_dlerror (void)
166{
167 static char buf[256];
168 DWORD err;
169 char *p;
170
171 err = GetLastError ();
172 if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, buf, sizeof (buf), NULL) == 0)
173 snprintf (buf, sizeof (buf), "error %lu", err);
174 p = strchr (buf, '\0');
175 while (p > buf && (p[-1] == '\r' || p[-1] == '\n'))
176 p--;
177 *p = '\0';
178 return buf;
179}
180#endif /* WIN32 */
181
182/** 126/**
183 * Notify clients about a changed object. 127 * Notify clients about a changed object.
184 * 128 *
185 * @param op the object that has changed 129 * @param op the object that has changed
186 */ 130 */
187static void 131static void
188send_changed_object (object *op) 132send_changed_object (object *op)
189{ 133{
190 object *tmp; 134 object *tmp;
191 player *pl;
192 135
193 if (op->env != NULL) 136 if (op->env)
194 { 137 {
195 tmp = is_player_inv (op->env); 138 tmp = op->in_player ();
139
196 if (!tmp) 140 if (!tmp)
197 { 141 {
198 for (pl = first_player; pl; pl = pl->next) 142 for_all_players (pl)
199 if (pl->ob->container == op->env) 143 if (pl->ob->container == op->env)
144 {
145 tmp = pl->ob;
200 break; 146 break;
201 if (pl) 147 }
202 tmp = pl->ob;
203 else
204 tmp = NULL;
205 } 148 }
149
206 if (tmp) 150 if (tmp)
207 esrv_send_item (tmp, op); 151 esrv_send_item (tmp, op);
208 } 152 }
209 else 153 else
210 { 154 {
222 */ 166 */
223static void 167static void
224send_removed_object (object *op) 168send_removed_object (object *op)
225{ 169{
226 object *tmp; 170 object *tmp;
227 player *pl;
228 171
229 if (op->env == NULL) 172 if (op->env == NULL)
230 { 173 {
231 /* no action necessary: remove_ob() notifies the client */ 174 /* no action necessary: remove_ob() notifies the client */
232 return; 175 return;
233 } 176 }
234 177
235 tmp = is_player_inv (op->env); 178 tmp = op->in_player ();
236 if (!tmp) 179 if (!tmp)
237 { 180 {
238 for (pl = first_player; pl; pl = pl->next) 181 for_all_players (pl)
239 if (pl->ob->container == op->env) 182 if (pl->ob->container == op->env)
183 {
184 tmp = pl->ob;
240 break; 185 break;
241 if (pl) 186 }
242 tmp = pl->ob;
243 else
244 tmp = NULL;
245 } 187 }
188
246 if (tmp) 189 if (tmp)
247 esrv_del_item (tmp->contr, op->count); 190 esrv_del_item (tmp->contr, op->count);
248} 191}
249 192
250extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr); 193extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr);
538 *type = CFAPI_INT; 481 *type = CFAPI_INT;
539 return &rv; 482 return &rv;
540} 483}
541 484
542void * 485void *
543cfapi_system_strdup_local (int *type, ...) 486cfapi_system_strdup (int *type, ...)
544{ 487{
545 va_list args; 488 va_list args;
546 char *txt; 489 char *txt;
547 490
548 va_start (args, type); 491 va_start (args, type);
549 txt = va_arg (args, char *); 492 txt = va_arg (args, char *);
550 493
551 va_end (args); 494 va_end (args);
552 *type = CFAPI_STRING; 495 *type = CFAPI_STRING;
553 return strdup_local (txt); 496 return strdup (txt);
554} 497}
555 498
556void * 499void *
557cfapi_system_register_global_event (int *type, ...) 500cfapi_system_register_global_event (int *type, ...)
558{ 501{
612 *type = CFAPI_INT; 555 *type = CFAPI_INT;
613 return &rv; 556 return &rv;
614} 557}
615 558
616void * 559void *
617cfapi_system_re_cmp (int *type, ...)
618{
619 va_list args;
620 char *rv;
621 const char *str;
622 const char *regexp;
623
624 va_start (args, type);
625
626 str = va_arg (args, char *);
627 regexp = va_arg (args, char *);
628
629 rv = (char *) re_cmp (str, regexp);
630
631 va_end (args);
632 *type = CFAPI_STRING;
633 return rv;
634}
635
636void *
637cfapi_system_directory (int *type, ...) 560cfapi_system_directory (int *type, ...)
638{ 561{
639 va_list args; 562 va_list args;
640 int dirtype; 563 int dirtype;
641 564
686/* MAP RELATED HOOKS */ 609/* MAP RELATED HOOKS */
687 610
688void * 611void *
689cfapi_map_get_map (int *type, ...) 612cfapi_map_get_map (int *type, ...)
690{ 613{
614 abort ();
615}
616
617void *
618cfapi_map_has_been_loaded (int *type, ...)
619{
620 abort ();
621}
622
623void *
624cfapi_map_create_path (int *type, ...)
625{
626 abort ();
627}
628
629void *
630cfapi_map_get_map_property (int *type, ...)
631{
632 abort ();
633}
634
635void *
636cfapi_map_set_map_property (int *type, ...)
637{
638 abort ();
639}
640
641void *
642cfapi_map_out_of_map (int *type, ...)
643{
644 abort ();
645}
646
647void *
648cfapi_map_update_position (int *type, ...)
649{
691 va_list args; 650 va_list args;
692 mapstruct *rv; 651 maptile *map;
693 int ctype;
694 int x, y; 652 int x, y;
695 sint16 nx, ny;
696 char *name;
697 mapstruct *m;
698 653
699 va_start (args, type); 654 va_start (args, type);
700 655
701 ctype = va_arg (args, int);
702
703 switch (ctype)
704 {
705 case 0:
706 x = va_arg (args, int);
707 y = va_arg (args, int);
708
709 rv = get_empty_map (x, y);
710 break;
711
712 case 1:
713 name = va_arg (args, char *);
714 x = va_arg (args, int);
715
716 rv = ready_map_name (name, x);
717 break;
718
719 case 2:
720 m = va_arg (args, mapstruct *);
721 nx = va_arg (args, int);
722 ny = va_arg (args, int);
723
724 rv = get_map_from_coord (m, &nx, &ny);
725 break;
726
727 case 3:
728 rv = first_map;
729 break;
730
731 default:
732 *type = CFAPI_NONE;
733 va_end (args);
734 return NULL;
735 break;
736 }
737 va_end (args);
738 *type = CFAPI_PMAP;
739 return rv;
740}
741
742void *
743cfapi_map_has_been_loaded (int *type, ...)
744{
745 va_list args;
746 mapstruct *map;
747 char *string;
748
749 va_start (args, type);
750 string = va_arg (args, char *);
751
752 map = has_been_loaded (string);
753 va_end (args);
754 *type = CFAPI_PMAP;
755 return map;
756}
757
758void *
759cfapi_map_create_path (int *type, ...)
760{
761 va_list args;
762 int ctype;
763 const char *str;
764 char *rv;
765
766 va_start (args, type);
767
768 ctype = va_arg (args, int);
769 str = va_arg (args, char *);
770
771 *type = CFAPI_STRING;
772
773 switch (ctype)
774 {
775 case 0:
776 rv = (char *) create_pathname (str);
777 break;
778
779 case 1:
780 rv = (char *) create_overlay_pathname (str);
781 break;
782
783 /*case 2:
784 rv = create_items_path(str);
785 break; */
786
787 default:
788 rv = NULL;
789 *type = CFAPI_NONE;
790 break;
791 }
792 va_end (args);
793 return rv;
794}
795
796void *
797cfapi_map_get_map_property (int *type, ...)
798{
799 va_list args;
800 int x, y;
801 sint16 nx, ny;
802 mapstruct *map;
803 mapstruct *newmap;
804 static int rv;
805 int property;
806 char *buf;
807
808 va_start (args, type);
809
810 property = va_arg (args, int);
811
812 switch (property)
813 {
814 case CFAPI_MAP_PROP_FLAGS:
815 map = va_arg (args, mapstruct *);
816 newmap = va_arg (args, mapstruct *);
817 x = va_arg (args, int);
818 y = va_arg (args, int);
819 nx = va_arg (args, int);
820 ny = va_arg (args, int);
821
822 rv = get_map_flags (map, &newmap, x, y, &nx, &ny);
823 va_end (args);
824 *type = CFAPI_INT;
825 return &rv;
826 break;
827
828 case CFAPI_MAP_PROP_DIFFICULTY:
829 map = va_arg (args, mapstruct *);
830
831 rv = calculate_difficulty (map);
832 va_end (args);
833 *type = CFAPI_INT;
834 return &rv;
835 break;
836
837 case CFAPI_MAP_PROP_PATH:
838 map = va_arg (args, mapstruct *);
839
840 buf = map->path;
841 *type = CFAPI_STRING;
842 va_end (args);
843 return buf;
844 break;
845
846 case CFAPI_MAP_PROP_TMPNAME:
847 map = va_arg (args, mapstruct *);
848
849 buf = map->tmpname;
850 *type = CFAPI_STRING;
851 va_end (args);
852 return buf;
853 break;
854
855 case CFAPI_MAP_PROP_NAME:
856 map = va_arg (args, mapstruct *);
857
858 buf = map->name;
859 *type = CFAPI_STRING;
860 va_end (args);
861 return buf;
862 break;
863
864 case CFAPI_MAP_PROP_RESET_TIME:
865 map = va_arg (args, mapstruct *);
866
867 rv = map->reset_time;
868 *type = CFAPI_INT;
869 va_end (args);
870 return &rv;
871 break;
872
873 case CFAPI_MAP_PROP_RESET_TIMEOUT:
874 map = va_arg (args, mapstruct *);
875
876 rv = map->reset_timeout;
877 *type = CFAPI_INT;
878 va_end (args);
879 return &rv;
880 break;
881
882 case CFAPI_MAP_PROP_PLAYERS:
883 map = va_arg (args, mapstruct *);
884
885 rv = map->players;
886 *type = CFAPI_INT;
887 va_end (args);
888 return &rv;
889 break;
890
891 case CFAPI_MAP_PROP_DARKNESS:
892 map = va_arg (args, mapstruct *);
893
894 rv = map->darkness;
895 *type = CFAPI_INT;
896 va_end (args);
897 return &rv;
898 break;
899
900 case CFAPI_MAP_PROP_WIDTH:
901 map = va_arg (args, mapstruct *);
902
903 rv = map->width;
904 *type = CFAPI_INT;
905 va_end (args);
906 return &rv;
907 break;
908
909 case CFAPI_MAP_PROP_HEIGHT:
910 map = va_arg (args, mapstruct *);
911
912 rv = map->height;
913 *type = CFAPI_INT;
914 va_end (args);
915 return &rv;
916 break;
917
918 case CFAPI_MAP_PROP_ENTER_X:
919 map = va_arg (args, mapstruct *);
920
921 rv = map->enter_x;
922 *type = CFAPI_INT;
923 va_end (args);
924 return &rv;
925 break;
926
927 case CFAPI_MAP_PROP_ENTER_Y:
928 map = va_arg (args, mapstruct *);
929
930 rv = map->enter_y;
931 *type = CFAPI_INT;
932 va_end (args);
933 return &rv;
934 break;
935
936 case CFAPI_MAP_PROP_TEMPERATURE:
937 map = va_arg (args, mapstruct *);
938
939 rv = map->temp;
940 *type = CFAPI_INT;
941 va_end (args);
942 return &rv;
943 break;
944
945 case CFAPI_MAP_PROP_PRESSURE:
946 map = va_arg (args, mapstruct *);
947
948 rv = map->pressure;
949 *type = CFAPI_INT;
950 va_end (args);
951 return &rv;
952 break;
953
954 case CFAPI_MAP_PROP_HUMIDITY:
955 map = va_arg (args, mapstruct *);
956
957 rv = map->humid;
958 *type = CFAPI_INT;
959 va_end (args);
960 return &rv;
961 break;
962
963 case CFAPI_MAP_PROP_WINDSPEED:
964 map = va_arg (args, mapstruct *);
965
966 rv = map->windspeed;
967 *type = CFAPI_INT;
968 va_end (args);
969 return &rv;
970 break;
971
972 case CFAPI_MAP_PROP_WINDDIR:
973 map = va_arg (args, mapstruct *);
974
975 rv = map->winddir;
976 *type = CFAPI_INT;
977 va_end (args);
978 return &rv;
979 break;
980
981 case CFAPI_MAP_PROP_SKY:
982 map = va_arg (args, mapstruct *);
983
984 rv = map->sky;
985 *type = CFAPI_INT;
986 va_end (args);
987 return &rv;
988 break;
989
990 case CFAPI_MAP_PROP_WPARTX:
991 map = va_arg (args, mapstruct *);
992
993 rv = map->wpartx;
994 *type = CFAPI_INT;
995 va_end (args);
996 return &rv;
997 break;
998
999 case CFAPI_MAP_PROP_WPARTY:
1000 map = va_arg (args, mapstruct *);
1001
1002 rv = map->wparty;
1003 *type = CFAPI_INT;
1004 va_end (args);
1005 return &rv;
1006 break;
1007
1008 case CFAPI_MAP_PROP_MESSAGE:
1009 map = va_arg (args, mapstruct *);
1010
1011 buf = map->msg;
1012 *type = CFAPI_STRING;
1013 va_end (args);
1014 return buf;
1015 break;
1016
1017 case CFAPI_MAP_PROP_NEXT:
1018 map = va_arg (args, mapstruct *);
1019
1020 *type = CFAPI_PMAP;
1021 va_end (args);
1022 return map->next;
1023 break;
1024
1025 case CFAPI_MAP_PROP_REGION:
1026 map = va_arg (args, mapstruct *);
1027
1028 *type = CFAPI_PREGION;
1029 va_end (args);
1030 return get_region_by_map (map);
1031 break;
1032
1033 default:
1034 *type = CFAPI_NONE;
1035 va_end (args);
1036 return NULL;
1037 break;
1038 }
1039}
1040
1041void *
1042cfapi_map_set_map_property (int *type, ...)
1043{
1044 va_list args;
1045 static int rv;
1046 mapstruct *map;
1047 int val;
1048 int property;
1049
1050 va_start (args, type);
1051
1052 property = va_arg (args, int);
1053
1054 switch (property)
1055 {
1056 case CFAPI_MAP_PROP_LIGHT:
1057 map = va_arg (args, mapstruct *);
1058 val = va_arg (args, int);
1059
1060 rv = change_map_light (map, val);
1061 *type = CFAPI_INT;
1062 va_end (args);
1063 return &rv;
1064 break;
1065
1066 case CFAPI_MAP_PROP_RESET_TIME:
1067 map = va_arg (args, mapstruct *);
1068
1069 *type = CFAPI_NONE;
1070 va_end (args);
1071 return NULL;
1072 break;
1073
1074 default:
1075 *type = CFAPI_NONE;
1076 va_end (args);
1077 return NULL;
1078 break;
1079 }
1080}
1081void *
1082cfapi_map_out_of_map (int *type, ...)
1083{
1084 va_list args;
1085 static int rv;
1086 mapstruct *map;
1087 int x, y;
1088
1089 va_start (args, type);
1090 map = va_arg (args, mapstruct *); 656 map = va_arg (args, maptile *);
1091 x = va_arg (args, int); 657 x = va_arg (args, int);
1092 y = va_arg (args, int); 658 y = va_arg (args, int);
1093 659
1094 rv = out_of_map (map, x, y); 660 map->at (x, y).flags_ &= ~P_UPTODATE;
1095 va_end (args);
1096 *type = CFAPI_INT;
1097 return &rv;
1098}
1099 661
1100void *
1101cfapi_map_update_position (int *type, ...)
1102{
1103 va_list args;
1104 mapstruct *map;
1105 int x, y;
1106
1107 va_start (args, type);
1108
1109 map = va_arg (args, mapstruct *);
1110 x = va_arg (args, int);
1111 y = va_arg (args, int);
1112
1113 update_position (map, x, y);
1114 va_end (args); 662 va_end (args);
1115 *type = CFAPI_NONE; 663 *type = CFAPI_NONE;
1116 return NULL; 664 return NULL;
1117} 665}
1118 666
1119void * 667void *
1120cfapi_map_delete_map (int *type, ...) 668cfapi_map_delete_map (int *type, ...)
1121{ 669{
1122 va_list args; 670 abort ();
1123 mapstruct *map;
1124
1125 va_start (args, type);
1126
1127 map = va_arg (args, mapstruct *);
1128
1129 delete_map (map);
1130
1131 va_end (args);
1132 *type = CFAPI_NONE;
1133 return NULL;
1134} 671}
1135 672
1136void * 673void *
1137cfapi_map_message (int *type, ...) 674cfapi_map_message (int *type, ...)
1138{ 675{
1139 va_list args; 676 va_list args;
1140 mapstruct *map; 677 maptile *map;
1141 char *string; 678 char *string;
1142 int color; 679 int color;
1143 680
1144 va_start (args, type); 681 va_start (args, type);
1145 map = va_arg (args, mapstruct *); 682 map = va_arg (args, maptile *);
1146 string = va_arg (args, char *); 683 string = va_arg (args, char *);
1147 color = va_arg (args, int); 684 color = va_arg (args, int);
1148 685
1149 va_end (args); 686 va_end (args);
1150 687
1155 692
1156void * 693void *
1157cfapi_map_get_object_at (int *type, ...) 694cfapi_map_get_object_at (int *type, ...)
1158{ 695{
1159 va_list args; 696 va_list args;
1160 mapstruct *map; 697 maptile *map;
1161 int x, y; 698 int x, y;
1162 object *rv; 699 object *rv;
1163 700
1164 va_start (args, type); 701 va_start (args, type);
1165 map = va_arg (args, mapstruct *); 702 map = va_arg (args, maptile *);
1166 x = va_arg (args, int); 703 x = va_arg (args, int);
1167 y = va_arg (args, int); 704 y = va_arg (args, int);
1168 705
1169 va_end (args); 706 va_end (args);
1170 707
1171 rv = get_map_ob (map, x, y); 708 rv = GET_MAP_OB (map, x, y);
1172 *type = CFAPI_POBJECT; 709 *type = CFAPI_POBJECT;
1173 return rv; 710 return rv;
1174} 711}
1175 712
1176void * 713void *
1177cfapi_map_get_flags (int *type, ...) 714cfapi_map_get_flags (int *type, ...)
1178{ 715{
1179 va_list args; 716 va_list args;
1180 sint16 x, y; 717 sint16 x, y;
1181 sint16 *nx, *ny; 718 sint16 *nx, *ny;
1182 static mapstruct *map; 719 static maptile *map;
1183 mapstruct **newmap; 720 maptile **newmap;
1184 static int rv; 721 static int rv;
1185 722
1186 va_start (args, type); 723 va_start (args, type);
1187 724
1188 map = va_arg (args, mapstruct *); 725 map = va_arg (args, maptile *);
1189 newmap = va_arg (args, mapstruct **); 726 newmap = va_arg (args, maptile **);
1190 x = va_arg (args, int); 727 x = va_arg (args, int);
1191 y = va_arg (args, int); 728 y = va_arg (args, int);
1192 729
1193 nx = va_arg (args, sint16 *); 730 nx = va_arg (args, sint16 *);
1194 ny = va_arg (args, sint16 *); 731 ny = va_arg (args, sint16 *);
1204cfapi_map_present_arch_by_name (int *type, ...) 741cfapi_map_present_arch_by_name (int *type, ...)
1205{ 742{
1206 va_list args; 743 va_list args;
1207 object *rv; 744 object *rv;
1208 int x, y; 745 int x, y;
1209 mapstruct *map; 746 maptile *map;
1210 char *msg; 747 char *msg;
1211 748
1212 va_start (args, type); 749 va_start (args, type);
1213 750
1214 msg = va_arg (args, char *); 751 msg = va_arg (args, char *);
1215 map = va_arg (args, mapstruct *); 752 map = va_arg (args, maptile *);
1216 x = va_arg (args, int); 753 x = va_arg (args, int);
1217 y = va_arg (args, int); 754 y = va_arg (args, int);
1218 755
1219 va_end (args); 756 va_end (args);
1220 757
1713 rv = &op->stats.exp; 1250 rv = &op->stats.exp;
1714 *type = CFAPI_LONG; 1251 *type = CFAPI_LONG;
1715 break; 1252 break;
1716 1253
1717 case CFAPI_OBJECT_PROP_OWNER: 1254 case CFAPI_OBJECT_PROP_OWNER:
1718 rv = get_owner (op); 1255 rv = op->owner;
1719 *type = CFAPI_POBJECT; 1256 *type = CFAPI_POBJECT;
1720 break; 1257 break;
1721 1258
1722 case CFAPI_OBJECT_PROP_PRESENT: 1259 case CFAPI_OBJECT_PROP_PRESENT:
1723 { 1260 {
1765 case CFAPI_OBJECT_PROP_MERGEABLE: 1302 case CFAPI_OBJECT_PROP_MERGEABLE:
1766 { 1303 {
1767 object *op2; 1304 object *op2;
1768 op2 = va_arg (args, object *); 1305 op2 = va_arg (args, object *);
1769 1306
1770 ri = CAN_MERGE (op, op2); 1307 ri = object::can_merge_slow (op, op2);
1771 rv = &ri; 1308 rv = &ri;
1772 } 1309 }
1773 *type = CFAPI_INT; 1310 *type = CFAPI_INT;
1774 break; 1311 break;
1775 1312
1922 rv = &ri; 1459 rv = &ri;
1923 *type = CFAPI_INT; 1460 *type = CFAPI_INT;
1924 break; 1461 break;
1925 1462
1926 case CFAPI_PLAYER_PROP_IP: 1463 case CFAPI_PLAYER_PROP_IP:
1927 rv = op->contr->socket.host; 1464 rv = op->contr->ns->host;
1928 *type = CFAPI_STRING; 1465 *type = CFAPI_STRING;
1929 break; 1466 break;
1930 1467
1931 case CFAPI_PLAYER_PROP_MARKED_ITEM: 1468 case CFAPI_PLAYER_PROP_MARKED_ITEM:
1932 rv = find_marked_object (op); 1469 rv = find_marked_object (op);
2042 if (op->nrof > (uint32) iarg) 1579 if (op->nrof > (uint32) iarg)
2043 decrease_ob_nr (op, op->nrof - iarg); 1580 decrease_ob_nr (op, op->nrof - iarg);
2044 else if (op->nrof < (uint32) iarg) 1581 else if (op->nrof < (uint32) iarg)
2045 { 1582 {
2046 object *tmp; 1583 object *tmp;
2047 player *pl;
2048 1584
2049 op->nrof = iarg; 1585 op->nrof = iarg;
2050 if (op->env != NULL) 1586 if (op->env != NULL)
2051 { 1587 {
2052 tmp = is_player_inv (op->env); 1588 tmp = op->in_player ();
2053 if (!tmp) 1589 if (!tmp)
2054 { 1590 {
2055 for (pl = first_player; pl; pl = pl->next) 1591 for_all_players (pl)
2056 if (pl->ob->container == op->env) 1592 if (pl->ob->container == op->env)
1593 {
1594 tmp = pl->ob;
2057 break; 1595 break;
2058 if (pl)
2059 tmp = pl->ob;
2060 else 1596 }
2061 tmp = NULL;
2062 } 1597 }
2063 else 1598 else
2064 { 1599 {
2065 sum_weight (tmp); 1600 sum_weight (tmp);
2066 fix_player (tmp); 1601 tmp->update_stats ();
2067 } 1602 }
2068 if (tmp) 1603 if (tmp)
2069 esrv_send_item (tmp, op); 1604 esrv_send_item (tmp, op);
2070 } 1605 }
2071 else 1606 else
2203 iarg = va_arg (args, int); 1738 iarg = va_arg (args, int);
2204 1739
2205 if (op->weight != iarg) 1740 if (op->weight != iarg)
2206 { 1741 {
2207 object *tmp; 1742 object *tmp;
2208 player *pl;
2209 1743
2210 op->weight = iarg; 1744 op->weight = iarg;
2211 if (op->env != NULL) 1745 if (op->env != NULL)
2212 { 1746 {
2213 tmp = is_player_inv (op->env); 1747 tmp = op->in_player ();
2214 if (!tmp) 1748 if (!tmp)
2215 { 1749 {
2216 for (pl = first_player; pl; pl = pl->next) 1750 for_all_players (pl)
2217 if (pl->ob->container == op->env) 1751 if (pl->ob->container == op->env)
1752 {
1753 tmp = pl->ob;
2218 break; 1754 break;
2219 if (pl)
2220 tmp = pl->ob;
2221 else 1755 }
2222 tmp = NULL;
2223 } 1756 }
2224 else 1757 else
2225 { 1758 {
2226 sum_weight (tmp); 1759 sum_weight (tmp);
2227 fix_player (tmp); 1760 tmp->update_stats ();
2228 } 1761 }
2229 if (tmp) 1762 if (tmp)
2230 esrv_send_item (tmp, op); 1763 esrv_send_item (tmp, op);
2231 } 1764 }
2232 else 1765 else
2347 break; 1880 break;
2348 1881
2349 case CFAPI_OBJECT_PROP_OWNER: 1882 case CFAPI_OBJECT_PROP_OWNER:
2350 oparg = va_arg (args, object *); 1883 oparg = va_arg (args, object *);
2351 1884
2352 set_owner (op, oparg); 1885 op->set_owner (oparg);
2353 break; 1886 break;
2354 1887
2355 case CFAPI_OBJECT_PROP_CHEATER: 1888 case CFAPI_OBJECT_PROP_CHEATER:
2356 set_cheat (op); 1889 set_cheat (op);
2357 break; 1890 break;
2492 if (op->contr) 2025 if (op->contr)
2493 { 2026 {
2494 oparg = va_arg (args, object *); 2027 oparg = va_arg (args, object *);
2495 2028
2496 op->contr->mark = oparg; 2029 op->contr->mark = oparg;
2497 if (oparg)
2498 op->contr->mark_count = oparg->count;
2499 } 2030 }
2500 break; 2031 break;
2501 2032
2502 case CFAPI_PLAYER_PROP_PARTY: 2033 case CFAPI_PLAYER_PROP_PARTY:
2503 if (op->contr) 2034 if (op->contr)
2594} 2125}
2595 2126
2596void * 2127void *
2597cfapi_object_drain (int *type, ...) 2128cfapi_object_drain (int *type, ...)
2598{ 2129{
2599 va_list args; 2130 abort ();
2131}
2600 2132
2133void *
2134cfapi_object_fix (int *type, ...)
2135{
2136 va_list args;
2601 object *op; 2137 object *op;
2602 int ds;
2603 2138
2604 va_start (args, type); 2139 va_start (args, type);
2605 2140
2606 op = va_arg (args, object *); 2141 op = va_arg (args, object *);
2607 ds = va_arg (args, int);
2608 2142
2609 va_end (args); 2143 va_end (args);
2610 2144
2611 drain_specific_stat (op, ds); 2145 op->update_stats ();
2612
2613 *type = CFAPI_NONE;
2614 return NULL;
2615}
2616
2617void *
2618cfapi_object_fix (int *type, ...)
2619{
2620 va_list args;
2621 object *op;
2622
2623 va_start (args, type);
2624
2625 op = va_arg (args, object *);
2626
2627 va_end (args);
2628
2629 fix_player (op);
2630 2146
2631 *type = CFAPI_NONE; 2147 *type = CFAPI_NONE;
2632 return NULL; 2148 return NULL;
2633} 2149}
2634 2150
2682 op = va_arg (args, object *); 2198 op = va_arg (args, object *);
2683 2199
2684 va_end (args); 2200 va_end (args);
2685 2201
2686 send_removed_object (op); 2202 send_removed_object (op);
2687 remove_ob (op); 2203 op->remove ();
2688 *type = CFAPI_NONE; 2204 *type = CFAPI_NONE;
2689 return NULL; 2205 return NULL;
2690} 2206}
2691 2207
2692void * 2208void *
2699 2215
2700 op = va_arg (args, object *); 2216 op = va_arg (args, object *);
2701 2217
2702 va_end (args); 2218 va_end (args);
2703 2219
2704 free_object (op); 2220 op->destroy ();
2705 2221
2706 *type = CFAPI_NONE; 2222 *type = CFAPI_NONE;
2707 return NULL; 2223 return NULL;
2708} 2224}
2709 2225
2726 *type = CFAPI_POBJECT; 2242 *type = CFAPI_POBJECT;
2727 return object_create_clone (op); 2243 return object_create_clone (op);
2728 } 2244 }
2729 else 2245 else
2730 { 2246 {
2731 object *tmp; 2247 object *tmp = op->clone ();
2732
2733 tmp = get_object ();
2734 copy_object (op, tmp);
2735 *type = CFAPI_POBJECT; 2248 *type = CFAPI_POBJECT;
2736 return tmp; 2249 return tmp;
2737 } 2250 }
2738} 2251}
2739void * 2252void *
2775 break; 2288 break;
2776 2289
2777 case 3: 2290 case 3:
2778 op = va_arg (args, object *); 2291 op = va_arg (args, object *);
2779 2292
2780 rv = is_player_inv (op); 2293 rv = op->in_player ();
2781 break; 2294 break;
2782 2295
2783 default: 2296 default:
2784 rv = NULL; 2297 rv = NULL;
2785 *type = CFAPI_NONE; 2298 *type = CFAPI_NONE;
2803 *type = CFAPI_POBJECT; 2316 *type = CFAPI_POBJECT;
2804 switch (ival) 2317 switch (ival)
2805 { 2318 {
2806 case 0: 2319 case 0:
2807 va_end (args); 2320 va_end (args);
2808 return get_object (); 2321 return object::create ();
2809 break; 2322 break;
2810 2323
2811 case 1: /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */ 2324 case 1: /* Named object. Nearly the old plugin behavior, but we don't add artifact suffixes */
2812 { 2325 {
2813 char *sval; 2326 char *sval;
2816 2329
2817 op = get_archetype_by_object_name (sval); 2330 op = get_archetype_by_object_name (sval);
2818 2331
2819 if (strncmp (query_name (op), ARCH_SINGULARITY, ARCH_SINGULARITY_LEN) == 0) 2332 if (strncmp (query_name (op), ARCH_SINGULARITY, ARCH_SINGULARITY_LEN) == 0)
2820 { 2333 {
2821 free_object (op); 2334 op->destroy ();
2822 /* Try with archetype names... */ 2335 /* Try with archetype names... */
2823 op = get_archetype (sval); 2336 op = get_archetype (sval);
2824 if (strncmp (query_name (op), ARCH_SINGULARITY, ARCH_SINGULARITY_LEN) == 0) 2337 if (strncmp (query_name (op), ARCH_SINGULARITY, ARCH_SINGULARITY_LEN) == 0)
2825 { 2338 {
2826 free_object (op); 2339 op->destroy ();
2827 *type = CFAPI_NONE; 2340 *type = CFAPI_NONE;
2828 va_end (args); 2341 va_end (args);
2829 return NULL; 2342 return NULL;
2830 } 2343 }
2831 } 2344 }
2845cfapi_object_insert (int *type, ...) 2358cfapi_object_insert (int *type, ...)
2846{ 2359{
2847 va_list args; 2360 va_list args;
2848 object *op; 2361 object *op;
2849 object *orig; 2362 object *orig;
2850 mapstruct *map; 2363 maptile *map;
2851 int flag, x, y; 2364 int flag, x, y;
2852 int itype; 2365 int itype;
2853 char *arch_string; 2366 char *arch_string;
2854 void *rv = NULL; 2367 void *rv = NULL;
2855 2368
2859 itype = va_arg (args, int); 2372 itype = va_arg (args, int);
2860 2373
2861 switch (itype) 2374 switch (itype)
2862 { 2375 {
2863 case 0: 2376 case 0:
2864 map = va_arg (args, mapstruct *); 2377 map = va_arg (args, maptile *);
2865 orig = va_arg (args, object *); 2378 orig = va_arg (args, object *);
2866 flag = va_arg (args, int); 2379 flag = va_arg (args, int);
2867 x = va_arg (args, int); 2380 x = va_arg (args, int);
2868 y = va_arg (args, int); 2381 y = va_arg (args, int);
2869 2382
2870 rv = insert_ob_in_map_at (op, map, orig, flag, x, y); 2383 rv = insert_ob_in_map_at (op, map, orig, flag, x, y);
2871 *type = CFAPI_POBJECT; 2384 *type = CFAPI_POBJECT;
2872 break; 2385 break;
2873 2386
2874 case 1: 2387 case 1:
2875 map = va_arg (args, mapstruct *); 2388 map = va_arg (args, maptile *);
2876 orig = va_arg (args, object *); 2389 orig = va_arg (args, object *);
2877 flag = va_arg (args, int); 2390 flag = va_arg (args, int);
2878 2391
2879 rv = insert_ob_in_map (op, map, orig, flag); 2392 rv = insert_ob_in_map (op, map, orig, flag);
2880 *type = CFAPI_POBJECT; 2393 *type = CFAPI_POBJECT;
2981} 2494}
2982 2495
2983void * 2496void *
2984cfapi_object_clear (int *type, ...) 2497cfapi_object_clear (int *type, ...)
2985{ 2498{
2986 va_list args; 2499 abort ();
2987 object *op;
2988
2989 va_start (args, type);
2990
2991 op = va_arg (args, object *);
2992
2993 va_end (args);
2994
2995 clear_object (op);
2996 *type = CFAPI_NONE;
2997 return NULL;
2998} 2500}
2999 2501
3000void * 2502void *
3001cfapi_object_reset (int *type, ...) 2503cfapi_object_reset (int *type, ...)
3002{ 2504{
3035} 2537}
3036 2538
3037void * 2539void *
3038cfapi_object_clean_object (int *type, ...) 2540cfapi_object_clean_object (int *type, ...)
3039{ 2541{
3040 va_list args; 2542 abort ();
3041 object *op;
3042
3043 va_start (args, type);
3044 op = va_arg (args, object *);
3045
3046 clean_object (op);
3047 va_end (args);
3048 *type = CFAPI_NONE;
3049 return NULL;
3050} 2543}
3051 2544
3052void * 2545void *
3053cfapi_object_on_same_map (int *type, ...) 2546cfapi_object_on_same_map (int *type, ...)
3054{ 2547{
3266 object *op; 2759 object *op;
3267 object *originator; 2760 object *originator;
3268 int x, y, randompos, ttype; 2761 int x, y, randompos, ttype;
3269 va_list args; 2762 va_list args;
3270 static int rv = 0; 2763 static int rv = 0;
3271 mapstruct *map; 2764 maptile *map;
3272 2765
3273 va_start (args, type); 2766 va_start (args, type);
3274 op = va_arg (args, object *); 2767 op = va_arg (args, object *);
3275 ttype = va_arg (args, int); 2768 ttype = va_arg (args, int);
3276 2769
3290 break; 2783 break;
3291 2784
3292 case 1: 2785 case 1:
3293 x = va_arg (args, int); 2786 x = va_arg (args, int);
3294 y = va_arg (args, int); 2787 y = va_arg (args, int);
3295 map = va_arg (args, mapstruct *); 2788 map = va_arg (args, maptile *);
3296 2789
3297 va_end (args); 2790 va_end (args);
3298 if (x < 0 || y < 0) 2791 if (x < 0 || y < 0)
3299 { 2792 {
3300 x = map->enter_x; 2793 x = map->enter_x;
3301 y = map->enter_y; 2794 y = map->enter_y;
3302 } 2795 }
3303 2796
3304/* 2797/*
3305 originator = get_object(); 2798 originator = object::create();
3306 EXIT_PATH(originator) = add_string(map->path); 2799 EXIT_PATH(originator) = add_string(map->path);
3307 EXIT_X(originator) = x; 2800 EXIT_X(originator) = x;
3308 EXIT_Y(originator) = y; 2801 EXIT_Y(originator) = y;
3309 printf("B Transfer: X=%d, Y=%d, OP=%s\n", x, y, op->name);*/ 2802 printf("B Transfer: X=%d, Y=%d, OP=%s\n", x, y, op->name);*/
3310 /*enter_exit(op, originator); */ 2803 /*enter_exit(op, originator); */
3311 insert_ob_in_map_at (op, map, NULL, 0, x, y); 2804 insert_ob_in_map_at (op, map, NULL, 0, x, y);
3312 /*printf("A Transfer: X=%d, Y=%d, MAP=%s\n", x, y, op->map->name); 2805 /*printf("A Transfer: X=%d, Y=%d, MAP=%s\n", x, y, op->map->name);
3313 free_object(originator); 2806 originator->destroy ();
3314 */ 2807 */
3315 *type = CFAPI_INT; 2808 *type = CFAPI_INT;
3316 return &rv; 2809 return &rv;
3317 break; 2810 break;
3318 2811
3391 drop (author, op); 2884 drop (author, op);
3392 2885
3393 if (author->type == PLAYER) 2886 if (author->type == PLAYER)
3394 { 2887 {
3395 author->contr->count = 0; 2888 author->contr->count = 0;
3396 author->contr->socket.update_look = 1; 2889 author->contr->ns->floorbox_update ();
3397 } 2890 }
3398 2891
3399 *type = CFAPI_NONE; 2892 *type = CFAPI_NONE;
3400 return NULL; 2893 return NULL;
3401} 2894}
3482} 2975}
3483 2976
3484void * 2977void *
3485cfapi_object_teleport (int *type, ...) 2978cfapi_object_teleport (int *type, ...)
3486{ 2979{
3487 mapstruct *map; 2980 maptile *map;
3488 int x, y; 2981 int x, y;
3489 object *who; 2982 object *who;
3490 static int result; 2983 static int result;
3491 va_list args; 2984 va_list args;
3492 2985
3493 va_start (args, type); 2986 va_start (args, type);
3494 who = va_arg (args, object *); 2987 who = va_arg (args, object *);
3495 map = va_arg (args, mapstruct *); 2988 map = va_arg (args, maptile *);
3496 x = va_arg (args, int); 2989 x = va_arg (args, int);
3497 y = va_arg (args, int); 2990 y = va_arg (args, int);
3498 2991
3499 if (!out_of_map (map, x, y)) 2992 if (!out_of_map (map, x, y))
3500 { 2993 {
3507 result = 1; 3000 result = 1;
3508 return &result; 3001 return &result;
3509 } 3002 }
3510 3003
3511 send_removed_object (who); 3004 send_removed_object (who);
3512 remove_ob (who); 3005 who->remove ();
3513 3006
3514 for (tmp = who; tmp != NULL; tmp = tmp->more) 3007 for (tmp = who; tmp != NULL; tmp = tmp->more)
3515 tmp->x = x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x), 3008 tmp->x = x + freearr_x[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x),
3516 tmp->y = y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); 3009 tmp->y = y + freearr_y[k] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
3517 3010
3634 3127
3635 case CFAPI_PARTY_PROP_PLAYER: 3128 case CFAPI_PARTY_PROP_PLAYER:
3636 *type = CFAPI_PPLAYER; 3129 *type = CFAPI_PPLAYER;
3637 obarg = va_arg (args, object *); 3130 obarg = va_arg (args, object *);
3638 3131
3639 pl = (obarg ? obarg->contr : first_player); 3132 pl = (obarg ? (player *)obarg->contr : first_player);
3640 rv = NULL; 3133 rv = NULL;
3641 for (; pl != NULL; pl = pl->next) 3134 for (; pl != NULL; pl = pl->next)
3642 if (pl->ob->contr->party == party) 3135 if (pl->ob->contr->party == party)
3643 { 3136 {
3644 rv = (void *) pl; 3137 rv = (void *) pl;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines