Crossfire Server, Trunk  1.75.0
c_new.cpp
Go to the documentation of this file.
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 <crossfire@metalforge.org>.
12  */
13 
19 #include "global.h"
20 
21 #include <stdlib.h>
22 #include <string.h>
23 #include <ctype.h>
24 
25 #include "commands.h"
26 #include "sproto.h"
27 
28 #ifndef tolower
29 
30 #define tolower(C) (((C) >= 'A' && (C) <= 'Z') ? (C)-'A'+'a' : (C))
31 #endif
32 
41 void command_run(object *op, const char *params) {
42  int dir;
43 
44  dir = atoi(params);
45  if (dir < 0 || dir >= 9) {
47  "Can't run into a non adjacent square.");
48  return;
49  }
50  op->contr->run_on = 1;
51  move_player(op, dir);
52 }
53 
64 void command_run_stop(object *op, const char *params) {
65  (void)params;
66  op->contr->run_on = 0;
67 }
68 
77 void command_fire(object *op, const char *params) {
78  int dir;
79 
80  dir = atoi(params);
81  if (dir < 0 || dir >= 9) {
83  "Can't fire to a non adjacent square.");
84  return;
85  }
86  op->contr->fire_on = 1;
87  move_player(op, dir);
88 }
89 
98 void command_fire_stop(object *op, const char *params) {
99  (void)params;
100  op->contr->fire_on = 0;
101 }
102 
111 void command_face(object *op, const char *params) {
112  int dir;
113 
114  if ( !isdigit(*params) ) {
115  if ( strcmp(params,"stay") == 0 || strcmp(params,"down") == 0 ) dir=0;
116  else if ( strcmp(params,"north") == 0 || strcmp(params,"n") == 0 ) dir=1;
117  else if ( strcmp(params,"northeast") == 0 || strcmp(params,"ne") == 0 ) dir=2;
118  else if ( strcmp(params,"east") == 0 || strcmp(params,"e") == 0 ) dir=3;
119  else if ( strcmp(params,"southeast") == 0 || strcmp(params,"se") == 0 ) dir=4;
120  else if ( strcmp(params,"south") == 0 || strcmp(params,"s") == 0 ) dir=5;
121  else if ( strcmp(params,"southwest") == 0 || strcmp(params,"sw") == 0 ) dir=6;
122  else if ( strcmp(params,"west") == 0 || strcmp(params,"w") == 0 ) dir=7;
123  else if ( strcmp(params,"northwest") == 0 || strcmp(params,"nw") == 0 ) dir=8;
124  else {
126  "Unknown direction to face: %s",params);
127  return;
128  }
129  }
130  else dir = atoi(params);
131  if (dir < 0 || dir >= 9) {
133  "Can't face to a non adjacent square.");
134  return;
135  }
136  face_player(op, dir);
137 }
global.h
command_face
void command_face(object *op, const char *params)
Player wants to face a given direction.
Definition: c_new.cpp:111
command_run_stop
void command_run_stop(object *op, const char *params)
Player wants to stop running.
Definition: c_new.cpp:64
command_fire
void command_fire(object *op, const char *params)
Player wants to start firing.
Definition: c_new.cpp:77
command_run
void command_run(object *op, const char *params)
Player wants to start running.
Definition: c_new.cpp:41
draw_ext_info_format
void draw_ext_info_format(int flags, int pri, const object *pl, uint8_t type, uint8_t subtype, const char *format,...) PRINTF_ARGS(6
move_player
int move_player(object *op, int dir)
Move player in the given direction.
Definition: player.cpp:2962
MSG_TYPE_COMMAND_ERROR
#define MSG_TYPE_COMMAND_ERROR
Bad syntax/can't use command.
Definition: newclient.h:533
MSG_TYPE_COMMAND
#define MSG_TYPE_COMMAND
Responses to commands, eg, who.
Definition: newclient.h:408
draw_ext_info
vs only yadda is in because all tags get reset on the next draw_ext_info In the second since it is all in one draw_ext_info
Definition: media-tags.txt:61
object::contr
struct player * contr
Pointer to the player which control this object.
Definition: object.h:284
player::run_on
uint32_t run_on
Player should keep moving in dir until run is off.
Definition: player.h:143
face_player
int face_player(object *op, int dir)
Face player in the given direction.
Definition: player.cpp:3041
sproto.h
player::fire_on
uint32_t fire_on
Player should fire object, not move.
Definition: player.h:142
NDI_UNIQUE
#define NDI_UNIQUE
Print immediately, don't buffer.
Definition: newclient.h:266
commands.h
command_fire_stop
void command_fire_stop(object *op, const char *params)
Player wants to stop firing.
Definition: c_new.cpp:98