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

Comparing deliantra/server/server/pets.C (file contents):
Revision 1.4 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.5 by root, Tue Sep 12 18:15:35 2006 UTC

1 1
2/* 2/*
3 * static char *rcsid_pets_c = 3 * static char *rcsid_pets_c =
4 * "$Id: pets.C,v 1.4 2006/09/10 15:59:57 root Exp $"; 4 * "$Id: pets.C,v 1.5 2006/09/12 18:15:35 root Exp $";
5 */ 5 */
6 6
7/* 7/*
8 CrossFire, A Multiplayer game for X-windows 8 CrossFire, A Multiplayer game for X-windows
9 9
887 /* This should not happen */ 887 /* This should not happen */
888 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); 888 LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n");
889 return NULL; 889 return NULL;
890} 890}
891 891
892
893
894int 892int
895summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) 893summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg)
896{ 894{
897 sint16 x, y, nrof = 1, i; 895 sint16 x, y, nrof = 1, i;
898 archetype *summon_arch; 896 archetype *summon_arch;
899 int ndir; 897 int ndir;
900 898
901 if (spell_ob->other_arch) 899 if (spell_ob->other_arch)
902 {
903 summon_arch = spell_ob->other_arch; 900 summon_arch = spell_ob->other_arch;
904 }
905 else if (spell_ob->randomitems) 901 else if (spell_ob->randomitems)
906 { 902 {
907 int level = caster_level (caster, spell_ob); 903 int level = caster_level (caster, spell_ob);
908 treasure *tr, *lasttr = NULL;; 904 treasure *tr, *lasttr = NULL;
909 905
906 shstr_cmp sparam (stringarg);
907
910 /* In old code, this was a very convuluted for statement, 908 /* In old code, this was a very convoluted for statement,
911 * with all the checks in the 'for' portion itself. Much 909 * with all the checks in the 'for' portion itself. Much
912 * more readable to break some of the conditions out. 910 * more readable to break some of the conditions out.
913 */ 911 */
914 for (tr = spell_ob->randomitems->items; tr; tr = tr->next) 912 for (tr = spell_ob->randomitems->items; tr; tr = tr->next)
915 { 913 {
916 if (level < tr->magic) 914 if (level < tr->magic)
917 break; 915 break;
916
918 lasttr = tr; 917 lasttr = tr;
918
919 if (stringarg && !strcmp (tr->item->name, stringarg)) 919 if (stringarg && tr->item->name == sparam)
920 break; 920 break;
921
921 if (tr->next == NULL || tr->next->item == NULL) 922 if (!tr->next || !tr->next->item)
922 break; 923 break;
923 } 924 }
925
924 if (!lasttr) 926 if (!lasttr)
925 { 927 {
926 LOG (llevError, "Treasurelist %s did not generate a valid entry in summon_object\n", &spell_ob->randomitems->name); 928 LOG (llevError, "Treasurelist %s did not generate a valid entry in summon_object\n", &spell_ob->randomitems->name);
927 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); 929 new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters.");
928 return 0; 930 return 0;
929 } 931 }
932
930 summon_arch = lasttr->item; 933 summon_arch = lasttr->item;
931 nrof = lasttr->nrof; 934 nrof = lasttr->nrof;
932
933 } 935 }
934 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) 936 else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON"))
935 { 937 {
936 object *god = find_god (determine_god (op)), *mon, *owner; 938 object *god = find_god (determine_god (op)), *mon, *owner;
937 int summon_level, tries; 939 int summon_level, tries;
938 940
939 if (!god && ((owner = get_owner (op)) != NULL)) 941 if (!god && ((owner = get_owner (op)) != NULL))
940 {
941 god = find_god (determine_god (owner)); 942 god = find_god (determine_god (owner));
942 } 943
943 /* If we can't find a god, can't get what monster to summon */ 944 /* If we can't find a god, can't get what monster to summon */
944 if (!god) 945 if (!god)
945 return 0; 946 return 0;
946 947
947 if (!god->race) 948 if (!god->race)
948 { 949 {
949 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); 950 new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name);
950 return 0; 951 return 0;
951 } 952 }
953
952 /* the summon level */ 954 /* the summon level */
953 summon_level = caster_level (caster, spell_ob); 955 summon_level = caster_level (caster, spell_ob);
954 if (summon_level == 0) 956 if (summon_level == 0)
955 summon_level = 1; 957 summon_level = 1;
958
956 tries = 0; 959 tries = 0;
957 do 960 do
958 { 961 {
959 mon = choose_cult_monster (op, god, summon_level); 962 mon = choose_cult_monster (op, god, summon_level);
960 if (!mon) 963 if (!mon)
961 { 964 {
962 new_draw_info_format (NDI_UNIQUE, 0, op, "%s fails to send anything.", &god->name); 965 new_draw_info_format (NDI_UNIQUE, 0, op, "%s fails to send anything.", &god->name);
963 return 0; 966 return 0;
964 } 967 }
968
965 ndir = dir; 969 ndir = dir;
970
966 if (!ndir) 971 if (!ndir)
967 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 972 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
973
968 if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 974 if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
969 { 975 {
970 ndir = -1; 976 ndir = -1;
971 if (++tries == 5) 977 if (++tries == 5)
972 { 978 {
974 return 0; 980 return 0;
975 } 981 }
976 } 982 }
977 } 983 }
978 while (ndir == -1); 984 while (ndir == -1);
985
979 if (mon->level > (summon_level / 2)) 986 if (mon->level > (summon_level / 2))
980 nrof = random_roll (1, 2, op, PREFER_HIGH); 987 nrof = random_roll (1, 2, op, PREFER_HIGH);
981 else 988 else
982 nrof = die_roll (2, 2, op, PREFER_HIGH); 989 nrof = die_roll (2, 2, op, PREFER_HIGH);
990
983 summon_arch = mon->arch; 991 summon_arch = mon->arch;
984 } 992 }
985 else 993 else
986 {
987 summon_arch = NULL; 994 summon_arch = 0;
988 }
989 995
990 if (spell_ob->stats.dam) 996 if (spell_ob->stats.dam)
991 nrof += spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob); 997 nrof += spell_ob->stats.dam + SP_level_dam_adjust (caster, spell_ob);
992 998
993 if (!summon_arch) 999 if (!summon_arch)
1034 set_owner (tmp, op); 1040 set_owner (tmp, op);
1035 set_spell_skill (op, caster, spell_ob, tmp); 1041 set_spell_skill (op, caster, spell_ob, tmp);
1036 tmp->enemy = op->enemy; 1042 tmp->enemy = op->enemy;
1037 tmp->type = 0; 1043 tmp->type = 0;
1038 CLEAR_FLAG (tmp, FLAG_SLEEP); 1044 CLEAR_FLAG (tmp, FLAG_SLEEP);
1045
1039 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) 1046 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY))
1040 { 1047 {
1041 /* If this is not set, we make it friendly */ 1048 /* If this is not set, we make it friendly */
1042 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) 1049 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER))
1043 { 1050 {
1044 SET_FLAG (tmp, FLAG_FRIENDLY); 1051 SET_FLAG (tmp, FLAG_FRIENDLY);
1045 add_friendly_object (tmp); 1052 add_friendly_object (tmp);
1046 tmp->stats.exp = 0; 1053 tmp->stats.exp = 0;
1054
1047 if (spell_ob->attack_movement) 1055 if (spell_ob->attack_movement)
1048 tmp->attack_movement = spell_ob->attack_movement; 1056 tmp->attack_movement = spell_ob->attack_movement;
1057
1049 if (get_owner (op)) 1058 if (get_owner (op))
1050 set_owner (tmp, get_owner (op)); 1059 set_owner (tmp, get_owner (op));
1051 } 1060 }
1052 } 1061 }
1053 } 1062 }
1063
1054 if (tmp->speed > MIN_ACTIVE_SPEED) 1064 if (tmp->speed > MIN_ACTIVE_SPEED)
1055 tmp->speed_left = -1; 1065 tmp->speed_left = -1;
1056 } 1066 }
1067
1057 if (head == NULL) 1068 if (head == NULL)
1058 head = tmp; 1069 head = tmp;
1059 else 1070 else
1060 { 1071 {
1061 tmp->head = head; 1072 tmp->head = head;
1062 prev->more = tmp; 1073 prev->more = tmp;
1063 } 1074 }
1075
1064 prev = tmp; 1076 prev = tmp;
1065 tmp->x = op->x + x + tmp->arch->clone.x; 1077 tmp->x = op->x + x + tmp->arch->clone.x;
1066 tmp->y = op->y + y + tmp->arch->clone.y; 1078 tmp->y = op->y + y + tmp->arch->clone.y;
1067 tmp->map = op->map; 1079 tmp->map = op->map;
1068 } 1080 }
1081
1069 head->direction = freedir[ndir]; 1082 head->direction = freedir[ndir];
1070 head->stats.exp = 0; 1083 head->stats.exp = 0;
1071 head = insert_ob_in_map (head, head->map, op, 0); 1084 head = insert_ob_in_map (head, head->map, op, 0);
1085
1072 if (head && head->randomitems) 1086 if (head && head->randomitems)
1073 { 1087 {
1074 object *tmp; 1088 object *tmp;
1075 1089
1076 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1090 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1077 for (tmp = head->inv; tmp; tmp = tmp->below) 1091 for (tmp = head->inv; tmp; tmp = tmp->below)
1078 if (!tmp->nrof) 1092 if (!tmp->nrof)
1079 SET_FLAG (tmp, FLAG_NO_DROP); 1093 SET_FLAG (tmp, FLAG_NO_DROP);
1080 } 1094 }
1081 } /* for i < nrof */ 1095 } /* for i < nrof */
1096
1082 return 1; 1097 return 1;
1083} 1098}
1084 1099
1085/* recursively look through the owner property of objects until the real owner 1100/* recursively look through the owner property of objects until the real owner
1086is found */ 1101is found */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines