forked from deadjim/darknova-iphone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShipYardView.m
executable file
·201 lines (160 loc) · 6.93 KB
/
ShipYardView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
Dark Nova © Copyright 2009 Dead Jim Studios
This file is part of Dark Nova.
Dark Nova is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Dark Nova is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dark Nova. If not, see <http://www.gnu.org/licenses/>
*/
#import "ShipYardView.h"
#import "S1AppDelegate.h"
#import "Player.h"
#import "AlertModalWindow.h"
#import "BuyShipViewController.h"
@implementation ShipYardView
//@synthesize fuelAmount, fuelCost, hullStrength, needRepairs, newShipsInfo, escapePod, buyFuel, buyFullTank,
//buyRepair, buyFullRepair, buyEscapePod, totalCash;
-(void) UpdateView {
S1AppDelegate * app = (S1AppDelegate *)[[UIApplication sharedApplication] delegate];
totalCash.text = [NSString stringWithFormat:@"Cash: %i cr.", app.gamePlayer.credits];
if ([app.gamePlayer getFuel] < [app.gamePlayer GetFuelTanks]) {
[self addSubview:buyFuel];
[self addSubview:buyFullTank];
} else {
[buyFuel removeFromSuperview];
[buyFullTank removeFromSuperview];
}
if ( [app.gamePlayer getShipHull] < [app.gamePlayer GetHullStrength]) {
[self addSubview:buyRepair];
[self addSubview:buyFullRepair];
} else {
[buyRepair removeFromSuperview];
[buyFullRepair removeFromSuperview];
}
if ([app.gamePlayer getCurrentSystemTechLevelInt] >= [app.gamePlayer getCurrentShipTechLevel])/* && (
[app.gamePlayer getShipPriceInt:0] != 0 || [app.gamePlayer getShipPriceInt:1] != 0 ||
[app.gamePlayer getShipPriceInt:2] != 0 || [app.gamePlayer getShipPriceInt:3] != 0 ||
[app.gamePlayer getShipPriceInt:4] != 0 || [app.gamePlayer getShipPriceInt:5] != 0 ||
[app.gamePlayer getShipPriceInt:6] != 0 || [app.gamePlayer getShipPriceInt:7] != 0 ||
[app.gamePlayer getShipPriceInt:8] != 0 || [app.gamePlayer getShipPriceInt:9] != 0 ))*/ {
[self addSubview:buyNewShip];
[shipInfo removeFromSuperview];
} else {
[buyNewShip removeFromSuperview];
[shipInfo removeFromSuperview];
}
if ([app.gamePlayer getCurrentSystemTechLevelInt] < [app.gamePlayer getCurrentShipTechLevel] || [app.gamePlayer toSpend] < 2000 || [app.gamePlayer escapePod]) {
[buyEscapePod removeFromSuperview];
} else {
[self addSubview:buyEscapePod];
}
fuelAmount.text = [NSString stringWithFormat:@"You have fuel to fly %i parsec%@", [app.gamePlayer getFuel],[app.gamePlayer getFuel] > 1 ? @"." : @"s." ];
if ([app.gamePlayer getFuel] < [app.gamePlayer GetFuelTanks]) {
int cost = ([app.gamePlayer GetFuelTanks] - [app.gamePlayer getFuel]) * [app.gamePlayer getFuelCost];
fuelCost.text = [NSString stringWithFormat:@"A full tank costs %i cr.", cost];
}
else {
fuelCost.text = @"Your tank cannot hold more fuel.";
}
hullStrength.text = [NSString stringWithFormat:@"Your hull strength is at %i %%.", [app.gamePlayer getShipHull] * 100/ [app.gamePlayer GetHullStrength]];
if ([app.gamePlayer getShipHull] < [app.gamePlayer GetHullStrength]) {
int cost = (-[app.gamePlayer getShipHull] + [app.gamePlayer GetHullStrength]) * [app.gamePlayer getRepairCost];
needRepairs.text = [NSString stringWithFormat:@"Full repair will cost %i cr.", cost];
}
else {
needRepairs.text = @"No repairs are needed.";
}
if ([app.gamePlayer getCurrentSystemTechLevelInt] >= [app.gamePlayer getCurrentShipTechLevel]) {
newShipsInfo.text =@"There are new ships for sale.";
}
else {
newShipsInfo.text =@"No new ships for sale.";
}
if ([app.gamePlayer escapePod])
escapePod.text = @"You have an escape pod installed.";
else
if ([app.gamePlayer getCurrentSystemTechLevelInt] < [app.gamePlayer getCurrentShipTechLevel])
escapePod.text =@"No escape pods for sale.";
else if ([app.gamePlayer toSpend] < 2000)
escapePod.text = @"You need 2000 c. for an escape pod.";
else
escapePod.text = @"You can buy an escape pod for 2000 cr.";
}
- (void)viewDidAppear:(BOOL)animated {
[self UpdateView];
}
- (void)didMoveToWindow {
[super didMoveToWindow];
[self UpdateView];
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex // after animation
{
int button = buttonIndex;
S1AppDelegate * app = (S1AppDelegate *)[[UIApplication sharedApplication] delegate];
if (button == 1) {
// Ok
NSString * value = [[(AlertModalWindow*)alertView myTextField] text];
unsigned int val = value.intValue;
if (mode == 1)
[app.gamePlayer BuyFuel:val];
else
[app.gamePlayer buyRepairs:val];
//[app.gamePlayer buyCargo:activeTradeItem Amount:buyCargoViewValue[val]];
[self UpdateView];
} else if (button == 2) {
if (mode == 1)
[app.gamePlayer BuyFuel:999];
else
[app.gamePlayer buyRepairs:999];
//[self pressedCargoMax:activeTradeItem];
}
[self UpdateView];
}
-(IBAction) buyFuel {
mode = 1;
NSString * message = [NSString stringWithFormat:@"How much do you want to spend on fuel?"];
AlertModalWindow * myAlertView = [[[AlertModalWindow alloc] initWithTitle:@"Buy Fuel" yoffset:90 message:message
delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Ok" thirdButtonTitle:@"All"] autorelease];
[myAlertView show];
}
-(IBAction) buyFullFuel {
S1AppDelegate * app = (S1AppDelegate *)[[UIApplication sharedApplication] delegate];
[app.gamePlayer BuyFuel:999];
[self UpdateView];
}
-(IBAction) buyRepair {
mode = 2;
NSString * message = [NSString stringWithFormat:@"How much do you want to spend on repairs?"];
AlertModalWindow * myAlertView = [[[AlertModalWindow alloc] initWithTitle:@"Repairs" yoffset:90 message:message
delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Ok" thirdButtonTitle:@"All"] autorelease];
[myAlertView show];
}
-(IBAction) buyFullRepair {
S1AppDelegate * app = (S1AppDelegate *)[[UIApplication sharedApplication] delegate];
[app.gamePlayer buyRepairs:999];
[self UpdateView];
}
-(IBAction) buyNewShip {
S1AppDelegate * app = (S1AppDelegate *)[[UIApplication sharedApplication] delegate];
if (app.buyShipController == 0)
app.buyShipController = [[[BuyShipViewController alloc] initWithNibName:@"buyShip" bundle:nil] autorelease];
[app.navigationController pushViewController:app.buyShipController animated:YES];
}
-(IBAction) buyEscapePod {
S1AppDelegate * app = (S1AppDelegate *)[[UIApplication sharedApplication] delegate];
app.gamePlayer.escapePod = true;
app.gamePlayer.credits -= 2000;
[self UpdateView];
}
-(IBAction) shipInfo {
}
/*
AlertModalWindow * myAlertView = [[AlertModalWindow alloc] initWithTitle:@"Buy Items" yoffset:90 message:message
delegate:self cancelButtonTitle:@"Cancel" okButtonTitle:@"Ok" thirdButtonTitle:@"All"];*/
@end