Debian Codegraph @

server/c_move.c

raw symbols SCIP
1 /*
2 * Crossfire -- cooperative multi-player graphical RPG and adventure game
3 *
4 * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5 * Copyright (c) 1992 Frank Tore Johansen
6 *
7 * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8 * welcome to redistribute it under certain conditions. For details, please
9 * see COPYING and LICENSE.
10 *
11 * The authors can be reached via e-mail at <[email protected]>.
12 */
13
14 /**
15 * @file
16 * Move-related (north, east, ...) commands.
17 */
18
19 #include <global.h>
20 #ifndef __CEXTRACT__
21 #include <sproto.h>
22 #endif
23 #include <skills.h>
24
25 /**
26 * A player is moving in a direction, but this may indicate firing.
27 *
28 * @param op
29 * player moving.
30 * @param params
31 * optional parameters for moving (fire, run).
32 * @param dir
33 * moving direction.
34 */
35 static void move_internal(object *op, const char *params, int dir) {
36 if (*params != '\0') {
37 if (params[0] == 'f') {
38 if (!op->contr->fire_on) {
39 op->contr->fire_on = 1;
40 move_player(op, dir);
41 op->contr->fire_on = 0;
42 return;
43 }
44 } else if (params[0] == 'r' && !op->contr->run_on)
45 op->contr->run_on = 1;
46 }
47 move_player(op, dir);
48 }
49
50 /**
51 * 'east' command.
52 * @param op
53 * player.
54 * @param params
55 * optional parameters for moving (fire, run).
56 */
57 void command_east(object *op, const char *params) {
58 move_internal(op, params, 3);
59 }
60
61 /**
62 * 'north' command.
63 * @param op
64 * player.
65 * @param params
66 * optional parameters for moving (fire, run).
67 */
68 void command_north(object *op, const char *params) {
69 move_internal(op, params, 1);
70 }
71
72 /**
73 * 'northeast' command.
74 * @param op
75 * player.
76 * @param params
77 * optional parameters for moving (fire, run).
78 */
79 void command_northeast(object *op, const char *params) {
80 move_internal(op, params, 2);
81 }
82
83 /**
84 * 'northwest' command.
85 * @param op
86 * player.
87 * @param params
88 * optional parameters for moving (fire, run).
89 */
90 void command_northwest(object *op, const char *params) {
91 move_internal(op, params, 8);
92 }
93
94 /**
95 * 'south' command.
96 * @param op
97 * player.
98 * @param params
99 * optional parameters for moving (fire, run).
100 */
101 void command_south(object *op, const char *params) {
102 move_internal(op, params, 5);
103 }
104
105 /**
106 * 'southeast' command.
107 * @param op
108 * player.
109 * @param params
110 * optional parameters for moving (fire, run).
111 */
112 void command_southeast(object *op, const char *params) {
113 move_internal(op, params, 4);
114 }
115
116 /**
117 * 'southwest' command.
118 * @param op
119 * player.
120 * @param params
121 * optional parameters for moving (fire, run).
122 */
123 void command_southwest(object *op, const char *params) {
124 move_internal(op, params, 6);
125 }
126
127 /**
128 * 'west' command.
129 * @param op
130 * player.
131 * @param params
132 * optional parameters for moving (fire, run).
133 */
134 void command_west(object *op, const char *params) {
135 move_internal(op, params, 7);
136 }
137
138 /**
139 * 'stay' command. Used to specify to fire under oneself.
140 * @param op
141 * player.
142 * @param params
143 * optional parameters for moving (fire, run).
144 */
145 void command_stay(object *op, const char *params) {
146 if (!op->contr->fire_on && params[0] != 'f')
147 return;
148 fire(op, 0);
149 }
150
151 void do_goto(object *op, const char *name, int x, int y) {
152 object *dummy;
153 dummy = object_new();
154 dummy->map = op->map;
155 EXIT_PATH(dummy) = add_string(name);
156 EXIT_X(dummy) = x;
157 EXIT_Y(dummy) = y;
158 dummy->name = add_string(name);
159
160 enter_exit(op, dummy);
161 object_free(dummy, FREE_OBJ_NO_DESTROY_CALLBACK);
162 }