| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "global.h" |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
|
| 25 |
#include "ob_methods.h" |
| 26 |
#include "ob_types.h" |
| 27 |
#include "shop.h" |
| 28 |
#include "sounds.h" |
| 29 |
#include "sproto.h" |
| 30 |
|
| 31 |
static method_ret transport_type_apply(ob_methods *context, object *op, object *applier, int aflags); |
| 32 |
static method_ret transport_type_process(ob_methods *context, object *op); |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
void init_type_transport(void) { |
| 38 |
register_apply(TRANSPORT, transport_type_apply); |
| 39 |
register_process(TRANSPORT, transport_type_process); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
static method_ret transport_type_apply(ob_methods *context, object *op, object *applier, int aflags) { |
| 53 |
object *old_transport = applier->contr->transport; |
| 54 |
object *inv; |
| 55 |
char name_op[MAX_BUF], name_old[MAX_BUF]; |
| 56 |
|
| 57 |
|
| 58 |
if (applier->type != PLAYER) |
| 59 |
return METHOD_UNHANDLED; |
| 60 |
|
| 61 |
query_name(op, name_op, MAX_BUF); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if (old_transport && old_transport != op) { |
| 68 |
query_name(old_transport, name_old, MAX_BUF); |
| 69 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 70 |
"You must exit %s before you can board %s.", |
| 71 |
name_old, name_op); |
| 72 |
return METHOD_SILENT_ERROR; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
if (old_transport) { |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
if (aflags&AP_APPLY) |
| 83 |
return 1; |
| 84 |
|
| 85 |
query_name(old_transport, name_old, MAX_BUF); |
| 86 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 87 |
"You disembark from %s.", |
| 88 |
name_old); |
| 89 |
object_remove(applier); |
| 90 |
if (applier->contr == old_transport->contr) |
| 91 |
old_transport->contr = NULL; |
| 92 |
|
| 93 |
applier->contr->transport = NULL; |
| 94 |
object_insert_in_map_at(applier, old_transport->map, applier, 0, old_transport->x, old_transport->y); |
| 95 |
if ( applier->map ) applier->map->players--; |
| 96 |
object_sum_weight(old_transport); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
inv = object_find_by_type(old_transport, PLAYER); |
| 103 |
if (!inv) { |
| 104 |
old_transport->face = old_transport->arch->clone.face; |
| 105 |
old_transport->animation = old_transport->arch->clone.animation; |
| 106 |
} else { |
| 107 |
old_transport->contr = inv->contr; |
| 108 |
draw_ext_info_format(NDI_UNIQUE, 0, inv, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 109 |
"%s has disembarked. You are now the captain of %s", |
| 110 |
applier->name, name_old); |
| 111 |
} |
| 112 |
return METHOD_OK; |
| 113 |
} else { |
| 114 |
|
| 115 |
int pc = 0, p_limit; |
| 116 |
const char *kv; |
| 117 |
int16_t ox, oy; |
| 118 |
|
| 119 |
if (aflags&AP_UNAPPLY) |
| 120 |
return 1; |
| 121 |
|
| 122 |
|
| 123 |
if (!transport_can_hold(op, applier, 1)) { |
| 124 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 125 |
"The %s is unable to hold your weight!", |
| 126 |
name_op); |
| 127 |
return METHOD_SILENT_ERROR; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
if (op->env == applier) { |
| 132 |
old_transport = op; |
| 133 |
|
| 134 |
if (!shop_contains(applier)) { |
| 135 |
op = drop_object(applier, op, 1); |
| 136 |
} else { |
| 137 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 138 |
"You cannot drop the %s in a shop to use it.", |
| 139 |
name_old); |
| 140 |
return METHOD_SILENT_ERROR; |
| 141 |
} |
| 142 |
|
| 143 |
if (!op) { |
| 144 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 145 |
"You need to drop the %s to use it.", |
| 146 |
name_old); |
| 147 |
return METHOD_SILENT_ERROR; |
| 148 |
} |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
FOR_INV_PREPARE(op, inv) |
| 153 |
if (inv->type == PLAYER) |
| 154 |
pc++; |
| 155 |
FOR_INV_FINISH(); |
| 156 |
|
| 157 |
kv = object_get_value(op, "passenger_limit"); |
| 158 |
if (!kv) |
| 159 |
p_limit = 1; |
| 160 |
else |
| 161 |
p_limit = atoi(kv); |
| 162 |
if (pc >= p_limit) { |
| 163 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 164 |
"The %s does not have space for any more people", |
| 165 |
name_op); |
| 166 |
return METHOD_SILENT_ERROR; |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
applier->contr->transport = op; |
| 171 |
|
| 172 |
if (op->contr) { |
| 173 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 174 |
"The %s's captain is currently %s", |
| 175 |
name_op, op->contr->ob->name); |
| 176 |
} else { |
| 177 |
draw_ext_info_format(NDI_UNIQUE, 0, applier, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 178 |
"You're the %s's captain", |
| 179 |
name_op); |
| 180 |
op->contr = applier->contr; |
| 181 |
} |
| 182 |
|
| 183 |
if ( applier->map ) applier->map->players++; |
| 184 |
object_remove(applier); |
| 185 |
|
| 186 |
ox = applier->x; |
| 187 |
oy = applier->y; |
| 188 |
object_insert_in_ob(applier, op); |
| 189 |
object_sum_weight(op); |
| 190 |
applier->map = op->map; |
| 191 |
if (ox != op->x || oy != op->y) { |
| 192 |
esrv_map_scroll(&applier->contr->socket, (ox-op->x), (oy-op->y)); |
| 193 |
} |
| 194 |
applier->contr->socket.update_look = 1; |
| 195 |
applier->contr->socket.look_position = 0; |
| 196 |
applier->x = op->x; |
| 197 |
applier->y = op->y; |
| 198 |
|
| 199 |
|
| 200 |
if (!pc) { |
| 201 |
const char *str; |
| 202 |
|
| 203 |
str = object_get_value(op, "face_full"); |
| 204 |
if (str) |
| 205 |
op->face = find_face(str, op->face); |
| 206 |
str = object_get_value(op, "anim_full"); |
| 207 |
if (str) |
| 208 |
op->animation = find_animation(str); |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
kv = object_get_value(op, "weight_speed_ratio"); |
| 213 |
if (kv) { |
| 214 |
int wsr = atoi(kv); |
| 215 |
float base_speed; |
| 216 |
|
| 217 |
kv = object_get_value(op, "base_speed"); |
| 218 |
if (kv) |
| 219 |
base_speed = atof(kv); |
| 220 |
else |
| 221 |
base_speed = op->arch->clone.speed; |
| 222 |
|
| 223 |
op->speed = base_speed-(base_speed*op->carrying*wsr)/(op->weight_limit*100); |
| 224 |
|
| 225 |
|
| 226 |
if (op->speed < 0.10) |
| 227 |
op->speed = 0.10; |
| 228 |
if (op->speed > 1.0) |
| 229 |
op->speed = 1.0; |
| 230 |
} |
| 231 |
} |
| 232 |
return METHOD_OK; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
static method_ret transport_type_process(ob_methods *context, object *op) { |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
if (op->speed_left < 0.0) { |
| 249 |
op->speed_left += 1.0; |
| 250 |
return 1; |
| 251 |
} |
| 252 |
return 0; |
| 253 |
} |