OSDN Git Service

日本語版
[nazghul-jp/nazghul-jp.git] / src / wind.c
1 //
2 // nazghul - an old-school RPG engine
3 // Copyright (C) 2002, 2003 Gordon McNutt
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation; either version 2 of the License, or (at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 // more details.
14 //
15 // You should have received a copy of the GNU General Public License along with
16 // this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 // Suite 330, Boston, MA 02111-1307 USA
18 //
19 // Gordon McNutt
20 // gmcnutt@users.sourceforge.net
21 //
22 #include "wind.h"
23 #include "wq.h"
24 #include "common.h"
25 #include "screen.h"
26 #include "session.h"
27 #include "log.h"
28
29 static SDL_Rect windRect;
30 static int windDirection;
31 static int windDuration;
32
33 void windAdvanceTurns(void)
34 {
35         if (windDuration > 0) {
36                 windDuration--;
37                 return;
38         }
39
40         if (rand() % 100 < WIND_CHANGE_PROBABILITY) {
41             int dir = rand() % NUM_WIND_DIRECTIONS;
42             windSetDirection(dir, 10);
43         }
44 }
45
46 int windInit(void)
47 {
48         windRect.w = WIND_W;
49         windRect.x = WIND_X;
50         windRect.y = WIND_Y;
51         windRect.h = WIND_H;
52
53         windDirection = NORTH;
54         windDuration = 0;
55
56         return 0;
57 }
58
59 void windSetDirection(int dir, int dur)
60 {
61     if (HERE == dir || dir >= NUM_WIND_DIRECTIONS) {
62         return;
63     }
64
65     if (dir != windDirection) {
66         log_msg("É÷¸þ¤­¤¬%s¤ËÊѤï¤Ã¤¿¡£", directionToString(dir));
67     }
68
69     windDirection = dir;
70     windDuration = dur;
71     windRepaint();
72 }
73
74 int windGetDirection(void)
75 {
76         return windDirection;
77 }
78
79 void windRepaint(void)
80 {
81         screenErase(&windRect);
82         screenPrint(&windRect, SP_CENTERED, "É÷¸þ¤­:%s",
83                     directionToString(windDirection));
84         screenUpdate(&windRect);
85 }
86
87 void windSave(struct save *save)
88 {
89         save->write(save, "(kern-set-wind %d %d)\n", windDirection, 
90                     windDuration);
91 }