Atrinik Server  4.0
clock.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <object.h>
34 #include <object_methods.h>
35 
37 static void
38 process_func (object *op)
39 {
40  HARD_ASSERT(op != NULL);
41 
42  if (op->map == NULL) {
43  return;
44  }
45 
46  if (op->last_heal > 0) {
47  play_sound_map(op->map,
48  CMD_SOUND_EFFECT,
49  "clock.ogg",
50  op->x,
51  op->y,
52  0,
53  0);
54  op->last_heal--;
55  return;
56  }
57 
58  timeofday_t tod;
59  get_tod(&tod);
60 
61  if (tod.hour == op->last_sp) {
62  return;
63  }
64 
65  op->last_sp = tod.hour;
66  if ((tod.hour % (HOURS_PER_DAY / 2)) == 0) {
67  op->last_heal = HOURS_PER_DAY / 2;
68  } else {
69  op->last_heal = tod.hour % (HOURS_PER_DAY / 2);
70  }
71 }
72 
74 static int
75 apply_func (object *op, object *applier, int aflags)
76 {
77  HARD_ASSERT(op != NULL);
78  HARD_ASSERT(applier != NULL);
79 
80  if (applier->type != PLAYER) {
82  }
83 
84  timeofday_t tod;
85  get_tod(&tod);
86  int hour;
87  if ((tod.hour % (HOURS_PER_DAY / 2)) == 0) {
88  hour = HOURS_PER_DAY / 2;
89  } else {
90  hour = tod.hour % (HOURS_PER_DAY / 2);
91  }
92 
93  draw_info_format(COLOR_WHITE, applier,
94  "It is %d minute%s past %d o'clock %s.",
95  tod.minute,
96  tod.minute == 1 ? "" : "s",
97  hour,
98  tod.hour >= HOURS_PER_DAY / 2 ? "pm" : "am");
99 
100  return OBJECT_METHOD_OK;
101 }
102 
104 static void
105 insert_map_func (object *op)
106 {
107  timeofday_t tod;
108  get_tod(&tod);
109  op->last_sp = tod.hour;
110 }
111 
116 {
117  OBJECT_METHODS(CLOCK)->process_func = process_func;
118  OBJECT_METHODS(CLOCK)->apply_func = apply_func;
119  OBJECT_METHODS(CLOCK)->insert_map_func = insert_map_func;
120 }
int16_t last_heal
Definition: object.h:310
int minute
Definition: tod.h:82
int16_t last_sp
Definition: object.h:313
#define PLAYER
Definition: define.h:122
#define CLOCK
Definition: define.h:154
static void process_func(object *op)
Definition: clock.c:38
void get_tod(timeofday_t *tod)
Definition: time.c:279
int16_t y
Definition: object.h:276
struct mapdef * map
Definition: object.h:139
#define OBJECT_METHOD_UNHANDLED
int16_t x
Definition: object.h:273
void play_sound_map(mapstruct *map, int type, const char *filename, int x, int y, int loop, int volume)
Definition: sounds.c:159
OBJECT_TYPE_INIT_DEFINE(clock)
Definition: clock.c:115
static int apply_func(object *op, object *applier, int aflags)
Definition: clock.c:75
#define HOURS_PER_DAY
Definition: tod.h:37
Definition: tod.h:65
uint8_t type
Definition: object.h:360
#define OBJECT_METHODS(type)
static void insert_map_func(object *op)
Definition: clock.c:105
int hour
Definition: tod.h:79
#define OBJECT_METHOD_OK