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

Comparing deliantra/server/server/main.C (file contents):
Revision 1.45 by root, Thu Dec 14 21:46:34 2006 UTC vs.
Revision 1.46 by root, Fri Dec 15 04:21:29 2006 UTC

950 950
951 enter_map (op, newmap, op->x, op->y); 951 enter_map (op, newmap, op->x, op->y);
952 } 952 }
953} 953}
954 954
955/*
956 * process_active_maps(): Works like process_events(), but it only
957 * processes maps which a player is on.
958 *
959 */
960
961#if 0 // dead code, schmorp
962void
963process_active_maps ()
964{
965 for (maptile *map = first_map; map != NULL; map = map->next)
966 if (map->in_memory == MAP_IN_MEMORY)
967 if (players_on_map (map, TRUE))
968 process_events (map);
969}
970#endif
971
972/* process_players1 and process_players2 do all the player related stuff. 955/* process_players1 and process_players2 do all the player related stuff.
973 * I moved it out of process events and process_map. This was to some 956 * I moved it out of process events and process_map. This was to some
974 * extent for debugging as well as to get a better idea of the time used 957 * extent for debugging as well as to get a better idea of the time used
975 * by the various functions. process_players1() does the processing before 958 * by the various functions. process_players1() does the processing before
976 * objects have been updated, process_players2() does the processing that 959 * objects have been updated, process_players2() does the processing that
977 * is needed after the players have been updated. 960 * is needed after the players have been updated.
978 */ 961 */
979 962static void
980void
981process_players1 (maptile *map) 963process_players1 ()
982{ 964{
983 int flag; 965 int flag;
984 player *pl, *plnext;
985
986 /* Basically, we keep looping until all the players have done their actions. */ 966 /* Basically, we keep looping until all the players have done their actions. */
987 for (flag = 1; flag != 0;) 967 for (flag = 1; flag != 0;)
988 { 968 {
989 flag = 0; 969 flag = 0;
990 for (pl = first_player; pl != NULL; pl = plnext) 970 for (player *plnext, *pl = first_player; pl; pl = plnext)
991 { 971 {
992 plnext = pl->next; /* In case a player exits the game in handle_player() */ 972 plnext = pl->next; /* In case a player exits the game in handle_player() */
993 973
994 if (pl->ob == NULL) 974 if (!pl->ob)
995 continue;
996
997 if (map != NULL && pl->ob->map != map)
998 continue; 975 continue;
999 976
1000 if (pl->ob->speed_left > 0) 977 if (pl->ob->speed_left > 0)
1001 { 978 {
1002 if (handle_newcs_player (pl->ob)) 979 if (handle_newcs_player (pl->ob))
1016 /* check for ST_PLAYING state so that we don't try to save off when 993 /* check for ST_PLAYING state so that we don't try to save off when
1017 * the player is logging in. 994 * the player is logging in.
1018 */ 995 */
1019 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING) 996 if ((pl->last_save_tick + AUTOSAVE) < (uint32) pticks && pl->state == ST_PLAYING)
1020 { 997 {
1021 /* Don't save the player on unholy ground. Instead, increase the
1022 * tick time so it will be about 10 seconds before we try and save
1023 * again.
1024 */
1025// if (get_map_flags(pl->ob->map, NULL, pl->ob->x, pl->ob->y, NULL, NULL) & P_NO_CLERIC) {
1026// pl->last_save_tick += 100;
1027// } else {
1028 save_player (pl->ob, 1); 998 save_player (pl->ob, 1);
1029 pl->last_save_tick = pticks; 999 pl->last_save_tick = pticks;
1030// }
1031 } 1000 }
1032#endif 1001#endif
1033 } /* end of for loop for all the players */ 1002 } /* end of for loop for all the players */
1034 } /* for flag */ 1003 } /* for flag */
1004
1035 for (pl = first_player; pl != NULL; pl = pl->next) 1005 for (player *pl = first_player; pl; pl = pl->next)
1036 { 1006 {
1037 if (map != NULL && (pl->ob == NULL || pl->ob->map != map))
1038 continue;
1039 if (settings.casting_time == TRUE) 1007 if (settings.casting_time)
1040 { 1008 {
1041 if (pl->ob->casting_time > 0) 1009 if (pl->ob->casting_time > 0)
1042 { 1010 {
1043 pl->ob->casting_time--; 1011 pl->ob->casting_time--;
1044 pl->ob->start_holding = 1; 1012 pl->ob->start_holding = 1;
1045 } 1013 }
1014
1046 /* set spell_state so we can update the range in stats field */ 1015 /* set spell_state so we can update the range in stats field */
1047 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1)) 1016 if ((pl->ob->casting_time == 0) && (pl->ob->start_holding == 1))
1048 {
1049 pl->ob->start_holding = 0; 1017 pl->ob->start_holding = 0;
1050 } 1018 }
1051 } 1019
1052 do_some_living (pl->ob); 1020 do_some_living (pl->ob);
1053 /* draw(pl->ob); *//* updated in socket code */
1054 } 1021 }
1055} 1022}
1056 1023
1057void 1024static void
1058process_players2 (maptile *map) 1025process_players2 ()
1059{ 1026{
1060 player *pl;
1061
1062 /* Then check if any players should use weapon-speed instead of speed */ 1027 /* Then check if any players should use weapon-speed instead of speed */
1063 for (pl = first_player; pl != NULL; pl = pl->next) 1028 for (player *pl = first_player; pl; pl = pl->next)
1064 { 1029 {
1065 if (map != NULL)
1066 {
1067 if (pl->ob == NULL || QUERY_FLAG (pl->ob, FLAG_REMOVED))
1068 continue;
1069 else if (pl->loading != NULL) /* Player is blocked */
1070 pl->ob->speed_left -= pl->ob->speed;
1071 if (pl->ob->map != map)
1072 continue;
1073 }
1074
1075 /* The code that did weapon_sp handling here was out of place - 1030 /* The code that did weapon_sp handling here was out of place -
1076 * this isn't called until after the player has finished there 1031 * this isn't called until after the player has finished there
1077 * actions, and is thus out of place. All we do here is bounds 1032 * actions, and is thus out of place. All we do here is bounds
1078 * checking. 1033 * checking.
1079 */ 1034 */
1085 /* This needs to be here - if the player is running, we need to 1040 /* This needs to be here - if the player is running, we need to
1086 * clear this each tick, but new commands are not being received 1041 * clear this each tick, but new commands are not being received
1087 * so execute_newserver_command() is never called 1042 * so execute_newserver_command() is never called
1088 */ 1043 */
1089 pl->has_hit = 0; 1044 pl->has_hit = 0;
1090
1091 } 1045 }
1092 else if (pl->ob->speed_left > pl->ob->speed) 1046 else if (pl->ob->speed_left > pl->ob->speed)
1093 pl->ob->speed_left = pl->ob->speed; 1047 pl->ob->speed_left = pl->ob->speed;
1094 } 1048 }
1095} 1049}
1096 1050
1097void 1051void
1098process_events (maptile *map) 1052process_events ()
1099{ 1053{
1100 object *op; 1054 object *op;
1101 1055
1102 static object *marker; 1056 static object *marker;
1103 1057
1104 if (!marker) 1058 if (!marker)
1105 marker = object::create (); 1059 marker = object::create ();
1106 1060
1107 process_players1 (map); 1061 process_players1 ();
1108 1062
1109 marker->active_next = active_objects; 1063 marker->active_next = active_objects;
1110 1064
1111 if (marker->active_next) 1065 if (marker->active_next)
1112 marker->active_next->active_prev = marker; 1066 marker->active_next->active_prev = marker;
1163 continue; 1117 continue;
1164 } 1118 }
1165 1119
1166 if (!op->speed) 1120 if (!op->speed)
1167 { 1121 {
1168 LOG (llevError, "BUG: process_events(): Object %s has no speed, " "but is on active list\n", &op->arch->name); 1122 LOG (llevError, "BUG: process_events(): Object %s has no speed, "
1123 "but is on active list\n", &op->arch->name);
1169 update_ob_speed (op); 1124 update_ob_speed (op);
1170 continue; 1125 continue;
1171 } 1126 }
1172 1127
1173 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP && map == NULL) 1128 if (op->map == NULL && op->env == NULL && op->name && op->type != MAP)
1174 { 1129 {
1175 LOG (llevError, "BUG: process_events(): Object without map or " "inventory is on active list: %s (%d)\n", &op->name, op->count); 1130 LOG (llevError, "BUG: process_events(): Object without map or "
1131 "inventory is on active list: %s (%d)\n", &op->name, op->count);
1176 op->speed = 0; 1132 op->speed = 0;
1177 update_ob_speed (op); 1133 update_ob_speed (op);
1178 continue; 1134 continue;
1179 } 1135 }
1180 1136
1181 if (map != NULL && op->map != map)
1182 continue;
1183
1184 /* Animate the object. Bug of feature that andim_speed 1137 /* Animate the object. Bug or feature that anim_speed
1185 * is based on ticks, and not the creatures speed? 1138 * is based on ticks, and not the creatures speed?
1186 */ 1139 */
1187 if (op->anim_speed && op->last_anim >= op->anim_speed) 1140 if (op->anim_speed && op->last_anim >= op->anim_speed)
1188 { 1141 {
1189 if ((op->type == PLAYER) || (op->type == MONSTER)) 1142 if ((op->type == PLAYER) || (op->type == MONSTER))
1230 if (marker->active_prev != NULL) 1183 if (marker->active_prev != NULL)
1231 marker->active_prev->active_next = NULL; 1184 marker->active_prev->active_next = NULL;
1232 else 1185 else
1233 active_objects = NULL; 1186 active_objects = NULL;
1234 1187
1235 process_players2 (map); 1188 process_players2 ();
1236} 1189}
1237 1190
1238void 1191void
1239clean_tmp_files (void) 1192clean_tmp_files (void)
1240{ 1193{
1431 nroferrors = 0; 1384 nroferrors = 0;
1432 1385
1433 // first do the user visible stuff 1386 // first do the user visible stuff
1434 doeric_server (); 1387 doeric_server ();
1435 INVOKE_GLOBAL (CLOCK); 1388 INVOKE_GLOBAL (CLOCK);
1436 process_events (NULL); /* "do" something with objects with speed */ 1389 process_events (); /* "do" something with objects with speed */
1437 flush_sockets (); 1390 flush_sockets ();
1438 1391
1439 // then do some bookkeeping, should not really be here 1392 // then do some bookkeeping, should not really be here
1440 check_active_maps (); /* Removes unused maps after a certain timeout */ 1393 check_active_maps (); /* Removes unused maps after a certain timeout */
1441 do_specials (); /* Routines called from time to time. */ 1394 do_specials (); /* Routines called from time to time. */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines