| 1 | # bMotion - Internal counters |
|---|
| 2 | # |
|---|
| 3 | |
|---|
| 4 | ############################################################################### |
|---|
| 5 | # bMotion - an 'AI' TCL script for eggdrops |
|---|
| 6 | # Copyright (C) James Michael Seward 2000-2008 |
|---|
| 7 | # |
|---|
| 8 | # This program is free software; you can redistribute it and/or modify |
|---|
| 9 | # it under the terms of the GNU General Public License as published by |
|---|
| 10 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | # (at your option) any later version. |
|---|
| 12 | # |
|---|
| 13 | # This program is distributed in the hope that it will be useful, but |
|---|
| 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | # General Public License for more details. |
|---|
| 17 | # |
|---|
| 18 | # You should have received a copy of the GNU General Public License |
|---|
| 19 | # along with this program; if not, write to the Free Software |
|---|
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 21 | ############################################################################### |
|---|
| 22 | |
|---|
| 23 | if {![info exists bMotion_counters]} { |
|---|
| 24 | set bMotion_counters(dummy,dummy) 0 |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | proc bMotion_counter_init { section name } { |
|---|
| 28 | global bMotion_counters |
|---|
| 29 | |
|---|
| 30 | if {$section == ""} { |
|---|
| 31 | return 0 |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | if {$name == ""} { |
|---|
| 35 | return 0 |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | if [info exists bMotion_counters($section,$name)] { |
|---|
| 39 | bMotion_putloglev d * "not reiniting counter for $section $name" |
|---|
| 40 | return 0 |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | bMotion_putloglev d * "initing counter for $section $name" |
|---|
| 44 | set bMotion_counters($section,$name) 0 |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | proc bMotion_counter_incr { section name { amount 1 } } { |
|---|
| 48 | global bMotion_counters |
|---|
| 49 | |
|---|
| 50 | bMotion_putloglev 1 * "incring counter $section $name by $amount" |
|---|
| 51 | |
|---|
| 52 | if {$section == ""} { |
|---|
| 53 | return 0 |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if {$name == ""} { |
|---|
| 57 | return 0 |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | incr bMotion_counters($section,$name) $amount |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | proc bMotion_counter_get { section name } { |
|---|
| 64 | global bMotion_counters |
|---|
| 65 | |
|---|
| 66 | if {$section == ""} { |
|---|
| 67 | return 0 |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | if {$name == ""} { |
|---|
| 71 | return 0 |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | return $bMotion_counters($section,$name) |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | proc bMotion_counter_set { section name amount } { |
|---|
| 78 | global bMotion_counters |
|---|
| 79 | |
|---|
| 80 | if {$section == ""} { |
|---|
| 81 | return 0 |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | if {$name == ""} { |
|---|
| 85 | return 0 |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | set bMotion_counters($section,$name) $amount |
|---|
| 89 | } |
|---|