1 /* $Id: stage.c,v 1.12 2004/08/16 15:48:09 oohara Exp $ */
2 
3 #include <stdio.h>
4 
5 #include "stage.h"
6 
7 static int current_stage_number = 1;
8 static int current_stage_id[6];
9 static int current_stage_difficulty[6];
10 static const char *current_stage_name[6];
11 
12 void
set_stage_number(int n)13 set_stage_number(int n)
14 {
15   current_stage_number = n;
16 }
17 
18 int
get_stage_number(void)19 get_stage_number(void)
20 {
21   return current_stage_number;
22 }
23 
24 /* return the new value of stage_number */
25 int
add_stage_number(int delta)26 add_stage_number(int delta)
27 {
28   if (current_stage_number + delta <= 0)
29   {
30     fprintf(stderr, "add_stage_number: trying to let stage_number negative, "
31             "assuming 1 instead\n");
32     current_stage_number = 1;
33   }
34   else
35   {
36     current_stage_number += delta;
37   }
38 
39   return current_stage_number;
40 }
41 
42 void
set_stage_id(int stage,int n)43 set_stage_id(int stage, int n)
44 {
45   /* sanity check */
46   if ((stage < 1) || (stage > 6))
47   {
48     fprintf(stderr, "set_stage_id: strange stage (%d)\n", stage);
49     return;
50   }
51 
52   current_stage_id[stage - 1] = n;
53 }
54 
55 void
set_stage_name(int stage,const char * p)56 set_stage_name(int stage, const char *p)
57 {
58   /* sanity check */
59   if ((stage < 1) || (stage > 6))
60   {
61     fprintf(stderr, "set_stage_name: strange stage (%d)\n", stage);
62     return;
63   }
64 
65   current_stage_name[stage - 1] = p;
66 }
67 
68 void
set_stage_difficulty(int stage,int n)69 set_stage_difficulty(int stage, int n)
70 {
71   /* sanity check */
72   if ((stage < 1) || (stage > 6))
73   {
74     fprintf(stderr, "set_stage_difficulty: strange stage (%d)\n", stage);
75     return;
76   }
77 
78   current_stage_difficulty[stage - 1] = n;
79 }
80 
81 int
get_stage_id(int stage)82 get_stage_id(int stage)
83 {
84   /* sanity check */
85   if ((stage < 1) || (stage > 6))
86   {
87     fprintf(stderr, "get_stage_id: strange stage (%d)\n", stage);
88     return -1;
89   }
90 
91   return current_stage_id[stage - 1];
92 }
93 
94 const char *
get_stage_name(int stage)95 get_stage_name(int stage)
96 {
97   /* sanity check */
98   if ((stage < 1) || (stage > 6))
99   {
100     fprintf(stderr, "get_stage_name: strange stage (%d)\n", stage);
101     return NULL;
102   }
103 
104   return current_stage_name[stage - 1];
105 }
106 
107 int
get_stage_difficulty(int stage)108 get_stage_difficulty(int stage)
109 {
110   /* sanity check */
111   if ((stage < 1) || (stage > 6))
112   {
113     fprintf(stderr, "get_stage_difficulty: strange stage (%d)\n", stage);
114     return -1;
115   }
116 
117   return current_stage_difficulty[stage - 1];
118 }
119