poke_engine/
instruction.rs

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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
use crate::choices::{Choices, MoveCategory};
use crate::items::Items;
use crate::state::Terrain;
use crate::state::Weather;
use crate::state::{FormeChange, SideReference};
use crate::state::{LastUsedMove, PokemonVolatileStatus};
use crate::state::{PokemonBoostableStat, PokemonType};
use crate::state::{PokemonIndex, PokemonSideCondition};
use crate::state::{PokemonMoveIndex, PokemonStatus};
use std::fmt;
use std::fmt::Formatter;

#[derive(PartialEq, Clone)]
pub struct StateInstructions {
    pub percentage: f32,
    pub instruction_list: Vec<Instruction>,
}

impl Default for StateInstructions {
    fn default() -> StateInstructions {
        StateInstructions {
            percentage: 100.0,
            instruction_list: Vec::with_capacity(16),
        }
    }
}

impl fmt::Debug for StateInstructions {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        let mut final_string = format!("\n\tPercentage: {:.2}\n\tInstructions:", self.percentage);
        for i in self.instruction_list.iter() {
            final_string.push_str(format!("\n\t\t{:?}", i).as_str());
        }
        write!(f, "{}\n", final_string)
    }
}

impl StateInstructions {
    pub fn update_percentage(&mut self, modifier: f32) {
        self.percentage *= modifier;
    }
}

// https://stackoverflow.com/questions/50686411/whats-the-usual-way-to-create-a-vector-of-different-structs
#[derive(PartialEq, Clone)]
pub enum Instruction {
    Switch(SwitchInstruction),
    ApplyVolatileStatus(ApplyVolatileStatusInstruction),
    RemoveVolatileStatus(RemoveVolatileStatusInstruction),
    ChangeStatus(ChangeStatusInstruction),
    Heal(HealInstruction),
    Damage(DamageInstruction),
    Boost(BoostInstruction),
    ChangeSideCondition(ChangeSideConditionInstruction),
    ChangeWeather(ChangeWeather),
    DecrementWeatherTurnsRemaining,
    ChangeTerrain(ChangeTerrain),
    DecrementTerrainTurnsRemaining,
    ChangeType(ChangeType),
    ChangeItem(ChangeItemInstruction),
    DisableMove(DisableMoveInstruction),
    EnableMove(EnableMoveInstruction),
    SetWish(SetWishInstruction),
    DecrementWish(DecrementWishInstruction),
    SetFutureSight(SetFutureSightInstruction),
    DecrementFutureSight(DecrementFutureSightInstruction),
    DamageSubstitute(DamageInstruction),
    DecrementRestTurns(DecrementRestTurnsInstruction),
    SetRestTurns(SetSleepTurnsInstruction),
    SetSleepTurns(SetSleepTurnsInstruction),
    SetSubstituteHealth(SetSubstituteHealthInstruction),
    FormeChange(FormeChangeInstruction),
    SetSideOneMoveSecondSwitchOutMove(SetSecondMoveSwitchOutMoveInstruction),
    SetSideTwoMoveSecondSwitchOutMove(SetSecondMoveSwitchOutMoveInstruction),
    ToggleBatonPassing(ToggleBatonPassingInstruction),
    SetLastUsedMove(SetLastUsedMoveInstruction),
    SetDamageDealtSideOne(SetDamageDealtSideOneInstruction),
    SetDamageDealtSideTwo(SetDamageDealtSideTwoInstruction),
    DecrementPP(DecrementPPInstruction),
    ToggleTrickRoom(ToggleTrickRoomInstruction),
    DecrementTrickRoomTurnsRemaining,
    ToggleSideOneForceSwitch,
    ToggleSideTwoForceSwitch,
    ToggleTerastallized(ToggleTerastallizedInstruction),
}

impl fmt::Debug for Instruction {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        match self {
            Instruction::Switch(s) => {
                write!(
                    f,
                    "Switch {:?}: {:?} -> {:?}",
                    s.side_ref, s.previous_index, s.next_index
                )
            }
            Instruction::ApplyVolatileStatus(a) => {
                write!(
                    f,
                    "ApplyVolatileStatus {:?}: {:?}",
                    a.side_ref, a.volatile_status
                )
            }
            Instruction::RemoveVolatileStatus(r) => {
                write!(
                    f,
                    "RemoveVolatileStatus {:?}: {:?}",
                    r.side_ref, r.volatile_status
                )
            }
            Instruction::ChangeStatus(c) => {
                write!(
                    f,
                    "ChangeStatus {:?}-{:?}: {:?} -> {:?}",
                    c.side_ref, c.pokemon_index, c.old_status, c.new_status
                )
            }
            Instruction::Heal(h) => {
                write!(f, "Heal {:?}: {:?}", h.side_ref, h.heal_amount)
            }
            Instruction::Damage(d) => {
                write!(f, "Damage {:?}: {}", d.side_ref, d.damage_amount)
            }
            Instruction::Boost(b) => {
                write!(f, "Boost {:?} {:?}: {:?}", b.side_ref, b.stat, b.amount)
            }
            Instruction::ChangeSideCondition(c) => {
                write!(
                    f,
                    "ChangeSideCondition {:?} {:?}: {:?}",
                    c.side_ref, c.side_condition, c.amount
                )
            }
            Instruction::ChangeWeather(c) => {
                write!(
                    f,
                    "ChangeWeather: {:?},{:?} -> {:?},{:?}",
                    c.previous_weather,
                    c.previous_weather_turns_remaining,
                    c.new_weather,
                    c.new_weather_turns_remaining
                )
            }
            Instruction::DecrementWeatherTurnsRemaining => {
                write!(f, "DecrementWeatherTurnsRemaining",)
            }
            Instruction::ChangeTerrain(c) => {
                write!(
                    f,
                    "ChangeTerrain: {:?},{:?} -> {:?},{:?}",
                    c.previous_terrain,
                    c.previous_terrain_turns_remaining,
                    c.new_terrain,
                    c.new_terrain_turns_remaining
                )
            }
            Instruction::DecrementTerrainTurnsRemaining => {
                write!(f, "DecrementTerrainTurnsRemaining",)
            }
            Instruction::ChangeType(c) => {
                write!(
                    f,
                    "ChangeType {:?}: {:?} -> {:?}",
                    c.side_ref, c.old_types, c.new_types
                )
            }
            Instruction::ChangeItem(c) => {
                write!(
                    f,
                    "ChangeItem {:?}: {:?} -> {:?}",
                    c.side_ref, c.current_item, c.new_item
                )
            }
            Instruction::DisableMove(d) => {
                write!(f, "DisableMove {:?}: {:?}", d.side_ref, d.move_index)
            }
            Instruction::EnableMove(e) => {
                write!(f, "EnableMove {:?}: {:?}", e.side_ref, e.move_index)
            }
            Instruction::SetWish(s) => {
                write!(
                    f,
                    "SetWish {:?}: {:?} -> {:?}",
                    s.side_ref, s.previous_wish_amount, s.wish_amount
                )
            }
            Instruction::DecrementWish(d) => {
                write!(f, "DecrementWish {:?}", d.side_ref)
            }
            Instruction::SetFutureSight(s) => {
                write!(
                    f,
                    "SetFutureSight {:?}: {:?} -> {:?}",
                    s.side_ref, s.previous_pokemon_index, s.pokemon_index
                )
            }
            Instruction::DecrementFutureSight(d) => {
                write!(f, "DecrementFutureSight {:?}", d.side_ref)
            }
            Instruction::DamageSubstitute(d) => {
                write!(
                    f,
                    "DamageSubstitute {:?}: {:?}",
                    d.side_ref, d.damage_amount
                )
            }
            Instruction::DecrementRestTurns(d) => {
                write!(f, "DecrementRestTurns {:?}", d.side_ref)
            }
            Instruction::SetRestTurns(s) => {
                write!(
                    f,
                    "SetRestTurns {:?}-{:?}: {:?} -> {:?}",
                    s.side_ref, s.pokemon_index, s.previous_turns, s.new_turns
                )
            }
            Instruction::SetSleepTurns(s) => {
                write!(
                    f,
                    "SetSleepTurns {:?}-{:?}: {:?} -> {:?}",
                    s.side_ref, s.pokemon_index, s.previous_turns, s.new_turns
                )
            }
            Instruction::SetSubstituteHealth(s) => {
                write!(
                    f,
                    "SetSubstituteHealth {:?}: {:?} -> {:?}",
                    s.side_ref, s.old_health, s.new_health
                )
            }
            Instruction::FormeChange(s) => {
                write!(f, "FormeChange {:?}: {:?}", s.side_ref, s.forme_change)
            }
            Instruction::SetSideOneMoveSecondSwitchOutMove(s) => {
                write!(
                    f,
                    "SideOneMoveSecondSwitchOutMove: {:?} -> {:?}",
                    s.previous_choice, s.new_choice
                )
            }
            Instruction::SetSideTwoMoveSecondSwitchOutMove(s) => {
                write!(
                    f,
                    "SideTwoMoveSecondSwitchOutMove: {:?} -> {:?}",
                    s.previous_choice, s.new_choice
                )
            }
            Instruction::ToggleBatonPassing(s) => {
                write!(f, "ToggleBatonPassing {:?}", s.side_ref)
            }
            Instruction::ToggleTerastallized(s) => {
                write!(f, "ToggleTerastallized {:?}", s.side_ref)
            }
            Instruction::SetLastUsedMove(s) => {
                write!(
                    f,
                    "SetLastUsedMove {:?}: {:?} -> {:?}",
                    s.side_ref, s.previous_last_used_move, s.last_used_move
                )
            }
            Instruction::SetDamageDealtSideOne(s) => {
                write!(
                    f,
                    "SetDamageDealt SideOne: ({:?} -> {:?}) Damage Change: {:?} HitSub Change: {:?}",
                    s.previous_move_category,
                    s.move_category,
                    s.damage_change,
                    s.toggle_hit_substitute
                )
            }
            Instruction::SetDamageDealtSideTwo(s) => {
                write!(
                    f,
                    "SetDamageDealt SideTwo: ({:?} -> {:?}) Damage Change: {:?} HitSub Change: {:?}",
                    s.previous_move_category,
                    s.move_category,
                    s.damage_change,
                    s.toggle_hit_substitute
                )
            }
            Instruction::DecrementPP(s) => {
                write!(
                    f,
                    "DecrementPP {:?}: {:?} {}",
                    s.side_ref, s.move_index, s.amount
                )
            }
            Instruction::ToggleTrickRoom(i) => {
                write!(
                    f,
                    "ToggleTrickRoom: {:?},{:?} -> {:?},{:?}",
                    i.currently_active,
                    i.previous_trickroom_turns_remaining,
                    !i.currently_active,
                    i.new_trickroom_turns_remaining,
                )
            }
            Instruction::DecrementTrickRoomTurnsRemaining => {
                write!(f, "DecrementTrickRoomTurnsRemaining")
            }
            Instruction::ToggleSideOneForceSwitch => {
                write!(f, "ToggleSideOneForceSwitch")
            }
            Instruction::ToggleSideTwoForceSwitch => {
                write!(f, "ToggleSideTwoForceSwitch")
            }
        }
    }
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetDamageDealtSideOneInstruction {
    pub damage_change: i16,
    pub move_category: MoveCategory,
    pub previous_move_category: MoveCategory,
    pub toggle_hit_substitute: bool,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetDamageDealtSideTwoInstruction {
    pub damage_change: i16,
    pub move_category: MoveCategory,
    pub previous_move_category: MoveCategory,
    pub toggle_hit_substitute: bool,
}

#[derive(Debug, PartialEq, Clone)]
pub struct DecrementPPInstruction {
    pub side_ref: SideReference,
    pub move_index: PokemonMoveIndex,
    pub amount: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetLastUsedMoveInstruction {
    pub side_ref: SideReference,
    pub last_used_move: LastUsedMove,
    pub previous_last_used_move: LastUsedMove,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ToggleBatonPassingInstruction {
    pub side_ref: SideReference,
}

#[derive(Debug, PartialEq, Clone)]
pub struct DecrementRestTurnsInstruction {
    pub side_ref: SideReference,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetSleepTurnsInstruction {
    pub side_ref: SideReference,
    pub pokemon_index: PokemonIndex,
    pub new_turns: i8,
    pub previous_turns: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetSecondMoveSwitchOutMoveInstruction {
    pub new_choice: Choices,
    pub previous_choice: Choices,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetWishInstruction {
    pub side_ref: SideReference,
    pub wish_amount: i16,
    pub previous_wish_amount: i16,
}

#[derive(Debug, PartialEq, Clone)]
pub struct DecrementWishInstruction {
    pub side_ref: SideReference,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetFutureSightInstruction {
    pub side_ref: SideReference,
    pub pokemon_index: PokemonIndex,
    pub previous_pokemon_index: PokemonIndex,
}

#[derive(Debug, PartialEq, Clone)]
pub struct DecrementFutureSightInstruction {
    pub side_ref: SideReference,
}

#[derive(Debug, PartialEq, Clone)]
pub struct EnableMoveInstruction {
    pub side_ref: SideReference,
    pub move_index: PokemonMoveIndex,
}

#[derive(Debug, PartialEq, Clone)]
pub struct DisableMoveInstruction {
    pub side_ref: SideReference,
    pub move_index: PokemonMoveIndex,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ChangeItemInstruction {
    pub side_ref: SideReference,
    pub current_item: Items,
    pub new_item: Items,
}

#[derive(Debug, PartialEq, Clone)]
pub struct HealInstruction {
    pub side_ref: SideReference,
    pub heal_amount: i16,
}

#[derive(Debug, PartialEq, Clone)]
pub struct DamageInstruction {
    pub side_ref: SideReference,
    pub damage_amount: i16,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SetSubstituteHealthInstruction {
    pub side_ref: SideReference,
    pub new_health: i16,
    pub old_health: i16,
}

#[derive(Debug, PartialEq, Clone)]
pub struct FormeChangeInstruction {
    pub side_ref: SideReference,
    pub forme_change: FormeChange,
}

#[derive(Debug, PartialEq, Clone)]
pub struct SwitchInstruction {
    pub side_ref: SideReference,
    pub previous_index: PokemonIndex,
    pub next_index: PokemonIndex,
}

// pokemon_index is present because even reserve pokemon can have their status
// changed (i.e. healbell)
#[derive(Debug, PartialEq, Clone)]
pub struct ChangeStatusInstruction {
    pub side_ref: SideReference,
    pub pokemon_index: PokemonIndex,
    pub old_status: PokemonStatus,
    pub new_status: PokemonStatus,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ApplyVolatileStatusInstruction {
    pub side_ref: SideReference,
    pub volatile_status: PokemonVolatileStatus,
}

#[derive(Debug, PartialEq, Clone)]
pub struct RemoveVolatileStatusInstruction {
    pub side_ref: SideReference,
    pub volatile_status: PokemonVolatileStatus,
}

#[derive(Debug, PartialEq, Clone)]
pub struct BoostInstruction {
    pub side_ref: SideReference,
    pub stat: PokemonBoostableStat,
    pub amount: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ChangeSideConditionInstruction {
    pub side_ref: SideReference,
    pub side_condition: PokemonSideCondition,
    pub amount: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ChangeWeather {
    pub new_weather: Weather,
    pub new_weather_turns_remaining: i8,
    pub previous_weather: Weather,
    pub previous_weather_turns_remaining: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ChangeTerrain {
    pub new_terrain: Terrain,
    pub new_terrain_turns_remaining: i8,
    pub previous_terrain: Terrain,
    pub previous_terrain_turns_remaining: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ToggleTrickRoomInstruction {
    pub currently_active: bool,
    pub new_trickroom_turns_remaining: i8,
    pub previous_trickroom_turns_remaining: i8,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ToggleTerastallizedInstruction {
    pub side_ref: SideReference,
}

#[derive(Debug, PartialEq, Clone)]
pub struct ChangeType {
    pub side_ref: SideReference,
    pub new_types: (PokemonType, PokemonType),
    pub old_types: (PokemonType, PokemonType),
}