Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Computer.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: Computer.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Computer System class
13 */
14 
15 #include "MemDebug.h"
16 #include "Computer.h"
17 #include "Game.h"
18 
19 // +----------------------------------------------------------------------+
20 
21 static int computer_value[] = {
22  0, 1, 1, 1, 1
23 };
24 
25 // +----------------------------------------------------------------------+
26 
27 Computer::Computer(int comp_type, const char* comp_name)
28 : System(COMPUTER, comp_type, comp_name, 1, 1, 1, 1)
29 {
30  SetAbbreviation(Game::GetText("sys.computer.abrv"));
32 
33  if (subtype == FLIGHT) {
34  crit_level = -1.0f;
35  }
36 }
37 
38 // +----------------------------------------------------------------------+
39 
41 : System(c)
42 {
43  Mount(c);
46 
47  if (subtype == FLIGHT) {
48  crit_level = -1.0f;
49  }
50 }
51 
52 // +--------------------------------------------------------------------+
53 
55 { }
56 
57 // +--------------------------------------------------------------------+
58 
59 void
60 Computer::ApplyDamage(double damage)
61 {
62  System::ApplyDamage(damage);
63 }
64 
65 // +--------------------------------------------------------------------+
66 
67 void
68 Computer::ExecFrame(double seconds)
69 {
70  energy = 0.0f;
71  System::ExecFrame(seconds);
72 }
73 
74 // +--------------------------------------------------------------------+
75 
76 void
77 Computer::Distribute(double delivered_energy, double seconds)
78 {
79  if (IsPowerOn()) {
80  // convert Joules to Watts:
81  energy = (float) (delivered_energy/seconds);
82 
83  // brown out:
84  if (energy < capacity*0.75f)
85  power_on = false;
86 
87  // spike:
88  else if (energy > capacity*1.5f) {
89  power_on = false;
90  ApplyDamage(50);
91  }
92  }
93 }