OSDN Git Service

Merge remote-tracking branch 'remotes/origin/feature/Implement-Debug-Auto-Save' into...
[hengband/hengband.git] / src / store / owner-insults.c
1 #include "store/owner-insults.h"
2 #include "core/asking-player.h"
3 #include "game-option/birth-options.h"
4 #include "store/say-comments.h"
5 #include "store/store.h"
6 #include "store/store-util.h"
7 #include "term/screen-processor.h"
8 #include "view/display-messages.h"
9 #include "world/world.h"
10
11 /* Last "increment" during haggling */
12 static s32b last_inc = 0L;
13
14 /*!
15  * @brief 店主の不満度を増やし、プレイヤーを締め出す判定と処理を行う /
16  * Increase the insult counter and get angry if too many -RAK-
17  * @return プレイヤーを締め出す場合TRUEを返す
18  */
19 int increase_insults(void)
20 {
21     st_ptr->insult_cur++;
22     if (st_ptr->insult_cur <= ot_ptr->insult_max)
23         return FALSE;
24
25     say_comment_4();
26     st_ptr->insult_cur = 0;
27     st_ptr->good_buy = 0;
28     st_ptr->bad_buy = 0;
29     st_ptr->store_open = current_world_ptr->game_turn + TURNS_PER_TICK * TOWN_DAWN / 8 + randint1(TURNS_PER_TICK * TOWN_DAWN / 8);
30     return TRUE;
31 }
32
33 /*!
34  * @brief 店主の不満度を減らす /
35  * Decrease insults                             -RAK-
36  * @return プレイヤーを締め出す場合TRUEを返す
37  */
38 void decrease_insults(void)
39 {
40     if (st_ptr->insult_cur)
41         st_ptr->insult_cur--;
42 }
43
44 /*!
45  * @brief 店主の不満度が増えた場合のみのメッセージを表示する /
46  * Have insulted while haggling                         -RAK-
47  * @return プレイヤーを締め出す場合TRUEを返す
48  */
49 int haggle_insults(void)
50 {
51     if (increase_insults())
52         return TRUE;
53
54     say_comment_5();
55     return FALSE;
56 }
57
58 /*!
59  * @brief 店主の持つプレイヤーに対する売買の良し悪し経験を記憶する /
60  * Update the bargain info
61  * @param price 実際の取引価格
62  * @param minprice 店主の提示した価格
63  * @param num 売買数
64  * @return なし
65  */
66 void updatebargain(PRICE price, PRICE minprice, int num)
67 {
68     if (!manual_haggle)
69         return;
70     if ((minprice / num) < 10L)
71         return;
72     if (price == minprice) {
73         if (st_ptr->good_buy < MAX_SHORT) {
74             st_ptr->good_buy++;
75         }
76     } else {
77         if (st_ptr->bad_buy < MAX_SHORT) {
78             st_ptr->bad_buy++;
79         }
80     }
81 }
82
83 /*!
84  * @brief 交渉価格を確認と認証の是非を行う /
85  * Get a haggle
86  * @param pmt メッセージ
87  * @param poffer 別途価格提示をした場合の値を返す参照ポインタ
88  * @param price 現在の交渉価格
89  * @param final 最終確定価格ならばTRUE
90  * @return プレイヤーを締め出す場合TRUEを返す
91  */
92 static int get_haggle(concptr pmt, s32b *poffer, PRICE price, int final)
93 {
94     GAME_TEXT buf[128];
95     if (!allow_inc)
96         last_inc = 0L;
97
98     if (final) {
99         sprintf(buf, _("%s [承諾] ", "%s [accept] "), pmt);
100     } else if (last_inc < 0) {
101         sprintf(buf, _("%s [-$%ld] ", "%s [-%ld] "), pmt, (long)(ABS(last_inc)));
102     } else if (last_inc > 0) {
103         sprintf(buf, _("%s [+$%ld] ", "%s [+%ld] "), pmt, (long)(ABS(last_inc)));
104     } else {
105         sprintf(buf, "%s ", pmt);
106     }
107
108     msg_print(NULL);
109     GAME_TEXT out_val[160];
110     while (TRUE) {
111         bool res;
112         prt(buf, 0, 0);
113         strcpy(out_val, "");
114
115         /*
116          * Ask the user for a response.
117          * Don't allow to use numpad as cursor key.
118          */
119         res = askfor_aux(out_val, 32, FALSE);
120         prt("", 0, 0);
121         if (!res)
122             return FALSE;
123
124         concptr p;
125         for (p = out_val; *p == ' '; p++) /* loop */
126             ;
127
128         if (*p == '\0') {
129             if (final) {
130                 *poffer = price;
131                 last_inc = 0L;
132                 break;
133             }
134
135             if (allow_inc && last_inc) {
136                 *poffer += last_inc;
137                 break;
138             }
139
140             msg_print(_("値がおかしいです。", "Invalid response."));
141             msg_print(NULL);
142             continue;
143         }
144
145         s32b i = atol(p);
146         if ((*p == '+' || *p == '-')) {
147             if (allow_inc) {
148                 *poffer += i;
149                 last_inc = i;
150                 break;
151             }
152         } else {
153             *poffer = i;
154             last_inc = 0L;
155             break;
156         }
157     }
158
159     return TRUE;
160 }
161
162 /*!
163  * @brief 店主がプレイヤーからの交渉価格を判断する /
164  * Receive an offer (from the player)
165  * @param pmt メッセージ
166  * @param poffer 店主からの交渉価格を返す参照ポインタ
167  * @param last_offer 現在の交渉価格
168  * @param factor 店主の価格基準倍率
169  * @param price アイテムの実価値
170  * @param final 最終価格確定ならばTRUE
171  * @return プレイヤーの価格に対して不服ならばTRUEを返す /
172  * Return TRUE if offer is NOT okay
173  */
174 bool receive_offer(concptr pmt, s32b *poffer, s32b last_offer, int factor, PRICE price, int final)
175 {
176     while (TRUE) {
177         if (!get_haggle(pmt, poffer, price, final))
178             return TRUE;
179
180         if (((*poffer) * factor) >= (last_offer * factor))
181             break;
182
183         if (haggle_insults())
184             return TRUE;
185
186         *poffer = last_offer;
187     }
188
189     return FALSE;
190 }