1 /***************************************************************************
2                           elbowupleft.cpp  -  description
3                              -------------------
4     begin                : Thu Aug 17 2000
5     copyright            : (C) 2000 by Waldemar Baraldi
6     email                : baraldi@lacasilla.com.ar
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 "elbowupleft.h"
19 #include "pointerelbowupleft.h"
20 
ElbowUpLeft()21 ElbowUpLeft::ElbowUpLeft():Pipe(){
22   p=new PointerElbowUpLeft();
23 }
24 
~ElbowUpLeft()25 ElbowUpLeft::~ElbowUpLeft(){
26   delete p;
27 }
28 
hasConnection(CardinalPoint con)29 bool ElbowUpLeft::hasConnection(CardinalPoint con){
30   return ((con==North) || (con==West));
31 }
32 
getOutput(CardinalPoint input)33 CardinalPoint ElbowUpLeft::getOutput(CardinalPoint input){
34   if (input==ro) return Void;
35   switch (input){
36     case North: return West;
37     case West:return North;
38     default:return Void;
39   }
40 }
41 
restrictAsOutput(CardinalPoint con)42 void ElbowUpLeft::restrictAsOutput(CardinalPoint con){
43   if (con==North || con==West) ro=con;
44 }
45 
isRestrictedAsOutput(CardinalPoint con)46 bool ElbowUpLeft::isRestrictedAsOutput(CardinalPoint con){
47   return (con==ro);
48 }
49 
incFullLevel(CardinalPoint input,unsigned int amount)50 void ElbowUpLeft::incFullLevel(CardinalPoint input,unsigned int amount){
51   if ((input==North || input==West) && ro!=input)
52     if ((used_input==Void) || (used_input==input)){
53       full_level+=amount;
54       used_input=input;
55     }
56 }
57 
getFullLevel(CardinalPoint input)58 int ElbowUpLeft::getFullLevel(CardinalPoint input){
59   if (input==used_input)
60     return full_level;
61   return -1;
62 }
63 
getPointer()64 Pointer * ElbowUpLeft::getPointer(){
65   return p;
66 }
67 
paint(VideoManager * vm)68 void ElbowUpLeft::paint(VideoManager * vm){
69   Image * ima;
70   if (fixed)
71     ima=(vm->getImageManager())->getImage(new Str("elbow_nwb.png"));
72   else
73     ima=(vm->getImageManager())->getImage(new Str("elbow_nw.png"));
74   vm->blit(ima, x, y);
75 
76   if (ro!=Void) paintRestriction(vm, ro);
77 
78   if (full_level>0){
79     Image * aux=(vm->getImageManager())->getImage(new Str("flow.png"));
80     float fwidth=(float)PipeWidth/2;
81     float fheight=(float)PipeHeight/2;
82     float nov=PI/2;
83     vm->setClipping(x, y, PipeWidth, PipeHeight);
84     vm->enableClipping(true);
85     int xaux=x-aux->width()/2;
86     int yaux=y-aux->width()/2;
87     if (used_input==North){
88       for (int i=0; i<full_level+1;i+=Gran)
89         vm->blit(aux, (int)(xaux+(float)cos((float)i/(float)full() * nov)*fwidth),
90                       (int)(yaux+(float)sin((float)i/(float)full() * nov)*fheight));
91     }else{
92       for (int i=0; i<full_level+1;i+=Gran)
93         vm->blit(aux, (int)(xaux+(float)cos((float)(full()-i)/(float)full() * nov)*fwidth),
94                       (int)(yaux+(float)sin((float)(full()-i)/(float)full() * nov)*fheight));
95     }
96     vm->enableClipping(false);
97   }
98   if (bonus!=NormalBonus) paintBonus(vm, bonus);
99 }
100