| 1 | /*************************************************************************** |
| 2 | cross.cpp - description |
| 3 | ------------------- |
| 4 | begin : Thu Aug 17 2000 |
| 5 | copyright : (C) 2000 by Waldemar Baraldi |
| 6 | email : [email protected] |
| 7 | ***************************************************************************/ |
| 8 | |
| 9 | /*************************************************************************** |
| 10 | * * |
| 11 | * This program is free software; you can redistribute it and/or modify * |
| 12 | * it under the terms of the GNU General Public License as published by * |
| 13 | * the Free Software Foundation; either version 2 of the License, or * |
| 14 | * (at your option) any later version. * |
| 15 | * * |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | #include "cross.h" |
| 19 | #include "pointercross.h" |
| 20 | |
| 21 | Cross::Cross():Pipe(){ |
| 22 | p=new PointerCross(); |
| 23 | extra_used_input=Void; |
| 24 | extra_full_level=0; |
| 25 | ro=Void; |
| 26 | extra_ro=Void; |
| 27 | } |
| 28 | |
| 29 | Cross::~Cross(){ |
| 30 | delete p; |
| 31 | } |
| 32 | |
| 33 | bool Cross::hasConnection(CardinalPoint con){ |
| 34 | return (con!=Void); |
| 35 | } |
| 36 | |
| 37 | bool Cross::isRemovable(){ |
| 38 | return !((full_level>0) || (extra_full_level>0)) && !fixed; |
| 39 | } |
| 40 | |
| 41 | void Cross::restrictAsOutput(CardinalPoint con){ |
| 42 | if (con!=Void) |
| 43 | if (con==South || con==North) |
| 44 | ro=con; |
| 45 | else extra_ro=con; |
| 46 | } |
| 47 | |
| 48 | bool Cross::isRestrictedAsOutput(CardinalPoint con){ |
| 49 | return (ro==con || extra_ro==con); |
| 50 | } |
| 51 | |
| 52 | CardinalPoint Cross::getOutput(CardinalPoint input){ |
| 53 | if (input==ro || input==extra_ro) return Void; |
| 54 | switch (input){ |
| 55 | case South: {return North;} |
| 56 | case North:return South; |
| 57 | case West: return East; |
| 58 | case East: return West; |
| 59 | default:break; |
| 60 | } |
| 61 | return Void; |
| 62 | } |
| 63 | |
| 64 | void Cross::incFullLevel(CardinalPoint input,unsigned int amount){ |
| 65 | if (!isRestrictedAsOutput(input)){ |
| 66 | if ((input==North) || (input==South)) |
| 67 | if ((used_input==Void) || (used_input==input)){ |
| 68 | full_level+=amount; |
| 69 | used_input=input; |
| 70 | } |
| 71 | if ((input==West) || (input==East)) |
| 72 | if ((extra_used_input==Void) || (extra_used_input==input)){ |
| 73 | extra_full_level+=amount; |
| 74 | extra_used_input=input; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | int Cross::getFullLevel(CardinalPoint input){ |
| 80 | if (input==used_input) |
| 81 | return full_level; |
| 82 | if (input==extra_used_input) |
| 83 | return extra_full_level; |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | bool Cross::hasLiquid(){ |
| 88 | return (full_level>0 || extra_full_level>0); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | Pointer * Cross::getPointer(){ |
| 93 | return p; |
| 94 | } |
| 95 | |
| 96 | void Cross::paint(VideoManager * vm){ |
| 97 | |
| 98 | Image * ima; |
| 99 | if (fixed) |
| 100 | ima=(vm->getImageManager())->getImage(new Str("cross_b.png")); |
| 101 | else |
| 102 | ima=(vm->getImageManager())->getImage(new Str("cross.png")); |
| 103 | |
| 104 | vm->blit(ima, x, y); |
| 105 | |
| 106 | if (ro != Void) paintRestriction(vm, ro); |
| 107 | if (extra_ro != Void) paintRestriction(vm, extra_ro); |
| 108 | if (full_level>0){ |
| 109 | Image * aux=(vm->getImageManager())->getImage(new Str("flow.png")); |
| 110 | int xof=x+PipeWidth/2-aux->width()/2; |
| 111 | int yof=aux->height()/2; |
| 112 | int total, f; |
| 113 | vm->setClipping(x, y, PipeWidth, PipeHeight); |
| 114 | vm->enableClipping(true); |
| 115 | if (used_input==North){ |
| 116 | total=y-yof; |
| 117 | f=1; |
| 118 | } |
| 119 | else{ |
| 120 | total=PipeHeight+y-yof; |
| 121 | f=-1; |
| 122 | } |
| 123 | for (int i=0; i<full_level+1;i+=Gran) |
| 124 | vm->blit(aux, xof, (int)(total+f*(float)i/(float)full()*(float)PipeHeight)); |
| 125 | vm->enableClipping(false); |
| 126 | } |
| 127 | if (extra_full_level>0){ |
| 128 | Image * aux=(vm->getImageManager())->getImage(new Str("flow.png")); |
| 129 | int yof=y+(PipeHeight-aux->height())/2; |
| 130 | int total,f; |
| 131 | vm->setClipping(x, y, PipeWidth, PipeHeight); |
| 132 | vm->enableClipping(true); |
| 133 | if (extra_used_input==West){ |
| 134 | total=x-aux->width()/2; |
| 135 | f=1; |
| 136 | } |
| 137 | else{ |
| 138 | total=x+PipeWidth-aux->width()/2; |
| 139 | f=-1; |
| 140 | } |
| 141 | for (int i=0; i<extra_full_level+1;i+=Gran) |
| 142 | vm->blit(aux, (int)(total+f*(float)i/(float)full()*(float)PipeWidth), yof); |
| 143 | vm->enableClipping(false); |
| 144 | } |
| 145 | if (bonus!=NormalBonus) paintBonus(vm, bonus); |
| 146 | } |