00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00029 #include <global.h>
00030 #include <ob_methods.h>
00031 #include <ob_types.h>
00032 #include <sounds.h>
00033 #include <sproto.h>
00034
00035 static method_ret transport_type_apply(ob_methods *context, object *op, object *applier, int aflags);
00036 static method_ret transport_type_process(ob_methods *context, object *op);
00037
00041 void init_type_transport(void) {
00042 register_apply(TRANSPORT, transport_type_apply);
00043 register_process(TRANSPORT, transport_type_process);
00044 }
00045
00058 static method_ret transport_type_apply(ob_methods *context, object *op, object *applier, int aflags) {
00059 object *old_transport = applier->contr->transport;
00060 object *inv;
00061 char name_op[MAX_BUF], name_old[MAX_BUF];
00062
00063
00064 if (applier->type != PLAYER)
00065 return 0;
00066
00067 query_name(op, name_op, MAX_BUF);
00068
00069
00070
00071
00072
00073 if (old_transport && old_transport != op) {
00074 query_name(old_transport, name_old, MAX_BUF);
00075 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00076 "You must exit %s before you can board %s.",
00077 "You must exit %s before you can board %s.",
00078 name_old, name_op);
00079 return 1;
00080 }
00081
00082
00083
00084
00085 if (old_transport) {
00086
00087
00088
00089 if (aflags&AP_APPLY)
00090 return 1;
00091
00092 query_name(old_transport, name_old, MAX_BUF);
00093 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY,
00094 "You disembark from %s.", "You disembark from %s.",
00095 name_old);
00096 remove_ob(applier);
00097 applier->map = old_transport->map;
00098 applier->x = old_transport->x;
00099 applier->y = old_transport->y;
00100 if (applier->contr == old_transport->contr)
00101 old_transport->contr = NULL;
00102
00103 applier->contr->transport = NULL;
00104 insert_ob_in_map(applier, applier->map, applier, 0);
00105 sum_weight(old_transport);
00106
00107
00108
00109
00110
00111 for (inv = old_transport->inv; inv; inv = inv->below)
00112 if (inv->type == PLAYER)
00113 break;
00114 if (!inv) {
00115 old_transport->face = old_transport->arch->clone.face;
00116 old_transport->animation_id = old_transport->arch->clone.animation_id;
00117 } else {
00118 old_transport->contr = inv->contr;
00119 draw_ext_info_format(NDI_UNIQUE, 0, inv, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00120 "%s has disembarked. You are now the captain of %s",
00121 "%s has disembarked. You are now the captain of %s",
00122 applier->name, name_old);
00123 }
00124 return 1;
00125 } else {
00126
00127 int pc = 0, p_limit;
00128 const char *kv;
00129 sint16 ox, oy;
00130
00131 if (aflags&AP_UNAPPLY)
00132 return 1;
00133
00134
00135 if (!transport_can_hold(op, applier, 1)) {
00136 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00137 "The %s is unable to hold your weight!",
00138 "The %s is unable to hold your weight!",
00139 name_op);
00140 return 1;
00141 }
00142
00143
00144 if (op->env == applier) {
00145 old_transport = op;
00146
00147 if (!is_in_shop(applier)) {
00148 op = drop_object(applier, op, 1);
00149 } else {
00150 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00151 "You cannot drop the %s in a shop to use it.",
00152 "You cannot drop the %s in a shop to use it.",
00153 name_old);
00154 return 1;
00155 }
00156
00157 if (!op) {
00158 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00159 "You need to drop the %s to use it.",
00160 "You need to drop the %s to use it.",
00161 name_old);
00162 return 1;
00163 }
00164 }
00165
00166
00167 for (inv = op->inv; inv; inv = inv->below)
00168 if (inv->type == PLAYER)
00169 pc++;
00170
00171 kv = get_ob_key_value(op, "passenger_limit");
00172 if (!kv)
00173 p_limit = 1;
00174 else
00175 p_limit = atoi(kv);
00176 if (pc >= p_limit) {
00177 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR,
00178 "The %s does not have space for any more people",
00179 "The %s does not have space for any more people",
00180 name_op);
00181 return 1;
00182 }
00183
00184
00185 applier->contr->transport = op;
00186
00187 if (op->contr) {
00188 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00189 "The %s's captain is currently %s",
00190 "The %s's captain is currently %s",
00191 name_op, op->contr->ob->name);
00192 } else {
00193 draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS,
00194 "You're the %s's captain",
00195 "You're the %s's captain",
00196 name_op);
00197 op->contr = applier->contr;
00198 }
00199
00200 remove_ob(applier);
00201
00202 ox = applier->x;
00203 oy = applier->y;
00204 insert_ob_in_ob(applier, op);
00205 sum_weight(op);
00206 applier->map = op->map;
00207 if (ox != op->x || oy != op->y) {
00208 esrv_map_scroll(&applier->contr->socket, (ox-op->x), (oy-op->y));
00209 }
00210 applier->contr->socket.update_look = 1;
00211 applier->contr->socket.look_position = 0;
00212 applier->x = op->x;
00213 applier->y = op->y;
00214
00215
00216 if (!pc) {
00217 const char *str;
00218
00219 str = get_ob_key_value(op, "face_full");
00220 if (str)
00221 op->face = &new_faces[find_face(str, op->face->number)];
00222 str = get_ob_key_value(op, "anim_full");
00223 if (str)
00224 op->animation_id = find_animation(str);
00225 }
00226
00227
00228 kv = get_ob_key_value(op, "weight_speed_ratio");
00229 if (kv) {
00230 int wsr = atoi(kv);
00231 float base_speed;
00232
00233 kv = get_ob_key_value(op, "base_speed");
00234 if (kv)
00235 base_speed = atof(kv);
00236 else
00237 base_speed = op->arch->clone.speed;
00238
00239 op->speed = base_speed-(base_speed*op->carrying*wsr)/(op->weight_limit*100);
00240
00241
00242 if (op->speed < 0.10)
00243 op->speed = 0.10;
00244 if (op->speed > 1.0)
00245 op->speed = 1.0;
00246 }
00247 }
00248 return 1;
00249 }
00250
00258 static method_ret transport_type_process(ob_methods *context, object *op) {
00259
00260
00261
00262
00263
00264 if (op->speed_left < 0.0) {
00265 op->speed_left += 1.0;
00266 return 1;
00267 }
00268 return 0;
00269 }